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
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd an event processor to the set of event processors available.voidClear event processors.protected voidCalled by replication strategy code (e.g.protected voiddestroyRemote(ID remoteID) protected voidDestroy this shared object in the context of the current container.protected voidDestroy the local copy of this shared object in the current container.voidMethod called by the ISharedObjectContainer upon ISharedObject destruction.protected voidfireEventProcessors(Event event) Fire the current set of event processors with given event.getAdapter(Class adapter) protected final ISharedObjectConfigGet the config for this shared object.protected IDprotected final ISharedObjectContextGet the shared object context for this object.protected ID[]Get IDs of remote containers currently in this group.protected IDgetID()Return the ID for this 'identifiable' object.protected IDprotected ReplicaSharedObjectDescriptiongetReplicaDescription(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 SharedObjectMsgGet SharedObjectMsg from ISharedObjectMessageEvent.voidhandleEvent(Event event) Handle Event passed to this IEventHandler.voidhandleEvents(Event[] events) Handle Events passed to this IEventHandler.protected booleanhandleSharedObjectCreateResponseEvent(ISharedObjectCreateResponseEvent createResponseEvent) Handle a ISharedObjectCreateResponseEvent.protected booleanhandleSharedObjectMsg(ID fromID, SharedObjectMsg msg) protected booleanSharedObjectMsg handler method.protected booleanHandle a ISharedObjectMessageEvent.protected voidhandleUnhandledEvent(Event event) Method called when an event is not handled by any event processor.final voidinit(ISharedObjectConfig initData) Initialize this ISharedObject.protected voidInitialize this shared object.protected final booleanprotected final booleanprotected voidprotected voidbooleanRemove an event processor from the set of event processors available to this object.protected voidreplicateToRemoteContainers(ID[] remoteContainers) Replicate this shared object to a given set of remote containers.protected voidsendSharedObjectMsgTo(ID toID, SharedObjectMsg msg) Send SharedObjectMessage to container with given ID.protected voidSend SharedObjectMsg to this shared object's primary instance.protected voidSend SharedObjectMsg to local shared object.protected voidprotected voidtraceCatching(String method, Throwable t) protected voidtraceEntering(String methodName) protected voidtraceEntering(String methodName, Object param) protected voidtraceEntering(String methodName, Object[] params) protected voidtraceExiting(String methodName) protected voidtraceExiting(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:ISharedObjectMethod 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:
disposein interfaceISharedObject- Parameters:
containerID- the ID of the container that is disposing this ISharedObject
-
getAdapter
- Specified by:
getAdapterin interfaceorg.eclipse.core.runtime.IAdaptable
-
handleEvent
Description copied from interface:ISharedObjectHandle Event passed to this IEventHandler.- Specified by:
handleEventin 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:
trueif actually added,falseotherwise.
-
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:
trueif actually removed,falseotherwise.
-
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:ISharedObjectHandle Events passed to this IEventHandler.- Specified by:
handleEventsin interfaceISharedObject- Parameters:
events- the Events [] for the implementer to handle
-
getID
Description copied from interface:IIdentifiableReturn the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May returnnull.- Specified by:
getIDin 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 benullas 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
nullas 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
nullif 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-
nullif the surrounding container is not currently connected.
-
isConnected
protected final boolean isConnected()- Returns:
trueif the surrounding container is currently connected,falseotherwise.
-
isPrimary
protected final boolean isPrimary()- Returns:
trueif 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