|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fulmine.AbstractLifeCycle fulmine.model.component.AbstractComponent
public abstract class AbstractComponent
A base component class that implements many common functions. Each component
has an identity that is provided during construction. A component is not
explicitly related with a context
.
The abstract component implements the IAddressable
interface. This is
an implementation detail and provides the context with the unique identity of
this component as an entity.
The addListener(IEventListener)
and
removeListener(IEventListener)
methods use copy-on-write for the
collection of listeners.
Constructor Summary | |
---|---|
protected |
AbstractComponent(String identity,
IType type,
IDomain domain)
Construct the component with an identity and type. |
protected |
AbstractComponent(String identity,
IType type,
IDomain domain,
byte eventGroupId)
Construct the component with an identity, type and event group id. |
Method Summary | |
---|---|
void |
addEvent(IEvent event)
A synchronous notification implementation |
boolean |
addListener(IEventListener listener)
Add the listener to the end of the list of listeners registered against this. |
protected void |
checkClone()
Check if this instance is a clone. |
Object |
clone()
Clone this. |
protected String |
createIdentityString()
Utility method to create the system identity string for a component. |
protected void |
doComponentDestroy()
The destroy method that is invoked on a non-cloned version of this. |
protected void |
doDestroy()
Overridden in subclasses to perform custom logic on destruction. |
protected void |
doPostAddListener(IEventListener listener)
Hook to allow sub-classes to perform any post processing after an IEventListener has been added via
addListener(IEventListener) |
protected void |
doPostRemoveListener(IEventListener listener)
Hook to allow sub-classes to perform any post processing after an IEventListener has been removed via
removeListener(IEventListener) |
protected abstract boolean |
doReadState(IOperationScope scope,
byte[] buffer,
int start,
int numberOfBytes)
Update the component state from the wire format state in the buffer. |
protected void |
doStart()
Overridden in subclasses to perform custom logic on activation. |
protected abstract boolean |
doWriteState(IOperationScope scope,
IWireIdentity wireId,
byte[][] headerBuffer,
int[] headerBufferPosition,
byte[][] dataBuffer,
int[] dataBufferPosition,
boolean completeState)
Write the component state in its wire form to the buffer. |
boolean |
equals(Object obj)
|
String |
getAddress()
Get the unique address for this. |
IAddressable |
getAddressable()
|
IDomain |
getDomain()
Get the domain attribute of this object. |
IEventFrameExecution |
getDrivingFrame()
Get the event frame execution that directly caused this event to occur. |
byte |
getEventSourceGroupId()
A byte identifying the event source group id. |
IEventFrameExecution |
getFrame()
Get the event frame of this event. |
String |
getIdentity()
Get the identification string for this entity. |
protected StringBuilder |
getIdentityString()
Helper method to return the component's identity and whether it is a clone or not |
List<IEventListener> |
getListeners()
Get the list of IEventListener instances observing this. |
protected AsyncLog |
getLog()
Get the log to use for the object hierarchy |
IEventSource |
getSource()
Get the event source that generated this event |
IEvent |
getTriggerEvent()
Get the 'trigger event'. |
IType |
getType()
Get the type attribute of this object. |
int |
hashCode()
|
boolean |
isClone()
Determine if this instance is the original or a clone |
void |
readState(IOperationScope scope,
byte[] dataBuffer,
int start,
int numberOfBytes)
Update this object's internal state from the fulmine delta (FD) wire format state encapsulated in the byte buffer. |
boolean |
removeListener(IEventListener listener)
Remove the listener from the list of listeners registered against this. |
List<IEventListener> |
removeListeners()
Remove all listeners registered for receiving IEvent events
originating from this. |
protected void |
setDrivingFrame(IEventFrameExecution drivingFrame)
Set the driving frame that caused the change in this component |
void |
setFrame(IEventFrameExecution frame)
Set the event frame identifier for this cloneable component. |
void |
setTriggerEvent(IEvent triggerEvent)
Set the 'trigger event'. |
String |
toDetailedString()
Provides a formatted string describing this object in detail. |
String |
toIdentityString()
Get a string that provides the identification for this object. |
String |
toString()
|
void |
writeState(IOperationScope scope,
IWireIdentity wireId,
byte[][] headerBuffer,
int[] headerBufferPosition,
byte[][] dataBuffer,
int[] dataBufferPosition,
boolean completeState)
Write the state of this object in fulmine delta (FD) wire format to the byte buffers. |
Methods inherited from class fulmine.AbstractLifeCycle |
---|
checkActive, destroy, finalize, isActive, start |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface fulmine.ILifeCycle |
---|
isActive, start |
Methods inherited from interface fulmine.IDestroyable |
---|
destroy |
Constructor Detail |
---|
protected AbstractComponent(String identity, IType type, IDomain domain)
identity
- the identity of the componenttype
- the type of the componentdomain
- the domain of the componentprotected AbstractComponent(String identity, IType type, IDomain domain, byte eventGroupId)
identity
- the identity of the componenttype
- the type of the componentdomain
- the domain of the componenteventGroupId
- the event group idMethod Detail |
---|
public final byte getEventSourceGroupId()
IEventSource
EventProcessor
that will distribute the events from this source.
getEventSourceGroupId
in interface IEventSource
EventProcessor
servicing this.public final String getIdentity()
IAddressable
getIdentity
in interface IAddressable
String
identity providing an identification for this
entity within its type and domain.IAddressable.getType()
,
IAddressable.getDomain()
public final IType getType()
IAddressable
getType
in interface IAddressable
IAddressable.getDomain()
public final IDomain getDomain()
IAddressable
getDomain
in interface IAddressable
IAddressable.getType()
public final String getAddress()
IAddressable
getAddress
in interface IAddressable
public final IEventSource getSource()
IEvent
getSource
in interface IEvent
public final IEventFrameExecution getDrivingFrame()
IEvent
An event occurs in its own event frame but it may have been caused by an event from another frame. This other frame is known as the 'driving' frame and directly causes this event. In this paradigm, where one event can cause another event to occur but in a separate event frame execution, it is sometimes necessary to know the frame of the first event so that the 2 events can be linked together.
getDrivingFrame
in interface IEvent
IEventFrameExecution
that is the event frame execution
of the event that caused this event to occur.public final IEventFrameExecution getFrame()
IEvent
getFrame
in interface IEvent
IEventFrameExecution
that identifies the frame this
event occurred in.public final void setFrame(IEventFrameExecution frame)
IEventListener
to process these events as a single work unit even
though they are generated in separate frames.
frame
- the event frame to associate this IEvent
with.protected final void setDrivingFrame(IEventFrameExecution drivingFrame)
drivingFrame
- the driving framepublic final void readState(IOperationScope scope, byte[] dataBuffer, int start, int numberOfBytes)
IWireState
The wire format state includes the fields of the object that have changed. The logic to read the component state should be delegated to the individual component.
readState
in interface IWireState
scope
- the scope of the read state operationdataBuffer
- the byte buffer that holds the contiguous wire format state to
read, at some positionstart
- where the wire format state begins in the byte buffernumberOfBytes
- the number of bytes in the byte buffer to read the wire format
statepublic final void writeState(IOperationScope scope, IWireIdentity wireId, byte[][] headerBuffer, int[] headerBufferPosition, byte[][] dataBuffer, int[] dataBufferPosition, boolean completeState)
IWireState
The object fields are written into headerBuffer[0] starting at headerBufferPosition[0]. The fields are written in 'component spec' format. The diagram below illustrates the IWF component spec for a single component:
------------------------------------------------------- | 1 byte | component bytes | data bytes | ------------------------------------------------------- | 7 6 5 4 3 2 1 0 | | | ------------------------------------------------------- | fbc | dbc | component | data position | -------------------------------------------------------
------------------------------------------------------- | 1 byte | 1 byte | component bytes | data bytes | ------------------------------------------------------- | fbc | dbc | component | data position | -------------------------------------------------------The data is written into dataBuffer[0] starting at dataBufferPosition[0].
writeState
in interface IWireState
scope
- the scope of the write state operationwireId
- the wire identity, expresses if this is an IWF or SWF
component specheaderBuffer
- headerBuffer[0] holds the header buffer to write the component
spec that describes the object's fields and their
corresponding data positions in the dataBufferheaderBufferPosition
- headerBufferPosition[0] holds the current position in the
headerBuffer[0]dataBuffer
- dataBuffer[0] holds the data buffer that component data is
written todataBufferPosition
- dataBufferPosition[0] holds the current position in the
dataBuffer[0]completeState
- whether to write the complete state or only changespublic void addEvent(IEvent event)
addEvent
in interface IEventSource
event
- the event to pass on to the registered listenerspublic final boolean addListener(IEventListener listener)
IEventSource
IPriorityEventListener
, it is added
to the beginning of the list.
Listeners are reference counted. Adding the same listener multiple times simply increments a reference count of the listener instance; if a listener is added twice, it must be removed twice for the listener instance reference to be removed from the internal list.
addListener
in interface IEventSource
listener
- the listener to add
true
if the listener instance was added (there were
no reference counts for it), false
if it already
existed (the reference count was incremented)public final List<IEventListener> getListeners()
IEventSource
IEventListener
instances observing this. The list
is the order of registration and the notification order for any
IEvent
raised by this event source.
The list is not modifiable.
getListeners
in interface IEventSource
null
if
there are no listenerspublic final boolean removeListener(IEventListener listener)
IEventSource
null
.
Listeners are reference counted. When removing a listener, this method decrements the reference count until there are no more references, at which point the listener instance reference is actually removed.
removeListener
in interface IEventSource
listener
- the listener to remove
true
if the listener was found and the reference
count was 0 and it was removed, false
otherwisepublic final List<IEventListener> removeListeners()
IEventSource
IEvent
events
originating from this.
removeListeners
in interface IEventSource
protected void doPostAddListener(IEventListener listener)
IEventListener
has been added via
addListener(IEventListener)
listener
- the listener that has been addedprotected void doPostRemoveListener(IEventListener listener)
IEventListener
has been removed via
removeListener(IEventListener)
listener
- the listener that has been removedprotected void doStart()
AbstractLifeCycle
RuntimeException
or subclass
thereof. When this method is called, the AbstractLifeCycle.isActive()
method will
return true
.
doStart
in class AbstractLifeCycle
protected final void doDestroy()
AbstractLifeCycle
RuntimeException
or subclass
thereof.
doDestroy
in class AbstractLifeCycle
protected void doComponentDestroy()
protected final void checkClone()
IllegalStateException
- if this is a cloned instance.public final boolean isClone()
true
if this is a clone of the originalprotected final String createIdentityString()
protected StringBuilder getIdentityString()
protected abstract boolean doWriteState(IOperationScope scope, IWireIdentity wireId, byte[][] headerBuffer, int[] headerBufferPosition, byte[][] dataBuffer, int[] dataBufferPosition, boolean completeState) throws Exception
writeState(IOperationScope, IWireIdentity, byte[][], int[], byte[][], int[], boolean)
method.
Exception
IWireState.writeState(IOperationScope, IWireIdentity, byte[][],
int[], byte[][], int[], boolean)
,
for a discussion of the byte[][] usage
protected abstract boolean doReadState(IOperationScope scope, byte[] buffer, int start, int numberOfBytes) throws Exception
readState(IOperationScope, byte[], int, int)
method.
Exception
IWireState.readState(IOperationScope, byte[], int, int)
public String toDetailedString()
IDescriptor
Object.toString()
method.
toDetailedString
in interface IDescriptor
public String toIdentityString()
IDescriptor
Object.toString()
method.
toIdentityString
in interface IDescriptor
public IEvent getTriggerEvent()
IEvent
IEventManager
queue after this event has been processed.
getTriggerEvent
in interface IEvent
null
if there is not a trigger event.public void setTriggerEvent(IEvent triggerEvent)
IEvent
IEventManager
queue after this event has been processed.
setTriggerEvent
in interface IEvent
triggerEvent
- the trigger event that will be queued after this event
has been processed.protected AsyncLog getLog()
AbstractLifeCycle
getLog
in class AbstractLifeCycle
public final IAddressable getAddressable()
public String toString()
toString
in class AbstractLifeCycle
public Object clone() throws CloneNotSupportedException
IEvent
clone
in interface IEvent
clone
in class Object
CloneNotSupportedException
Object#clone)_
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |