Platform SDK Java 8.5 API Reference

com.genesyslab.platform.applicationblocks.com.cache
Class DefaultConfCache

java.lang.Object
  extended by com.genesyslab.platform.applicationblocks.com.cache.DefaultConfCache
All Implemented Interfaces:
IConfCache, Action<ConfEvent>, Subscriber<ConfEvent>, SubscriptionService<ConfCacheEvent>, AsyncInvokerSupport

public final class DefaultConfCache
extends java.lang.Object
implements IConfCache, SubscriptionService<ConfCacheEvent>, AsyncInvokerSupport

The default implementation of the configuration cache interface.


Constructor Summary
DefaultConfCache()
          Creates a cache which will use the default policy, storage and query engine.
DefaultConfCache(IConfCachePolicy cachePolicy, IConfCacheStorage cacheStorage, IConfCacheQueryEngine cacheQueryEngine)
          Creates a new instance of the configuration cache.
 
Method Summary
 void add(ICfgObject obj)
          Adds a new configuration object to the cache.
 void addEndpoint(Endpoint endpoint)
          Adds a supported endpoint to the list.
 java.util.concurrent.Future<IConfCache> beginRefresh(AsyncInvoker asyncInvoker, Action<java.util.concurrent.Future<IConfCache>> finishCallback)
          Asynchronously updates all configuration objects in the cache.
 void clear()
          Removes all cache contents.
 boolean contains(ICfgObject obj)
          Determines whether the cache contains the specified object.
 void deserialize(java.io.InputStream stream)
          Deserializes the cache from the specified stream.
protected  void deserialize(org.w3c.dom.Node source)
          Deserializes the cache from the specified source.
 void deserialize(javax.xml.transform.Source source)
          Deserializes the cache from the specified source.
 void endRefresh(java.util.concurrent.Future<IConfCache> asyncResult)
          To be called when the asynchronous refresh operation is complete.
 int getEndpointCount()
           
 Predicate<ConfEvent> getFilter()
          Gets filter predicate that allows checking whether publishing event should be processed or ignored.
 IConfCachePolicy getPolicy()
          Returns the current policy associated with this cache.
 void handle(ConfEvent configEvent)
           
 void refresh()
          Synchronously updates all configuration objects which are currently in the cache.
 void register(Action<ConfCacheEvent> handler, Predicate<ConfCacheEvent> filter)
          Registers a delegate for receiving notifications from the cache based on the specified filter.
 void register(Subscriber<ConfCacheEvent> subscriber)
          Registers a subscriber object for receiving notifications from the cache.
 void remove(CfgObjectType type, int dbid)
          Removes the configuration object with the specified type and dbid from the cache.
 void remove(ICfgObject obj)
          Removes the specified configuration object from the cache.
 boolean removeEndpoint(Endpoint endpoint)
           
<T extends ICfgObject>
T
retrieve(java.lang.Class<T> cls, CfgObjectType type, int dbid)
          Retrieves a configuration object from the cache using the cache's query engine.
<T extends ICfgObject>
T
retrieve(java.lang.Class<T> cls, ICfgQuery query)
          Retrieves a configuration object from the cache using the cache's query engine.
<T extends ICfgObject>
java.lang.Iterable<T>
retrieveMultiple(java.lang.Class<T> cls)
          Retrieves an enumerable list of all configuration objects in the storage.
<T extends ICfgObject>
java.lang.Iterable<T>
retrieveMultiple(java.lang.Class<T> cls, ICfgQuery query)
          Retrieves an enumerable list of objects from the cache using the cache's query engine.
 void serialize(java.io.OutputStream stream)
          Serializes the cache into the specified stream.
 void serialize(javax.xml.transform.Result result)
          Serializes the cache into the specified result.
 void setInvoker(AsyncInvoker value)
           
 void setPolicy(IConfCachePolicy cachePolicy)
           
 void unregister(Action<ConfCacheEvent> handler)
          Unregisters the specified delegate from notifications.
 void unregister(Subscriber<ConfCacheEvent> subscriber)
          Unregisters the subscriber from event notifications.
 void update(ICfgObject obj)
          Overwrites a configuration object which already exists in the cache with a new copy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConfCache

public DefaultConfCache()
Creates a cache which will use the default policy, storage and query engine.


DefaultConfCache

public DefaultConfCache(IConfCachePolicy cachePolicy,
                        IConfCacheStorage cacheStorage,
                        IConfCacheQueryEngine cacheQueryEngine)
Creates a new instance of the configuration cache.

Parameters:
cachePolicy - The cache policy
cacheStorage - The storage to be used in this cache
cacheQueryEngine - The query engine to be used to retrieve data from the storage
Method Detail

setInvoker

public void setInvoker(AsyncInvoker value)
Specified by:
setInvoker in interface AsyncInvokerSupport

getEndpointCount

public int getEndpointCount()

addEndpoint

public void addEndpoint(Endpoint endpoint)
Adds a supported endpoint to the list. By default, the endpoint of the configuration service with which this cache is initially associated is added. This method should be used to add any other endpoints at which the objects in this cache are valid -- for instance the endpoint of a backup configuration server or a proxy. Note that ALL objects in the cache are assumed to be valid at ALL endpoints. This means that adding unrelated configuration servers to the list is unsupported and will result in undefined behavior.

Parameters:
endpoint - The endpoint of a configuration server

removeEndpoint

public boolean removeEndpoint(Endpoint endpoint)

add

public void add(ICfgObject obj)
Adds a new configuration object to the cache. An "ObjectAdded" cache event is fired upon the successful completion of this operation.

Specified by:
add in interface IConfCache
Parameters:
obj - A configuration object

update

public void update(ICfgObject obj)
Overwrites a configuration object which already exists in the cache with a new copy. An "ObjectUpdated" cache event is fired upon the successful completion of this operation.

Specified by:
update in interface IConfCache
Parameters:
obj - A configuration object

remove

public void remove(ICfgObject obj)
Removes the specified configuration object from the cache. An "ObjectRemoved" cache event is fired upon the successful completion of this operation.

Specified by:
remove in interface IConfCache
Parameters:
obj - A configuration object

remove

public void remove(CfgObjectType type,
                   int dbid)
Removes the configuration object with the specified type and dbid from the cache. An "ObjectRemoved" cache event is fired upon the successful completion of this operation.

Specified by:
remove in interface IConfCache
Parameters:
type - The type of configuration object
dbid - The dbid of the configuration object

retrieve

public <T extends ICfgObject> T retrieve(java.lang.Class<T> cls,
                                         CfgObjectType type,
                                         int dbid)
Retrieves a configuration object from the cache using the cache's query engine.

Specified by:
retrieve in interface IConfCache
Type Parameters:
T - The type of configuration object that should be returned
Parameters:
cls - class of object to be retrieved
type - The type of configuration object
dbid - The dbid of the configuration object
Returns:
A configuration object of the requested type

retrieve

public <T extends ICfgObject> T retrieve(java.lang.Class<T> cls,
                                         ICfgQuery query)
Retrieves a configuration object from the cache using the cache's query engine.

Specified by:
retrieve in interface IConfCache
Type Parameters:
T - The type of configuration object that should be returned
Parameters:
cls - class of object to be retrieved
query - A query based on which the result is obtained
Returns:
A configuration object matching the specified query

retrieveMultiple

public <T extends ICfgObject> java.lang.Iterable<T> retrieveMultiple(java.lang.Class<T> cls,
                                                                     ICfgQuery query)
Retrieves an enumerable list of objects from the cache using the cache's query engine.

Specified by:
retrieveMultiple in interface IConfCache
Type Parameters:
T - The types of configuration objects to be included in the list
Parameters:
cls - class of object to be retrieved
query - A query based on which the result is obtained
Returns:
An enumerable list of configuration objects matching the specified query

retrieveMultiple

public <T extends ICfgObject> java.lang.Iterable<T> retrieveMultiple(java.lang.Class<T> cls)
Retrieves an enumerable list of all configuration objects in the storage. Unlike the other Get methods this method does not use the query engine. Instead, all cached objects are returned, filtered by the T parameter.

Specified by:
retrieveMultiple in interface IConfCache
Type Parameters:
T - The type of configuration object to include (use ICfgObject to retrieve an enumeration of all stored objects)
Parameters:
cls - class of object to be retrieved
Returns:
An enumerable list of configuration objects

serialize

public void serialize(java.io.OutputStream stream)
Serializes the cache into the specified stream.

Parameters:
stream - The stream into which the cache is to be written

serialize

public void serialize(javax.xml.transform.Result result)
Serializes the cache into the specified result.

Specified by:
serialize in interface IConfCache
Parameters:
result - The result into which the cache is to be written
See Also:
StreamResult, DOMResult

deserialize

public void deserialize(java.io.InputStream stream)
Deserializes the cache from the specified stream.

Parameters:
stream - The stream from which the cache is to be read

deserialize

public void deserialize(javax.xml.transform.Source source)
Deserializes the cache from the specified source.

Specified by:
deserialize in interface IConfCache
Parameters:
source - The source from which the cache is to be read
See Also:
StreamSource, DOMSource

deserialize

protected void deserialize(org.w3c.dom.Node source)
Deserializes the cache from the specified source.

Parameters:
source - The source from which the cache is to be read
See Also:
StreamSource, DOMSource

clear

public void clear()
Removes all cache contents.

Specified by:
clear in interface IConfCache

refresh

public void refresh()
             throws ConfigException,
                    java.lang.InterruptedException
Synchronously updates all configuration objects which are currently in the cache.

Specified by:
refresh in interface IConfCache
Throws:
ConfigException - is thrown in case of object(s) reload exception
java.lang.InterruptedException - is thrown if task has been interrupted

beginRefresh

public java.util.concurrent.Future<IConfCache> beginRefresh(AsyncInvoker asyncInvoker,
                                                            Action<java.util.concurrent.Future<IConfCache>> finishCallback)
Asynchronously updates all configuration objects in the cache. Refresh operation will be executed in provided sync invoker as single task, so, invoker will be busy for all this time. Usage sample:
   AsyncInvoker invoker =
           new SingleThreadInvoker("CacheAsyncRefresh");
   Future asyncRefresh =
           cache.beginRefresh(invoker, null);
   // DO SOMETHING...
   // To check that refresh is done: 
   if (asyncRefresh.isDone()) {
       // ...
   }
   // To wait for refresh is done:
   asyncRefresh.get();
   // After refresh is done and invoker is not needed:
   invoker.dispose();
 

Specified by:
beginRefresh in interface IConfCache
Parameters:
asyncInvoker - invoker for refresh task execution
finishCallback - The callback method to be invoked when the operation completes
Returns:
The async result associated with this operation

endRefresh

public void endRefresh(java.util.concurrent.Future<IConfCache> asyncResult)
To be called when the asynchronous refresh operation is complete. If called before the refresh operation completes, this method will block until completion.

Specified by:
endRefresh in interface IConfCache
Parameters:
asyncResult - The async result associated with the current operation

getPolicy

public IConfCachePolicy getPolicy()
Returns the current policy associated with this cache.

Specified by:
getPolicy in interface IConfCache
Returns:
current policy associated with this cache

setPolicy

public void setPolicy(IConfCachePolicy cachePolicy)

contains

public boolean contains(ICfgObject obj)
Determines whether the cache contains the specified object. For the purposes of this method, two objects are considered equal if they have the same dbid and type.

Specified by:
contains in interface IConfCache
Parameters:
obj - The configuration object to look for
Returns:
true if the object is in the cache, false otherwise

register

public void register(Subscriber<ConfCacheEvent> subscriber)
Registers a subscriber object for receiving notifications from the cache.

Specified by:
register in interface SubscriptionService<ConfCacheEvent>
Parameters:
subscriber - the "subscriber" object which will handle the notifications

register

public void register(Action<ConfCacheEvent> handler,
                     Predicate<ConfCacheEvent> filter)
Registers a delegate for receiving notifications from the cache based on the specified filter.

Specified by:
register in interface SubscriptionService<ConfCacheEvent>
Parameters:
handler - The delegate which will handle the event
filter - A filter to apply to the event

unregister

public void unregister(Subscriber<ConfCacheEvent> subscriber)
Unregisters the subscriber from event notifications.

Specified by:
unregister in interface SubscriptionService<ConfCacheEvent>
Parameters:
subscriber - the subscriber to unregister

unregister

public void unregister(Action<ConfCacheEvent> handler)
Unregisters the specified delegate from notifications.

Specified by:
unregister in interface SubscriptionService<ConfCacheEvent>
Parameters:
handler - the function to unregister

getFilter

public Predicate<ConfEvent> getFilter()
Description copied from interface: Subscriber
Gets filter predicate that allows checking whether publishing event should be processed or ignored.

Specified by:
getFilter in interface Subscriber<ConfEvent>
Returns:
filter predicate

handle

public void handle(ConfEvent configEvent)
Specified by:
handle in interface Action<ConfEvent>

Platform SDK Java 8.5 API Reference

Send comments on this topicTechpubs.webadmin@genesys.com.
Document version: 8.5.302.00
Copyright © 2006–2017 Genesys Telecommunications Laboratories, Inc. All rights reserved.