fulmine.model.container
Class AbstractEventProcessingContainer

java.lang.Object
  extended by fulmine.AbstractLifeCycle
      extended by fulmine.model.component.AbstractComponent
          extended by fulmine.model.container.AbstractContainer
              extended by fulmine.model.container.AbstractEventProcessingContainer
All Implemented Interfaces:
IEvent, IEventFrame, IEventSource, IAddressable, IDescriptor, IDestroyable, ILifeCycle, IComponent, IContainer, IRemoteSubscribable, IWireState, Cloneable
Direct Known Subclasses:
AbstractDynamicContainer, BasicContainer

public abstract class AbstractEventProcessingContainer
extends AbstractContainer
implements Cloneable

An extended AbstractContainer that includes logic to handle event processing.

This implementation is thread safe. Events received by addEvent(IEvent) are cloned (if they are an AbstractCloneableComponent) and cached in a local collection until the event frame is flushed (see IEventFrame). The event sinking process is thread safe. If any of the events are fields of this container, they are marked for writing when the AbstractComponent.writeState(IOperationScope, IWireIdentity, byte[][], int[], byte[][], int[], boolean) method executes. This provides a delta change mechanism that overrides the AbstractContainer implementation that can only write the complete image.

Changes to the container are only notified to IEventListener objects when the events are processed via AbstractContainer.endFrame(). When the events are processed, the container also raises itself as an event. However, the container raises a clone of itself. The cloned container will be a deep clone so will represent the state of the container at the moment in time when the event occurs.

The AbstractContainer.endFrame() also raises a TxEvent containing the byte[] to with the changes send to remote context instances. This is a system event so only ISystemEventListener instances will receive these.

Events are raised via the FulmineContext.queueEvents(Collection) method.

Author:
Ramon Servadei

Nested Class Summary
 
Nested classes/interfaces inherited from class fulmine.model.container.AbstractContainer
AbstractContainer.ReaderTask
 
Nested classes/interfaces inherited from interface fulmine.model.container.IContainer
IContainer.DataState
 
Field Summary
protected  Collection<IEvent> events
          The events occurring in an event frame.
 
Constructor Summary
AbstractEventProcessingContainer(String nativeContextIdentity, String identity, IType type, IDomain domain, IFrameworkContext hostContext, boolean local)
          Standard constructor.
 
Method Summary
 void addEvent(IEvent event)
          A synchronous notification implementation
protected  void afterAdd(IField field)
          Called after the field is added and the copy-on-write operation has completed.
 Object clone()
          Clone this.
protected  void doCommitEvents()
          This is thread safe - only the event frame can execute this.
protected  void doComponentDestroy()
          The destroy method that is invoked on a non-cloned version of this.
protected  void doStateChangeOp(IContainer.DataState oldState)
          Perform the operation when the AbstractContainer.dataState changes.
 Collection<IField> getChangedFields()
          Get the fields that have changed in the previous event frame.
protected  Collection<IField> getFieldsToWrite(boolean completeState)
          Get the fields to write to a frame.
protected  AsyncLog getLog()
          Get the log to use for the object hierarchy
 
Methods inherited from class fulmine.model.container.AbstractContainer
add, afterRemove, beforeAdd, beforeRemove, beginFrame, contains, doPostAddListener, doPostRemoveListener, doReadState, doStart, doWriteState, endFrame, equals, flushFrame, get, getBooleanField, getComponentIdentities, getContext, getDataState, getDefinition, getDoubleField, getFields, getFloatField, getFrameIdentifier, getIntegerField, getLongField, getNativeContextIdentity, getRemoteSubscriptionCount, getStringField, hashCode, isDynamic, isEmpty, isEventFrameThread, isFrameActive, isLocal, isRemote, lockFrame, logNotTheEventFrameThread, markForRemoteSubscription, newReaderTask, remove, setState, size, toDetailedString, toString, unmarkForRemoteSubscription
 
Methods inherited from class fulmine.model.component.AbstractComponent
addListener, checkClone, createIdentityString, doDestroy, getAddress, getAddressable, getDomain, getDrivingFrame, getEventSourceGroupId, getFrame, getIdentity, getIdentityString, getListeners, getSource, getTriggerEvent, getType, isClone, readState, removeListener, removeListeners, setDrivingFrame, setFrame, setTriggerEvent, toIdentityString, writeState
 
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.model.container.IContainer
destroy, getType, isClone, start
 
Methods inherited from interface fulmine.protocol.wire.IWireState
readState, writeState
 
Methods inherited from interface fulmine.event.IEventSource
addListener, getEventSourceGroupId, getListeners, removeListener, removeListeners
 
Methods inherited from interface fulmine.IDescriptor
toIdentityString
 
Methods inherited from interface fulmine.ILifeCycle
isActive
 
Methods inherited from interface fulmine.IAddressable
getAddress, getDomain, getIdentity
 
Methods inherited from interface fulmine.event.IEvent
getDrivingFrame, getFrame, getSource, getTriggerEvent, setTriggerEvent
 
Methods inherited from interface fulmine.IDescriptor
toIdentityString
 
Methods inherited from interface fulmine.IAddressable
getAddress, getDomain, getIdentity
 

Field Detail

events

protected volatile Collection<IEvent> events
The events occurring in an event frame. The events are ordered and coalesced. Uses the 'cheap read-write lock'

Constructor Detail

AbstractEventProcessingContainer

public AbstractEventProcessingContainer(String nativeContextIdentity,
                                        String identity,
                                        IType type,
                                        IDomain domain,
                                        IFrameworkContext hostContext,
                                        boolean local)
Standard constructor.

Parameters:
nativeContextIdentity - whether the container is local to this context
identity - the identity of the container
type - the type of the container
domain - the domain for the container
hostContext - the context hosting this container instance
local - true the container is local to this context
Method Detail

doCommitEvents

protected final void doCommitEvents()
This is thread safe - only the event frame can execute this.

Overrides:
doCommitEvents in class AbstractContainer
See Also:
IEventFrame.endFrame()

addEvent

public final void addEvent(IEvent event)
Description copied from class: AbstractComponent
A synchronous notification implementation

Specified by:
addEvent in interface IEventFrame
Specified by:
addEvent in interface IEventSource
Overrides:
addEvent in class AbstractComponent
Parameters:
event - the event to pass on to the registered listeners

getLog

protected AsyncLog getLog()
Description copied from class: AbstractLifeCycle
Get the log to use for the object hierarchy

Overrides:
getLog in class AbstractContainer
Returns:
the log to use for the object hierarchy

doComponentDestroy

protected void doComponentDestroy()
Description copied from class: AbstractComponent
The destroy method that is invoked on a non-cloned version of this.

Overrides:
doComponentDestroy in class AbstractContainer

afterAdd

protected void afterAdd(IField field)
Description copied from class: AbstractContainer
Called after the field is added and the copy-on-write operation has completed. This is called whilst holding the monitor lock for adding/removing fields.

Overrides:
afterAdd in class AbstractContainer
Parameters:
field - the field to add

getChangedFields

public final Collection<IField> getChangedFields()
Get the fields that have changed in the previous event frame. This method should only be accessed from the IEventListener.update(IEvent) method when a listener receives notification that the IContainer has changed. The notification is a clone of the original and this method is only usable for cloned instances (hence only within the update method).

Returns:
the fields that have changed in the previous event frame.

getFieldsToWrite

protected Collection<IField> getFieldsToWrite(boolean completeState)
Description copied from class: AbstractContainer
Get the fields to write to a frame. This occurs whilst the event frame is locked. This method allows sub-classes to inspect and mutate the #changedFields field prior to being written to a frame.

Overrides:
getFieldsToWrite in class AbstractContainer
Returns:
the fields to write into a frame

doStateChangeOp

protected void doStateChangeOp(IContainer.DataState oldState)
Description copied from class: AbstractContainer
Perform the operation when the AbstractContainer.dataState changes.

Overrides:
doStateChangeOp in class AbstractContainer
Parameters:
oldState - the old state

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from interface: IEvent
Clone this.

Specified by:
clone in interface IEvent
Overrides:
clone in class AbstractContainer
Returns:
a clone of this
Throws:
CloneNotSupportedException
See Also:
Object#clone)_


Copyright © 2007-2009. All Rights Reserved.