public class

ContentManager

extends Object
implements EventReceiver
java.lang.Object
   ↳ com.neomades.content.ContentManager

Class Overview

This manager is responsible for query handling.

A typical implementation is using only one instance of ContentManager and register it to the Application by calling the registerContentManager(ContentManager) method.

Query can be posted either directly with the postQuery(Query) method or using the Event API.

Cache management

Cache can be disabled by the server if response contains the HTTP Header "Cache-Control" with "no-store" or "no-cache" value.

Summary

Constants
String DEFAULT_NAME
Public Constructors
ContentManager()
Creates a ContentManager.
ContentManager(String name)
Creates a ContentManager with a special name.
Public Methods
void cancelAll(QueryFilter filter)
Cancels all queries matching the given filter.
void cancelAll(Object tag)
Cancels all queries with the given tag.
void clear()
Removes all parsers, networks, caches.
Cache getCacheByType(String cacheType)
Returns the Cache instance associated with the type given in parameter
Network getNetworkByType(String networkType)
Returns the Network instance associated with the type given in parameter
Parser getParserByType(String parserType)
Returns the Parser instance associated with the type given in parameter
RetryPolicy getRetryPolicyByType(String retryPolicyType)
Returns the Retry policy associated with type name given in parameter.
void onReceiveEvent(Event event)
Called by EventBus when an Event has been received.
void postQuery(Query query)
Posts a query to a Queue.
void putCache(String type, Cache cache)
Puts a Cache with an associated type name.
void putNetwork(String type, Network network)
Puts a Network with an associated type name.
void putParser(String type, Parser parser)
Puts a Parser with an associated type name.
void putRetryPolicy(String type, RetryPolicy policy)
Puts a Parser with an associated type name.
void removeCache(String type)
Removes a Cache from this manager.
void removeNetwork(String type)
Removes a Network from this manager.
void removeParser(String type)
Removes a Parser from this manager.
void removeRetryPolicy(String type)
Removes a RetryPolicy from this manager.
void setDebugEnabled(boolean enabled)
Enables or disables traces inside logs.
void setEventBus(EventBus eventBus)
Registers this ContentManager into the eventBus given in parameter and unregisters it from old eventBus.
void start()
Starts managing queries.
void stop()
Stops managing queries.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.neomades.event.EventReceiver

Constants

public static final String DEFAULT_NAME

Constant Value: "com.neomades.content.ContentManager"

Public Constructors

public ContentManager ()

public ContentManager (String name)

Creates a ContentManager with a special name.

Don't forget the set the same name inside ContentQuery in order to send-receive query to the right ContentManager.

Public Methods

public void cancelAll (QueryFilter filter)

Cancels all queries matching the given filter.

Parameters
filter filter all ContentQuery queries.

public void cancelAll (Object tag)

Cancels all queries with the given tag.

Parameters
tag tag inside ContentQuery

public void clear ()

Removes all parsers, networks, caches.

public Cache getCacheByType (String cacheType)

Returns the Cache instance associated with the type given in parameter

Parameters
cacheType type to find
Returns
  • the found Cache instance or null if not found

public Network getNetworkByType (String networkType)

Returns the Network instance associated with the type given in parameter

Parameters
networkType type to find
Returns
  • the found Network instance or null if not found

public Parser getParserByType (String parserType)

Returns the Parser instance associated with the type given in parameter

Parameters
parserType type to find
Returns
  • the found Parser instance or null if not found

public RetryPolicy getRetryPolicyByType (String retryPolicyType)

Returns the Retry policy associated with type name given in parameter.

Parameters
retryPolicyType name associated with a RetryPolicy instance.
Returns
  • the Retry policy associated

public void onReceiveEvent (Event event)

Called by EventBus when an Event has been received.

The EventReceiver should be associated with this eventType. To do that, the EventReceiver's registration may say what type of event is associated to.

Parameters
event received event

public void postQuery (Query query)

Posts a query to a Queue.

This method is also called when ContentQuery are posted through the EventBus.

public void putCache (String type, Cache cache)

Puts a Cache with an associated type name.

Parameters
type a name to associated with
cache instance to register
Throws
IllegalArgumentException if the type has been already set.

public void putNetwork (String type, Network network)

Puts a Network with an associated type name.

Parameters
type a name to associated with
network instance to register
Throws
IllegalArgumentException if the type has been already set.

public void putParser (String type, Parser parser)

Puts a Parser with an associated type name. This parser can be used for serialization and de-serialization.

Parameters
type a name to associated with
parser instance to register
Throws
IllegalArgumentException if the type has been already set.

public void putRetryPolicy (String type, RetryPolicy policy)

Puts a Parser with an associated type name.

Parameters
type a name to associated with
policy instance to register
Throws
IllegalArgumentException if the type has been already set.

public void removeCache (String type)

Removes a Cache from this manager.

Parameters
type the cache type

public void removeNetwork (String type)

Removes a Network from this manager.

Parameters
type the network type

public void removeParser (String type)

Removes a Parser from this manager.

Parameters
type the parser type

public void removeRetryPolicy (String type)

Removes a RetryPolicy from this manager.

Parameters
type the RetryPolicy type

public void setDebugEnabled (boolean enabled)

Enables or disables traces inside logs.

Parameters
enabled true to print traces.

public void setEventBus (EventBus eventBus)

Registers this ContentManager into the eventBus given in parameter and unregisters it from old eventBus.

By default, the eventBus is the Application event bus.

public void start ()

Starts managing queries.

A queue of Queries, pool of threads for Cache and pool of threads for Network are initialized.

Queries will be received by EventBus used by the Application or by the postQuery(Query) method.

public void stop ()

Stops managing queries.

Stops queries queue, pools of threads.