Class DistributedEventAdmin
- All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable
,IIdentifiable
,ISharedObject
,org.osgi.service.event.EventAdmin
-
Field Summary
Modifier and TypeFieldDescriptionprotected BundleContext
protected org.eclipse.ecf.internal.remoteservice.eventadmin.EventHandlerTracker
protected static boolean
Fields inherited from class org.eclipse.ecf.core.sharedobject.BaseSharedObject
DESTROYREMOTE_CODE, DESTROYSELFLOCAL_CODE
-
Constructor Summary
ModifierConstructorDescriptionprotected
DistributedEventAdmin
(BundleContext context) Create a Distributed EventAdmin implementation.DistributedEventAdmin
(BundleContext context, org.osgi.service.log.LogService log) Create a Distributed EventAdmin implementation. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addEventTopicFilters
(String[] filters) protected org.osgi.service.event.Event
createEventFromMessageData
(ID fromID, Object[] messageData) Create a localEvent
from deserialized messageData.protected Object[]
createMessageDataFromEvent
(ID target, org.osgi.service.event.Event eventToSend) Create message data for deliver to a target (which could benull
to designate multiple target receivers), The resulting Object[] must be Serializable and in a form that receivers can deserialize viacreateEventFromMessageData(ID, Object[])
on the receiver.protected org.osgi.service.event.Event
getEventToSend
(org.osgi.service.event.Event event) Get the actual event to pass tosendMessage(Event)
.protected SerializationHandler
getSerializationHandler
(String topic) protected ID
getTarget
(org.osgi.service.event.Event eventToSend) Get the target receiver for the eventToSend.protected void
handleSendMessageException
(String message, org.osgi.service.event.Event eventToSend, Object[] messageParams, IOException exception) Handle any exceptions occuring as part of Event serialization or message send.protected boolean
handleSharedObjectMsg
(ID fromID, SharedObjectMsg msg) Handle the shared object message.protected final boolean
Override of BaseSharedObject.handleSharedObjectMsgEvent.protected void
localDispatch
(org.osgi.service.event.Event dispatchedEvent, boolean isAsync) Locally dispatch an Event.protected void
Log an error.protected void
Log an error.protected void
logWarning
(String message) Log a warning.protected void
logWarning
(String message, Throwable exception) Log a warning.protected void
notifyPostLocalDispatch
(org.osgi.service.event.Event event) Notification called after local dispatch has been done.protected void
notifyPostSendMessage
(org.osgi.service.event.Event eventSent) Method called aftersendMessage(Event)
is called (typically from withinpostEvent(Event)
), but prior to local dispatch.protected org.osgi.service.event.Event
notifyPreLocalDispatch
(org.osgi.service.event.Event event) Method called from withinlocalDispatch(Event, boolean)
prior to actual deliver to matchingEventHandler
s.protected void
notifyReceivedEvent
(ID fromID, org.osgi.service.event.Event receivedEvent) void
postEvent
(org.osgi.service.event.Event event) Post an event for asynchronous delivery via this distributed event admin.boolean
removeEventTopicFilters
(String[] filters) void
sendEvent
(org.osgi.service.event.Event event) Send the given event synchronously.protected void
sendMessage
(org.osgi.service.event.Event eventToSend) Send the event as a shared object message.void
start()
Start this distributed event admin instance.void
stop()
Stop this distributed event admin instance.Methods inherited from class org.eclipse.ecf.core.sharedobject.BaseSharedObject
addEventProcessor, clearEventProcessors, creationCompleted, destroyRemote, destroySelf, destroySelfLocal, dispose, fireEventProcessors, getAdapter, getConfig, getConnectedID, getContext, getGroupMemberIDs, getHomeContainerID, getID, getLocalContainerID, getProperties, getReplicaDescription, getReplicaDescriptions, getSharedObjectMsgFromEvent, handleEvent, handleEvents, handleSharedObjectCreateResponseEvent, handleSharedObjectMsg, handleUnhandledEvent, init, initialize, isConnected, isPrimary, log, log, removeEventProcessor, replicateToRemoteContainers, sendSharedObjectMsgTo, sendSharedObjectMsgToPrimary, sendSharedObjectMsgToSelf, trace, traceCatching, traceEntering, traceEntering, traceEntering, traceExiting, traceExiting
-
Field Details
-
ignoreSerializationExceptions
protected static boolean ignoreSerializationExceptions- Since:
- 1.2
- Restriction:
- protected non-final for unit tests only!!!
-
eventHandlerTracker
protected org.eclipse.ecf.internal.remoteservice.eventadmin.EventHandlerTracker eventHandlerTracker- Since:
- 1.2
- Restriction:
- This field is not intended to be referenced by clients.
-
context
- Since:
- 1.2
-
-
Constructor Details
-
DistributedEventAdmin
protected DistributedEventAdmin()- Restriction:
-
DistributedEventAdmin
Create a Distributed EventAdmin implementation.- Parameters:
context
- the BundleContext to be used. Must not benull
.log
- theLogService
to use. May benull
. Ifnull
, then a LogTracker is created and used to find and use aLogService
.- Since:
- 1.1
-
DistributedEventAdmin
Create a Distributed EventAdmin implementation.- Parameters:
context
- the BundleContext to be used. Must not benull
.- Since:
- 1.1
-
-
Method Details
-
start
public void start()Start this distributed event admin instance. This method should be called prior to registering this object as anEventAdmin
implementation with the OSGi service registry. -
stop
public void stop()Stop this distributed event admin instance. This method should be called after unregistering theServiceRegistration
created on registration with the OSGi service registry. -
sendEvent
public void sendEvent(org.osgi.service.event.Event event) Send the given event synchronously. The default implementation of this method simply does a local-only dispatch toEventHandler
s. It does not attempt to distribute the given event as doespostEvent(Event)
.- Specified by:
sendEvent
in interfaceorg.osgi.service.event.EventAdmin
- Parameters:
event
- the Event to send synchronously to localEventHandler
s (only). Must not benull
.
-
postEvent
public void postEvent(org.osgi.service.event.Event event) Post an event for asynchronous delivery via this distributed event admin. This is the primary entry point for the distributed event admin implementation for asynchronous delivery to a set of receivers (known to the this shared object and it's enclosingIContainer
. The event to post must not benull
.This implementation goes through the following steps
- Call
getEventToSend(Event)
. If the Event returned from getEventToSend isnull
, then the following three method calls do not occur, and postEvent returns immediately. - Call
sendMessage(Event)
with the non-null
result ofgetEventToSend(Event)
- Call
notifyPostSendMessage(Event)
- Call
localDispatch(Event, boolean)
- Specified by:
postEvent
in interfaceorg.osgi.service.event.EventAdmin
- Parameters:
event
- the Event to send asynchronously to matchingEventHandler
s. Must not benull
.- Since:
- 1.1
- Call
-
sendMessage
protected void sendMessage(org.osgi.service.event.Event eventToSend) Send the event as a shared object message. The given event will be serialized and sent viaBaseSharedObject.sendSharedObjectMsgTo(ID, SharedObjectMsg)
.Prior to actual sending, the
getTarget(Event)
method will be called, to allow subclasses to determine the target receiver. Then thecreateMessageDataFromEvent(ID, Event)
method is called, to create an Object[] of data for sending in the message. The Object[] returned fromcreateMessageDataFromEvent(ID, Event)
must be serializable. SeecreateMessageDataFromEvent(ID, Event)
.Subclasses may override this method to customize or replace this sendMessage behavior.
If an exception occurs on serialization or sending, the
handleSendMessageException(String, Event, Object[], IOException)
method will be called to handle it.- Parameters:
eventToSend
- the event to send. Will not benull
.- Since:
- 1.1
-
createMessageDataFromEvent
protected Object[] createMessageDataFromEvent(ID target, org.osgi.service.event.Event eventToSend) throws NotSerializableException Create message data for deliver to a target (which could benull
to designate multiple target receivers), The resulting Object[] must be Serializable and in a form that receivers can deserialize viacreateEventFromMessageData(ID, Object[])
on the receiver.The default implementation creates a single
EventMessage
instance and adds it to an Object[] of length 1.Subclasses may override as appropriate to customize the serialization of the given eventToSend.
Subclasses may override as appropriate. If this method is overridden, then
createEventFromMessageData(ID, Object[])
should also be overridden as well on the receiver.- Parameters:
target
- the targetID
that is the intended receiver returned fromgetTarget(Event)
.eventToSend
- the event to send. Will not benull
.- Returns:
- Object[] the actual message data that will be serialized (must be
Serializable to use in
sendMessage(Event)
). The default implementation creates a singleEventMessage
instance and adds it to an Object[] of length 1. - Throws:
NotSerializableException
- if the eventToSend cannot be serialized.- Since:
- 1.1
-
getSerializationHandler
- Parameters:
topic
- topic- Returns:
- SerializationHandler the serialization handler associated with topic
- Since:
- 1.2
-
createEventFromMessageData
Create a localEvent
from deserialized messageData. The fromID will be a non-null
ID
instance that is the container ID of the sender DistributedEventAdmin. The default implementation assumes that a singleEventMessage
is in the first array element of the messageData, casts the messageData[0] to EventMessage, and then returns eventMessage.getEvent().Subclasses can override as appropriate. If this method is overridden, then
createMessageDataFromEvent(ID, Event)
should also be overridden as well on the sender.- Parameters:
fromID
- the ID of the message sender. Will not benull
.messageData
- Object[] received from fromID. Will be a deserialized local version of the Object[] from fromID.- Returns:
- Event to be delivered to local
EventHandler
s. Should not benull
. - Since:
- 1.1
-
handleSendMessageException
protected void handleSendMessageException(String message, org.osgi.service.event.Event eventToSend, Object[] messageParams, IOException exception) Handle any exceptions occuring as part of Event serialization or message send. The default is to calllogError(String, Throwable)
with the eventToSend and messageParams appended to the message parameter.- Parameters:
message
- a message associated with the exception.eventToSend
- the event that was to be sent.messageParams
- the message params that were to beexception
- exception- Since:
- 1.1
-
getTarget
Get the target receiver for the eventToSend. The returnedID
will be used to send a shared object message to either a singleIContainer
, or a group ofIContainer
s. To send to the entire group, this method should returnnull
. The default implementation is to returnnull
, meaning that the given eventToSend is to be sent to all receivers connected to this shared object's enclosingIContainer
.- Parameters:
eventToSend
- the eventToSend. Will not benull
.- Returns:
- ID the ID target for
sendMessage(Event)
to send to. May benull
.null
is the default implementation, meaning that the Event will be delivered to all members of the group known to this shared object'sIContainer
. - Since:
- 1.1
-
getEventToSend
protected org.osgi.service.event.Event getEventToSend(org.osgi.service.event.Event event) Get the actual event to pass tosendMessage(Event)
. The default implementation of this method is to simply return the event passed in as the method argument.Subclasses may override...to filter or transform the event prior to calling
sendMessage(Event)
.- Parameters:
event
- the event. Will not benull
.- Returns:
- Event to send. By default, the event provided as the argument is returned.
- Since:
- 1.1
-
notifyPostSendMessage
protected void notifyPostSendMessage(org.osgi.service.event.Event eventSent) Method called aftersendMessage(Event)
is called (typically from withinpostEvent(Event)
), but prior to local dispatch. The default implementation is to do nothing.- Parameters:
eventSent
- the event that was sent. Will not benull
.- Since:
- 1.1
-
notifyPreLocalDispatch
protected org.osgi.service.event.Event notifyPreLocalDispatch(org.osgi.service.event.Event event) Method called from withinlocalDispatch(Event, boolean)
prior to actual deliver to matchingEventHandler
s. The default implementation returns the given event. Subclasses may override as appropriate. If the returned Event isnull
then no local dispatch will occur for the given Event.Subclasses may override as appropriate.
- Parameters:
event
- the Event to dispatch. Will not benull
.- Returns:
- Event the event to actually dispatch. If
null
, no local dispatch is done for this event. - Since:
- 1.1
-
notifyPostLocalDispatch
protected void notifyPostLocalDispatch(org.osgi.service.event.Event event) Notification called after local dispatch has been done. The default implemenation does nothing. Note that this method is called by the thread that callslocalDispatch(Event, boolean)
, and if the actual dispatch is done by another thread (i.e. second param to localDispatch istrue
), then the dispatch could occur before, after, or during the actual handling via the matchingEventHandler
s.Subclasses may override as appropriate.
- Parameters:
event
- the Event that was delivered to matchingEventHandler
s. Will not benull
.- Since:
- 1.1
-
localDispatch
protected void localDispatch(org.osgi.service.event.Event dispatchedEvent, boolean isAsync) Locally dispatch an Event. This method is used to deliver anEvent
to matchingEventHandler
s that are registered in the local OSGi service registry.- Parameters:
dispatchedEvent
- the Event to dispatch. Will not benull
.isAsync
-true
if the dispatch should be done asynchronously (non-blocking),false
if the dispatch should be done synchronously.
-
notifyReceivedEvent
- Parameters:
fromID
- fromIDreceivedEvent
- received event- Since:
- 1.1
-
logWarning
Log a warning.Subclasses may override as appropriate.
- Parameters:
message
- the message to include in the warning. Should not benull
.- Since:
- 1.1
-
logWarning
Log a warning.Subclasses may override as appropriate.
- Parameters:
message
- the message to include in the warning. Should not benull
.exception
- the exception to include in the warning. May benull
. If non-null
then exception will be printed to System.out.- Since:
- 1.1
-
logError
Log an error.Subclasses may override as appropriate.
- Parameters:
message
- the message to include in the error. Should not benull
.- Since:
- 1.1
-
logError
Log an error.Subclasses may override as appropriate.
- Parameters:
message
- the message to include in the error. Should not benull
.exception
- the exception to include in the warning. May benull
. If non-null
then exception will be printed to System.out.
-
addEventTopicFilters
- Parameters:
filters
- topic filters to add- Returns:
- boolean true if given filters added, false otherwise
- Since:
- 1.2
-
removeEventTopicFilters
- Parameters:
filters
- topic filters to add- Returns:
- boolean true if given filters added, false otherwise
- Since:
- 1.2
-