|
||||||||||
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
public class BaseSharedObject
Base class for shared object classes. This base class provides a number of
utility method for subclasses to use for tracing (e.g.
traceCatching(String, Throwable)
, traceEntering(String)
,
traceExiting(String)
) logging (e.g.
log(int, String, Throwable)
), as well as methods to access the
ISharedObjectContext
for the shared object instance (e.g.
getID()
, getHomeContainerID()
, getContext()
,
getConfig()
, getProperties()
, isConnected()
,
isPrimary()
, etc). Also provided are a number of methods for
sending messages to remote replica shared objects (e.g.
sendSharedObjectMsgTo(ID, SharedObjectMsg)
,
sendSharedObjectMsgToPrimary(SharedObjectMsg)
,
sendSharedObjectMsgToSelf(SharedObjectMsg)
) and methods for
replicating oneself to remote containers (e.g.
replicateToRemoteContainers(ID[])
). Finally, object lifecycle
methods are also provided (e.g. initialize()
,
creationCompleted()
, dispose(ID)
).
Subclasses may use and override these methods as appropriate.
Field Summary | |
---|---|
protected static int |
DESTROYREMOTE_CODE
|
protected static int |
DESTROYSELFLOCAL_CODE
|
Constructor Summary | |
---|---|
BaseSharedObject()
|
Method Summary | |
---|---|
boolean |
addEventProcessor(IEventProcessor proc)
Add an event processor to the set of event processors available. |
void |
clearEventProcessors()
Clear event processors. |
protected void |
creationCompleted()
Called by replication strategy code (e.g. |
protected void |
destroyRemote(ID remoteID)
|
protected void |
destroySelf()
Destroy this shared object in the context of the current container. |
protected void |
destroySelfLocal()
Destroy the local copy of this shared object in the current container. |
void |
dispose(ID containerID)
Method called by the ISharedObjectContainer upon ISharedObject destruction. |
protected void |
fireEventProcessors(Event event)
Fire the current set of event processors with given event. |
java.lang.Object |
getAdapter(java.lang.Class adapter)
|
protected ISharedObjectConfig |
getConfig()
Get the config for this shared object. |
protected ID |
getConnectedID()
|
protected ISharedObjectContext |
getContext()
Get the shared object context for this object. |
protected ID[] |
getGroupMemberIDs()
Get IDs of remote containers currently in this group. |
protected ID |
getHomeContainerID()
|
ID |
getID()
Return the ID for this 'identifiable' object. |
protected ID |
getLocalContainerID()
|
protected java.util.Map |
getProperties()
|
protected ReplicaSharedObjectDescription |
getReplicaDescription(ID receiver)
Get a ReplicaSharedObjectDescription for a replica to be created on a given receiver. |
protected ReplicaSharedObjectDescription[] |
getReplicaDescriptions(ID[] receivers)
This method is called by replicateToRemoteContainers to determine the ReplicaSharedObjectDescriptions associated with the given receivers. |
protected SharedObjectMsg |
getSharedObjectMsgFromEvent(ISharedObjectMessageEvent event)
Get SharedObjectMsg from ISharedObjectMessageEvent. |
void |
handleEvent(Event event)
Handle Event passed to this IEventHandler. |
void |
handleEvents(Event[] events)
Handle Events passed to this IEventHandler. |
protected boolean |
handleSharedObjectCreateResponseEvent(ISharedObjectCreateResponseEvent createResponseEvent)
Handle a ISharedObjectCreateResponseEvent. |
protected boolean |
handleSharedObjectMsg(SharedObjectMsg msg)
SharedObjectMsg handler method. |
protected boolean |
handleSharedObjectMsgEvent(ISharedObjectMessageEvent event)
Handle a ISharedObjectMessageEvent. |
protected void |
handleUnhandledEvent(Event event)
Method called when an event is not handled by any event processor. |
void |
init(ISharedObjectConfig initData)
Initialize this ISharedObject. |
protected void |
initialize()
Initialize this shared object. |
protected boolean |
isConnected()
|
protected boolean |
isPrimary()
|
protected void |
log(int code,
java.lang.String method,
java.lang.Throwable e)
|
protected void |
log(java.lang.String method,
java.lang.Throwable e)
|
boolean |
removeEventProcessor(IEventProcessor proc)
Remove an event processor from the set of event processors available to this object. |
protected void |
replicateToRemoteContainers(ID[] remoteContainers)
Replicate this shared object to a given set of remote containers. |
protected void |
sendSharedObjectMsgTo(ID toID,
SharedObjectMsg msg)
Send SharedObjectMessage to container with given ID. |
protected void |
sendSharedObjectMsgToPrimary(SharedObjectMsg msg)
Send SharedObjectMsg to this shared object's primary instance. |
protected void |
sendSharedObjectMsgToSelf(SharedObjectMsg msg)
Send SharedObjectMsg to local shared object. |
protected void |
trace(java.lang.String method,
java.lang.String message)
|
protected void |
traceCatching(java.lang.String method,
java.lang.Throwable t)
|
protected void |
traceEntering(java.lang.String methodName)
|
protected void |
traceEntering(java.lang.String methodName,
java.lang.Object param)
|
protected void |
traceEntering(java.lang.String methodName,
java.lang.Object[] params)
|
protected void |
traceExiting(java.lang.String methodName)
|
protected void |
traceExiting(java.lang.String methodName,
java.lang.Object result)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int DESTROYREMOTE_CODE
protected static final int DESTROYSELFLOCAL_CODE
Constructor Detail |
---|
public BaseSharedObject()
Method Detail |
---|
public final void init(ISharedObjectConfig initData) throws SharedObjectInitException
ISharedObject
init
in interface ISharedObject
initData
- the initialization data passed by the ISharedObjectContainer
upon initialization
SharedObjectInitException
- thrown by ISharedObject to halt initialization.
ISharedObjectContainers must respond to such an exception
by halting the addition of the ISharedObject instance and
treating it as not in the container.protected void initialize() throws SharedObjectInitException
SharedObjectInitException
- if initialization should throwprotected void creationCompleted()
public void dispose(ID containerID)
ISharedObject
dispose
in interface ISharedObject
containerID
- the ID of the container that is disposing this ISharedObjectpublic java.lang.Object getAdapter(java.lang.Class adapter)
getAdapter
in interface org.eclipse.core.runtime.IAdaptable
public void handleEvent(Event event)
ISharedObject
handleEvent
in interface ISharedObject
event
- the Event for the implementer to handlepublic boolean addEventProcessor(IEventProcessor proc)
proc
- the event processor to add. Must not be null
.
true
if actually added, false
otherwise.public boolean removeEventProcessor(IEventProcessor proc)
proc
- the event processor to remove. Must not be null
.
true
if actually removed, false
otherwise.public void clearEventProcessors()
protected void handleUnhandledEvent(Event event)
event
- the event that was not handled.protected void fireEventProcessors(Event event)
event
- the event to deliver to event processors.public void handleEvents(Event[] events)
ISharedObject
handleEvents
in interface ISharedObject
events
- the Events [] for the implementer to handlepublic ID getID()
IIdentifiable
null
.
getID
in interface IIdentifiable
null
.protected final ISharedObjectConfig getConfig()
init(ISharedObjectConfig)
. Will not be null
as long as the init method
is called prior to this method being called.protected final ISharedObjectContext getContext()
null
.protected ID getHomeContainerID()
null
as long as the init(ISharedObjectConfig)
method has been called (by container) as a result
of ISharedObjectManager.addSharedObject(ID, ISharedObject, Map)
.protected ID getLocalContainerID()
null
if
the shared object is *not* in a local container (i.e. has been removed from the container).protected ID getConnectedID()
null
if the surrounding container is not currently connected.protected final boolean isConnected()
true
if the surrounding container is currently connected, false
otherwise.protected final boolean isPrimary()
true
if this shared object replica is the primary. The definition of primary
is whether the getLocalContainerID()
and getHomeContainerID()
values are equal.protected final java.util.Map getProperties()
init(ISharedObjectConfig)
.protected void destroySelf()
protected void destroySelfLocal()
protected void destroyRemote(ID remoteID) throws java.io.IOException
remoteID
- the ID of the remote container where the replica should be destroyed.
java.io.IOException
- if the destroy message cannot be sent (i.e. due to disconnection, etc).protected void sendSharedObjectMsgTo(ID toID, SharedObjectMsg msg) throws java.io.IOException
toID
- the target container ID for the SharedObjectMsg. If null, the
given message is sent to all other containers currently in
groupmsg
- the message instance to send
java.io.IOException
- thrown if the local container is not connected or unable to
send for other reasonprotected void sendSharedObjectMsgToPrimary(SharedObjectMsg msg) throws java.io.IOException
msg
- the message instance to send
java.io.IOException
- throws if the local container is not connect or unable to
send for other reasonprotected void sendSharedObjectMsgToSelf(SharedObjectMsg msg)
msg
- the message instance to send.protected SharedObjectMsg getSharedObjectMsgFromEvent(ISharedObjectMessageEvent event)
event
-
protected boolean handleSharedObjectMsgEvent(ISharedObjectMessageEvent event)
event
- the event to handle
protected boolean handleSharedObjectCreateResponseEvent(ISharedObjectCreateResponseEvent createResponseEvent)
createResponseEvent
- the ISharedObjectCreateResponseEvent received
protected boolean handleSharedObjectMsg(SharedObjectMsg msg)
handleSharedObjectMsgEvent(ISharedObjectMessageEvent)
when a
SharedObjectMsg is received either from a local source or a remote
source. This default implementation simply returns false so that other
processing of of the given msg can occur. Subclasses should override this
behavior to define custom logic for handling SharedObjectMsgs.
msg
- the SharedObjectMsg received
protected ReplicaSharedObjectDescription getReplicaDescription(ID receiver)
receiver
- the receiver the ReplicaSharedObjectDescription is for
protected ReplicaSharedObjectDescription[] getReplicaDescriptions(ID[] receivers)
receivers
- an ID[] of the intended receivers for the resulting
ReplicaSharedObjectDescriptions. If null, then the entire
current group is assumed to be the target, and this
method should return a ReplicaSharedObjectDescriptions array
of length 1, with a single ReplicaSharedObjectDescriptions for
all target receivers.
protected ID[] getGroupMemberIDs()
ISharedObjectContext.getGroupMemberIDs()
protected void replicateToRemoteContainers(ID[] remoteContainers)
remoteContainers
- the set of remote containers to replicate to. If null, all
containers in the current group are sent a message to create a
replica of this shared object.protected void log(int code, java.lang.String method, java.lang.Throwable e)
protected void log(java.lang.String method, java.lang.Throwable e)
protected void traceEntering(java.lang.String methodName)
protected void traceEntering(java.lang.String methodName, java.lang.Object[] params)
protected void traceEntering(java.lang.String methodName, java.lang.Object param)
protected void traceExiting(java.lang.String methodName)
protected void traceExiting(java.lang.String methodName, java.lang.Object result)
protected void traceCatching(java.lang.String method, java.lang.Throwable t)
protected void trace(java.lang.String method, java.lang.String message)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |