|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sag.osami.contextstore.ContextStore
public final class ContextStore
Being the actual implementation of the ContextStore pattern, this class manages IContextHandler
s and dispatches and persists ContextEvent
s.
It implements all generic functionality, in particular handler-specific functionality as (de)registering context handlers and passing over context events to the according (interested) handlers.
It delegates all storage-related methods as loading, storing and querying ContextEvent
s to an implementation of a ISerializedContextStorage
.
It is noteworthy that this version of the ContextStore uses worker threads for the processing of the registered IContextHandler
s. Thus the semantics
of context event creation changed crucially: newContextEvent(String, String, Object, Date)
etc. are no longer synchronous, i.e. it
cannot be assumed that the newly created event is already handled by all interested handlers after newContextEvent
was executed.
By processing the context handlers concurrently, the overall speed is improved, especially on modern multi-core CPU architectures (in fact, the number of
handler worker threads corresponds to the number of CPU cores). Methods like registerHandler(IContextHandler)
etc. are thread-safe.
For creating a ContextStore instance conveniently, the builder class ContextStoreBuilder
can be used.
All internally used components such as the serialization handler and the storage implementation are used strictly through well-defined interfaces and
therefore can be replaced with custom implementations. See ContextStoreBuilder
and OsgiContextStoreActivator
for an overview how to replace
the default components.
ISerializedContextStorage
,
IContextHandler
,
ContextStoreBuilder
,
OsgiContextStoreActivator
Field Summary |
---|
Fields inherited from interface com.sag.osami.api.context.IContextStore |
---|
CONTEXT_STORE_ID, TYPE_ALL, TYPE_DEREGISTERED, TYPE_REGISTERED |
Constructor Summary | |
---|---|
ContextStore(ISerializationHandler serializer,
ISerializedContextStorage storage,
java.lang.String storeID)
|
Method Summary | |
---|---|
void |
activateEventsForHandler(IContextHandler myHandler)
Activate notification. |
void |
deactivateEventsForHandler(IContextHandler myHandler)
Deactivate notification. |
void |
deregisterContextType(java.lang.String myType)
Deregister context type in the ContextStore. |
void |
deregisterHandler(IContextHandler contextHandler)
Deregister context handler. |
void |
deregisterHandlerForContextType(IContextHandler handler,
java.lang.String contextType)
Deregister the context handler for the given context type. |
java.lang.String[] |
getHandlersRegisteredContextTypes(IContextHandler handler)
Returns all registered context types for committed handler. |
java.lang.String[] |
getRegisteredContextTypes()
Returns all registered context types. |
ISerializationHandler |
getSerializationHandler()
|
IContextStorage |
getStorage()
Returns the storage handler of the context store, which handles storing, loading, querying and deleting context events |
java.lang.String |
getStoreID()
Returns the ID of the ContextStore. |
boolean |
isRegisteredContextType(java.lang.String myType)
Checks if given context type is registered in the ContextStore. |
void |
newContextEvent(ContextEvent cev)
Insert a new context in the ContextStore. |
void |
newContextEvent(ContextEvent cev,
boolean persist)
Insert a new context in the ContextStore. |
void |
newContextEvent(java.lang.String originID,
java.lang.String type,
java.lang.Object data,
java.util.Date date)
Insert a new context with the given parameters in the ContextStore. |
void |
newContextEvent(java.lang.String originID,
java.lang.String type,
java.lang.Object data,
java.util.Date date,
boolean persist)
Insert a new context with the given parameters in the ContextStore. |
void |
newContextEvent(java.lang.String originID,
java.lang.String type,
java.lang.String[] data,
java.util.Date date,
java.lang.String contextStoreOriginID)
Creates a new context event with given parameters. |
void |
newContextEvent(java.lang.String originID,
java.lang.String type,
java.lang.String[] data,
java.util.Date date,
java.lang.String contextStoreOriginID,
boolean persist)
Creates a new context event with given parameters |
ContextEvent[] |
query(java.lang.String query,
java.lang.Object... params)
This method allows you to perform a query on the ContextStore database to get contexts with the specified properties |
java.lang.Iterable<ContextEvent> |
queryLazy(java.lang.String query,
java.lang.Object... params)
Lazy variant of IContextQuery.query(String, Object...) , i.e. it loads one ContextEvent at a time during iteration. |
void |
registerContextType(java.lang.String myType)
Register context type in the ContextStore. |
void |
registerHandler(IContextHandler contextHandler)
Register a context handler for notification of new contexts (all types). |
void |
registerHandler(IContextHandler contextHandler,
java.lang.String[] typeList)
Register a context handler for notification of new contexts with any type in the given list. |
void |
registerHandlerForContextType(IContextHandler handler,
java.lang.String contextType)
Register the context handler for the given context type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ContextStore(ISerializationHandler serializer, ISerializedContextStorage storage, java.lang.String storeID)
Method Detail |
---|
public void registerHandler(IContextHandler contextHandler, java.lang.String[] typeList)
IContextStore
registerHandler
in interface IContextStore
contextHandler
- the context handlertypeList
- the context type listpublic void registerHandler(IContextHandler contextHandler)
IContextStore
registerHandler
in interface IContextStore
contextHandler
- the context handlerpublic void registerHandlerForContextType(IContextHandler handler, java.lang.String contextType)
IContextStore
registerHandlerForContextType
in interface IContextStore
handler
- the context handlercontextType
- the context typepublic void deregisterHandler(IContextHandler contextHandler)
IContextStore
deregisterHandler
in interface IContextStore
contextHandler
- the context handlerpublic void newContextEvent(ContextEvent cev)
IContextStore
Note that the actual context event object won't be stored as-is in the ContextStore but instead is re-packaged in a new ContextEvent data object. Also, the properties ID and contextStoreOriginID stored in the given object will be ignored and determined internally. This method exists for convenience only.
newContextEvent
in interface IContextStore
cev
- the context event to be insertedpublic void newContextEvent(ContextEvent cev, boolean persist)
IContextStore
Note that the actual context event object won't be stored as-is in the ContextStore but instead is re-packaged in a new ContextEvent data object. Also, the properties ID and contextStoreOriginID stored in the given object will be ignored and determined internally. This method exists for convenience only.
newContextEvent
in interface IContextStore
cev
- the context event to be insertedpersist
- indicates whether context event should be persisted or notpublic void newContextEvent(java.lang.String originID, java.lang.String type, java.lang.Object data, java.util.Date date)
IContextStore
newContextEvent
in interface IContextStore
originID
- the origin id of the new context eventtype
- the type of the new context eventdata
- the data of the new context eventdate
- the date of the new context eventpublic void newContextEvent(java.lang.String originID, java.lang.String type, java.lang.Object data, java.util.Date date, boolean persist)
IContextStore
newContextEvent
in interface IContextStore
originID
- the origin id of the new context eventtype
- the type of the new context eventdata
- the data of the new context eventdate
- the date of the new context eventpersist
- indicates whether context event should be persisted or notpublic void newContextEvent(java.lang.String originID, java.lang.String type, java.lang.String[] data, java.util.Date date, java.lang.String contextStoreOriginID)
ISerializedContextReceiver
newContextEvent
in interface ISerializedContextReceiver
originID
- the origin IDtype
- see context typedata
- the serialized form of the payloaddate
- see context timestampcontextStoreOriginID
- the original context store namepublic void newContextEvent(java.lang.String originID, java.lang.String type, java.lang.String[] data, java.util.Date date, java.lang.String contextStoreOriginID, boolean persist)
ISerializedContextReceiver
newContextEvent
in interface ISerializedContextReceiver
originID
- the origin IDtype
- see context typedata
- the serialized form of the payloaddate
- see context timestampcontextStoreOriginID
- the original context store namepersist
- indicates whether context event should be persisted or notpublic ContextEvent[] query(java.lang.String query, java.lang.Object... params)
IContextQuery
query
in interface IContextQuery
query
- the query to be executedparams
- parameters which may occur in the query (e.g., using the ? syntax) and are bound accordingly (so escaping, quoting etc. is unnecessary)
IContextEvent[]
s (which is empty if no contexts were found)public java.lang.Iterable<ContextEvent> queryLazy(java.lang.String query, java.lang.Object... params) throws java.lang.UnsupportedOperationException
IContextQuery
IContextQuery.query(String, Object...)
, i.e. it loads one ContextEvent at a time during iteration. This operation is optional.
queryLazy
in interface IContextQuery
java.lang.UnsupportedOperationException
- if the underlying storage implementation does not support lazy queryingIContextQuery.query(String, Object...)
public void activateEventsForHandler(IContextHandler myHandler)
IContextStore
Has no effect when notification was already active.
activateEventsForHandler
in interface IContextStore
myHandler
- the context handlerpublic void deactivateEventsForHandler(IContextHandler myHandler)
IContextStore
This is useful if the handler does some time-consuming operations while processing, or needs to be temporarily disabled. Despite the deactivation, the normal operation can be resumed without having to register again.
Has no effect when notification was already inactive.
deactivateEventsForHandler
in interface IContextStore
myHandler
- the context handlerpublic void deregisterContextType(java.lang.String myType)
IContextStore
deregisterContextType
in interface IContextStore
myType
- the context typepublic boolean isRegisteredContextType(java.lang.String myType)
IContextStore
isRegisteredContextType
in interface IContextStore
public java.lang.String[] getRegisteredContextTypes()
IContextStore
getRegisteredContextTypes
in interface IContextStore
public void registerContextType(java.lang.String myType)
IContextStore
This routine is useful, if a context source is not available in the beginning, but there are already handlers registering for future context events of the given type.
registerContextType
in interface IContextStore
myType
- the context typepublic void deregisterHandlerForContextType(IContextHandler handler, java.lang.String contextType)
IContextStore
deregisterHandlerForContextType
in interface IContextStore
handler
- the context handlercontextType
- the context typepublic java.lang.String[] getHandlersRegisteredContextTypes(IContextHandler handler)
IContextStore
getHandlersRegisteredContextTypes
in interface IContextStore
public java.lang.String getStoreID()
IContextStore
getStoreID
in interface IContextStore
public ISerializationHandler getSerializationHandler()
public IContextStorage getStorage()
IContextStore
getStorage
in interface IContextStore
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |