org.electrocodeogram.cpc.core.api.hub.event
Class CPCEvent

java.lang.Object
  extended by org.electrocodeogram.cpc.core.api.hub.event.CPCEvent
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<CPCEvent>
Direct Known Subclasses:
CloneEvent, EclipseEvent, TeamOperationEvent

public abstract class CPCEvent
extends java.lang.Object
implements java.lang.Comparable<CPCEvent>, java.lang.Cloneable

Abstract parent class for all types of CPC Events. This is the root of the event class hierarchy.

Comparability is defined based on the creation time of an event object.
Creation times are guaranteed to be unique.

Author:
vw

Constructor Summary
CPCEvent()
          Creates a new CPCEvent instance with a unique creation time.
 
Method Summary
protected  void checkSeal()
          Ensures that this event has not yet been sealed.
protected  java.lang.Object clone()
           
 int compareTo(CPCEvent o)
           
 long getCreationTime()
          Retrieves the creation time of this event in milliseconds.
 boolean isValid()
          Checks if this event has been fully initialised.
 void seal()
          Marks this event as sealed.
abstract  java.lang.String toString()
          Every event should implement a sensible toString method for use in debugging log messages.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CPCEvent

public CPCEvent()
Creates a new CPCEvent instance with a unique creation time.

Method Detail

seal

public void seal()
Marks this event as sealed.
Once sealed, no more modifications to the contents of the event are allowed.
This method may only be called once per event.

IMPORTANT: An event is always sealed by the IEventHubRegistry once the event is being dispatched. The creator of the event, must not call this method.

Trying to modify a sealed event will throw an IllegalStateException.

Subclasses may override this method but must ensure that they call it in their new seal() implementation.


checkSeal

protected void checkSeal()
Ensures that this event has not yet been sealed.

Throws:
java.lang.IllegalStateException - if the event was already sealed.

getCreationTime

public long getCreationTime()
Retrieves the creation time of this event in milliseconds.
The value corresponds to System.currentTimeMillis() at the time of the creation of the event object.

Creation times are guaranteed to be unique. Equality and comparability are based on event creation times.

Returns:
creation time of this event.

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

isValid

public boolean isValid()
Checks if this event has been fully initialised.
Will return false if one of the mandatory fields of the event has not yet been filled out.

Subclasses should override this method but should never return true. Instead they should delegate to the super class implementation once all validity checks on their level have passed.

The isValid() implementation always returns true.

Returns:
true if this event is valid, false otherwise.
See Also:
IEventHubRegistry.dispatch(CPCEvent)

compareTo

public int compareTo(CPCEvent o)
Specified by:
compareTo in interface java.lang.Comparable<CPCEvent>

toString

public abstract java.lang.String toString()
Every event should implement a sensible toString method for use in debugging log messages.

Overrides:
toString in class java.lang.Object
Returns:
debug string representation, never null.