Class BaseSharedObject
java.lang.Object
org.eclipse.ecf.core.sharedobject.BaseSharedObject
- All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable
,IIdentifiable
,ISharedObject
- Direct Known Subclasses:
DistributedEventAdmin
,OptimisticSharedObject
,RegistrySharedObject
,TransactionSharedObject
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
Modifier and TypeFieldDescriptionprotected static final int
protected static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add an event processor to the set of event processors available.void
Clear event processors.protected void
Called by replication strategy code (e.g.protected void
destroyRemote
(ID remoteID) protected void
Destroy this shared object in the context of the current container.protected void
Destroy the local copy of this shared object in the current container.void
Method called by the ISharedObjectContainer upon ISharedObject destruction.protected void
fireEventProcessors
(Event event) Fire the current set of event processors with given event.getAdapter
(Class adapter) protected final ISharedObjectConfig
Get the config for this shared object.protected ID
protected final ISharedObjectContext
Get the shared object context for this object.protected ID[]
Get IDs of remote containers currently in this group.protected ID
getID()
Return the ID for this 'identifiable' object.protected ID
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
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
(ID fromID, SharedObjectMsg msg) protected boolean
SharedObjectMsg handler method.protected boolean
Handle a ISharedObjectMessageEvent.protected void
handleUnhandledEvent
(Event event) Method called when an event is not handled by any event processor.final void
init
(ISharedObjectConfig initData) Initialize this ISharedObject.protected void
Initialize this shared object.protected final boolean
protected final boolean
protected void
protected void
boolean
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
Send SharedObjectMsg to this shared object's primary instance.protected void
Send SharedObjectMsg to local shared object.protected void
protected void
traceCatching
(String method, Throwable t) protected void
traceEntering
(String methodName) protected void
traceEntering
(String methodName, Object param) protected void
traceEntering
(String methodName, Object[] params) protected void
traceExiting
(String methodName) protected void
traceExiting
(String methodName, Object result)
-
Field Details
-
DESTROYREMOTE_CODE
protected static final int DESTROYREMOTE_CODE- See Also:
-
DESTROYSELFLOCAL_CODE
protected static final int DESTROYSELFLOCAL_CODE- See Also:
-
-
Constructor Details
-
BaseSharedObject
public BaseSharedObject()
-
-
Method Details
-
initialize
Initialize this shared object. Subclasses may override as appropriate to define custom initialization behavior. If initialization should fail, then a SharedObjectInitException should be thrown by implementing code. Also, subclasses overriding this method should call super.initialize() before running their own code.- Throws:
SharedObjectInitException
- if initialization should throw
-
creationCompleted
protected void creationCompleted()Called by replication strategy code (e.g. two phase commit) when creation is completed (i.e. when transactional replication completed successfully). Subclasses that need to be notified when creation is completed should override this method. -
dispose
Description copied from interface:ISharedObject
Method called by the ISharedObjectContainer upon ISharedObject destruction. Once this method is called, no more Events will be passed to a ISharedObject until the init method is called again.- Specified by:
dispose
in interfaceISharedObject
- Parameters:
containerID
- the ID of the container that is disposing this ISharedObject
-
getAdapter
- Specified by:
getAdapter
in interfaceorg.eclipse.core.runtime.IAdaptable
-
handleEvent
Description copied from interface:ISharedObject
Handle Event passed to this IEventHandler.- Specified by:
handleEvent
in interfaceISharedObject
- Parameters:
event
- the Event for the implementer to handle
-
addEventProcessor
Add an event processor to the set of event processors available.- Parameters:
proc
- the event processor to add. Must not benull
.- Returns:
true
if actually added,false
otherwise.
-
removeEventProcessor
Remove an event processor from the set of event processors available to this object.- Parameters:
proc
- the event processor to remove. Must not benull
.- Returns:
true
if actually removed,false
otherwise.
-
clearEventProcessors
public void clearEventProcessors()Clear event processors. -
handleUnhandledEvent
Method called when an event is not handled by any event processor.- Parameters:
event
- the event that was not handled.
-
fireEventProcessors
Fire the current set of event processors with given event.- Parameters:
event
- the event to deliver to event processors.
-
handleEvents
Description copied from interface:ISharedObject
Handle Events passed to this IEventHandler.- Specified by:
handleEvents
in interfaceISharedObject
- Parameters:
events
- the Events [] for the implementer to handle
-
getID
Description copied from interface:IIdentifiable
Return the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May returnnull
.- Specified by:
getID
in interfaceIIdentifiable
- Returns:
- the ID for this identifiable object. May return
null
.
-
getConfig
Get the config for this shared object.- Returns:
- ISharedObjectConfig for this object. The ISharedObjectConfig is
set within
init(ISharedObjectConfig)
. Will not benull
as long as the init method is called prior to this method being called.
-
getContext
Get the shared object context for this object.- Returns:
- ISharedObjectContext the context. Will not be
null
.
-
getHomeContainerID
- Returns:
- ID that is the home container ID (primary) for this shared object. Will not be
null
as long as theinit(ISharedObjectConfig)
method has been called (by container) as a result ofISharedObjectManager.addSharedObject(ID, ISharedObject, Map)
.
-
getLocalContainerID
- Returns:
- ID that is the local container ID for this shared object. Will be
null
if the shared object is *not* in a local container (i.e. has been removed from the container).
-
getConnectedID
- Returns:
- ID the connected ID for the container that contains this shared object. Will be non-
null
if the surrounding container is not currently connected.
-
isConnected
protected final boolean isConnected()- Returns:
true
if the surrounding container is currently connected,false
otherwise.
-
isPrimary
protected final boolean isPrimary()- Returns:
true
if this shared object replica is the primary. The definition of primary is whether thegetLocalContainerID()
andgetHomeContainerID()
values are equal.
-
getProperties
- Returns:
- Map any properties associated with this shared object via the ISharedObjectConfig provided
upon
init(ISharedObjectConfig)
.
-
destroySelf
protected void destroySelf()Destroy this shared object in the context of the current container. Destroys both local copy and any replicas present in remote containers. -
destroySelfLocal
protected void destroySelfLocal()Destroy the local copy of this shared object in the current container. -
destroyRemote
- Parameters:
remoteID
- the ID of the remote container where the replica should be destroyed.- Throws:
IOException
- if the destroy message cannot be sent (i.e. due to disconnection, etc).
-
getReplicaDescription
Get a ReplicaSharedObjectDescription for a replica to be created on a given receiver.- Parameters:
receiver
- the receiver the ReplicaSharedObjectDescription is for- Returns:
- ReplicaSharedObjectDescription to be associated with given receiver. A non-null ReplicaSharedObjectDescription must be returned.
-
getReplicaDescriptions
This method is called by replicateToRemoteContainers to determine the ReplicaSharedObjectDescriptions associated with the given receivers. Receivers may be null (meaning that all in group are to be receivers), and if so then this method should return a ReplicaSharedObjectDescription [] of length 1 with a single ReplicaSharedObjectDescription that will be used for all receivers. If receivers is non-null, then the ReplicaSharedObjectDescription [] result must be of same length as the receivers array. This method calls the getReplicaDescription method to create a replica description for each receiver. If this method returns null, null replication is done.- Parameters:
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.- Returns:
- ReplicaSharedObjectDescription[] to determine replica descriptions for each receiver. A null return value indicates that no replicas are to be created. If the returned array is not null, then it must be of same length as the receivers parameter.
-
getGroupMemberIDs
Get IDs of remote containers currently in this group. This method consults the current container context to retrieve the current group membership- Returns:
- ID[] of current group membership. Will not return null;
- See Also:
-
replicateToRemoteContainers
Replicate this shared object to a given set of remote containers. This method will invoke the method getReplicaDescriptions in order to determine the set of ReplicaSharedObjectDescriptions to send to remote containers.- Parameters:
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.
-
log
-
log
-
traceEntering
-
traceEntering
-
traceEntering
-
traceExiting
-
traceExiting
-
traceCatching
-
trace
- Since:
- 2.2