|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.ecf.core.sharedobject.BaseSharedObject org.eclipse.ecf.remoteservice.eventadmin.DistributedEventAdmin
public class DistributedEventAdmin
Field Summary |
---|
Fields inherited from class org.eclipse.ecf.core.sharedobject.BaseSharedObject |
---|
DESTROYREMOTE_CODE, DESTROYSELFLOCAL_CODE |
Constructor Summary | |
---|---|
DistributedEventAdmin(org.osgi.framework.BundleContext context)
Create a Distributed EventAdmin implementation. |
|
DistributedEventAdmin(org.osgi.framework.BundleContext context,
org.osgi.service.log.LogService log)
Create a Distributed EventAdmin implementation. |
Method Summary | |
---|---|
protected org.osgi.service.event.Event |
createEventFromMessageData(ID fromID,
java.lang.Object[] messageData)
Create a local Event from deserialized messageData. |
protected java.lang.Object[] |
createMessageDataFromEvent(ID target,
org.osgi.service.event.Event eventToSend)
Create message data for deliver to a target (which could be null to designate multiple target receivers), The resulting
Object[] must be Serializable and in a form that receivers can
deserialize via createEventFromMessageData(ID, Object[]) on the
receiver. |
protected org.osgi.service.event.Event |
getEventToSend(org.osgi.service.event.Event event)
Get the actual event to pass to sendMessage(Event) . |
protected ID |
getTarget(org.osgi.service.event.Event eventToSend)
Get the target receiver for the eventToSend. |
protected void |
handleSendMessageException(java.lang.String message,
org.osgi.service.event.Event eventToSend,
java.lang.Object[] messageParams,
java.io.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 boolean |
handleSharedObjectMsgEvent(ISharedObjectMessageEvent event)
Override of BaseSharedObject.handleSharedObjectMsgEvent. |
protected void |
localDispatch(org.osgi.service.event.Event dispatchedEvent,
boolean isAsync)
Locally dispatch an Event. |
protected void |
logError(java.lang.String message)
Log an error. |
protected void |
logError(java.lang.String message,
java.lang.Throwable exception)
Log an error. |
protected void |
logWarning(java.lang.String message)
Log a warning. |
protected void |
logWarning(java.lang.String message,
java.lang.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 after sendMessage(Event) is called (typically from
within postEvent(Event) ), but prior to local dispatch. |
protected org.osgi.service.event.Event |
notifyPreLocalDispatch(org.osgi.service.event.Event event)
Method called from within localDispatch(Event, boolean) prior to
actual deliver to matching EventHandler 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. |
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DistributedEventAdmin(org.osgi.framework.BundleContext context, org.osgi.service.log.LogService log)
context
- the BundleContext to be used. Must not be null
.log
- the LogService
to use. May be null
. If
null
, then a LogTracker
is created and
used to find and use a LogService
.public DistributedEventAdmin(org.osgi.framework.BundleContext context)
context
- the BundleContext to be used. Must not be null
.Method Detail |
---|
public void start()
EventAdmin
implementation
with the OSGi service registry.
public void stop()
ServiceRegistration
created on
registration with the OSGi service registry.
public void sendEvent(org.osgi.service.event.Event event)
EventHandler
s.
It does not attempt to distribute the given event as does
postEvent(Event)
.
sendEvent
in interface org.osgi.service.event.EventAdmin
event
- the Event to send synchronously to local EventHandler
s
(only). Must not be null
.public void postEvent(org.osgi.service.event.Event event)
IContainer
. The event
to post must not be null
.
This implementation goes through the following steps
getEventToSend(Event)
. If the Event returned from
getEventToSend is null
, then the following three method
calls do not occur, and postEvent returns immediately.sendMessage(Event)
with the non-null
result of getEventToSend(Event)
notifyPostSendMessage(Event)
localDispatch(Event, boolean)
postEvent
in interface org.osgi.service.event.EventAdmin
event
- the Event to send asynchronously to matching
EventHandler
s. Must not be null
.protected void sendMessage(org.osgi.service.event.Event eventToSend)
BaseSharedObject.sendSharedObjectMsgTo(ID, SharedObjectMsg)
.
Prior to actual sending, the
getTarget(Event)
method will be
called, to allow subclasses to determine the target receiver. Then the
createMessageDataFromEvent(ID, Event)
method is called, to
create an Object[] of data for sending in the message. The Object[]
returned from createMessageDataFromEvent(ID, Event)
must be
serializable. See createMessageDataFromEvent(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.
eventToSend
- the event to send. Will not be null
.protected java.lang.Object[] createMessageDataFromEvent(ID target, org.osgi.service.event.Event eventToSend) throws java.io.NotSerializableException
null
to designate multiple target receivers), The resulting
Object[] must be Serializable and in a form that receivers can
deserialize via createEventFromMessageData(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.
target
- the target ID
that is the intended receiver returned
from getTarget(Event)
.eventToSend
- the event to send. Will not be null
.
sendMessage(Event)
). The default
implementation creates a single EventMessage
instance and
adds it to an Object[] of length 1.
java.io.NotSerializableException
- if the eventToSend cannot be serialized.protected org.osgi.service.event.Event createEventFromMessageData(ID fromID, java.lang.Object[] messageData)
Event
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 single EventMessage
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.
fromID
- the ID of the message sender. Will not be null
.messageData
- Object[] received from fromID. Will be a deserialized
local version of the Object[] from fromID.
EventHandler
s. Should not
be null
.protected void handleSendMessageException(java.lang.String message, org.osgi.service.event.Event eventToSend, java.lang.Object[] messageParams, java.io.IOException exception)
logError(String, Throwable)
with
the eventToSend and messageParams appended to the message parameter.
message
- a message associated with the exception.eventToSend
- the event that was to be sent.messageParams
- the message params that were to beprotected ID getTarget(org.osgi.service.event.Event eventToSend)
ID
will
be used to send a shared object message to either a single
IContainer
, or a group of IContainer
s. To send to the
entire group, this method should return null
. The default
implementation is to return null
, meaning that the given
eventToSend is to be sent to all receivers connected to this shared
object's enclosing IContainer
.
eventToSend
- the eventToSend. Will not be null
.
sendMessage(Event)
to send to. May
be null
. null
is the default
implementation, meaning that the Event will be delivered to all
members of the group known to this shared object's
IContainer
.protected org.osgi.service.event.Event getEventToSend(org.osgi.service.event.Event event)
sendMessage(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)
.
event
- the event. Will not be null
.
protected void notifyPostSendMessage(org.osgi.service.event.Event eventSent)
sendMessage(Event)
is called (typically from
within postEvent(Event)
), but prior to local dispatch. The
default implementation is to do nothing.
eventSent
- the event that was sent. Will not be null
.protected org.osgi.service.event.Event notifyPreLocalDispatch(org.osgi.service.event.Event event)
localDispatch(Event, boolean)
prior to
actual deliver to matching EventHandler
s. The default
implementation returns the given event. Subclasses may override as
appropriate. If the returned Event is null
then no local
dispatch will occur for the given Event.
Subclasses may override as appropriate.
event
- the Event to dispatch. Will not be null
.
null
, no
local dispatch is done for this event.protected void notifyPostLocalDispatch(org.osgi.service.event.Event event)
localDispatch(Event, boolean)
, and if the actual
dispatch is done by another thread (i.e. second param to localDispatch is
true
), then the dispatch could occur before, after, or
during the actual handling via the matching EventHandler
s.
Subclasses may override as appropriate.
event
- the Event that was delivered to matching EventHandler
s. Will not be null
.protected void localDispatch(org.osgi.service.event.Event dispatchedEvent, boolean isAsync)
Event
to matching EventHandler
s that are registered in
the local OSGi service registry.
dispatchedEvent
- the Event to dispatch. Will not be null
.isAsync
- true
if the dispatch should be done
asynchronously (non-blocking), false
if the
dispatch should be done synchronously.protected boolean handleSharedObjectMsg(ID fromID, SharedObjectMsg msg)
EventHandler
s.
This implementation does the following:
SharedObjectMsg.getMethod()
matches the appropriate String.null
, then call
protected void notifyReceivedEvent(ID fromID, org.osgi.service.event.Event receivedEvent)
protected final boolean handleSharedObjectMsgEvent(ISharedObjectMessageEvent event)
handleSharedObjectMsgEvent
in class BaseSharedObject
event
- the event to handle
protected void logWarning(java.lang.String message)
Subclasses may override as appropriate.
message
- the message to include in the warning. Should not be
null
.protected void logWarning(java.lang.String message, java.lang.Throwable exception)
Subclasses may override as appropriate.
message
- the message to include in the warning. Should not be
null
.exception
- the exception to include in the warning. May be
null
. If non-null
then exception
will be printed to System.out.protected void logError(java.lang.String message)
Subclasses may override as appropriate.
message
- the message to include in the error. Should not be
null
.protected void logError(java.lang.String message, java.lang.Throwable exception)
Subclasses may override as appropriate.
message
- the message to include in the error. Should not be
null
.exception
- the exception to include in the warning. May be
null
. If non-null
then exception
will be printed to System.out.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |