org.mule.routing
Class EventGroup

java.lang.Object
  extended by org.mule.routing.EventGroup
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<EventGroup>

public class EventGroup
extends java.lang.Object
implements java.lang.Comparable<EventGroup>, java.io.Serializable

EventGroup is a holder over events grouped by a common group Id. This can be used by components such as routers to managed related events.

See Also:
Serialized Form

Field Summary
static MuleEvent[] EMPTY_EVENTS_ARRAY
           
 
Constructor Summary
EventGroup(java.lang.Object groupId)
           
EventGroup(java.lang.Object groupId, int expectedSize)
           
 
Method Summary
 void addEvent(MuleEvent event)
          Add the given event to this group.
 void clear()
          Removes all events from this group.
 int compareTo(EventGroup other)
          Compare this EventGroup to another one.
 boolean equals(java.lang.Object obj)
          Compares two EventGroups for equality.
 int expectedSize()
          Returns the number of events that this EventGroup is expecting before correlation can proceed.
 long getCreated()
          Return the creation timestamp of the current group in nanoseconds.
 java.lang.Object getGroupId()
          Returns an identifier for this EventGroup.
 MuleEvent getMessageCollectionEvent()
           
 int hashCode()
          The hashCode of an EventGroup is derived from the object returned by getGroupId().
 java.util.Iterator<MuleEvent> iterator()
          Returns an iterator over a snapshot copy of this group's collected events.
 void removeEvent(MuleEvent event)
          Remove the given event from the group.
 int size()
          Returns the number of events collected so far.
 MuleEvent[] toArray()
          Returns a snapshot of collected events in this group.
 MuleMessageCollection toMessageCollection()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_EVENTS_ARRAY

public static final MuleEvent[] EMPTY_EVENTS_ARRAY
Constructor Detail

EventGroup

public EventGroup(java.lang.Object groupId)

EventGroup

public EventGroup(java.lang.Object groupId,
                  int expectedSize)
Method Detail

compareTo

public int compareTo(EventGroup other)
Compare this EventGroup to another one. If the receiver and the argument both have groupIds that are Comparable, they are used for the comparison; otherwise - since the id can be any object - the group creation time stamp is used as fallback. Older groups are considered "smaller".

Specified by:
compareTo in interface java.lang.Comparable<EventGroup>
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(java.lang.Object obj)
Compares two EventGroups for equality. EventGroups are considered equal when their groupIds (as returned by getGroupId()) are equal.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
The hashCode of an EventGroup is derived from the object returned by getGroupId().

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

getGroupId

public java.lang.Object getGroupId()
Returns an identifier for this EventGroup. It is recommended that this id is unique and Comparable e.g. a UUID.

Returns:
the id of this event group

iterator

public java.util.Iterator<MuleEvent> iterator()
Returns an iterator over a snapshot copy of this group's collected events. If you need to iterate over the group and e.g. remove select events, do so via removeEvent(MuleEvent). If you need to do so atomically in order to prevent e.g. concurrent reception/aggregation of the group during iteration, wrap the iteration in a synchronized block on the group instance.

Returns:
an iterator over collected MuleEvents.

toArray

public MuleEvent[] toArray()
Returns a snapshot of collected events in this group.

Returns:
an array of collected MuleEvents.

addEvent

public void addEvent(MuleEvent event)
Add the given event to this group.

Parameters:
event - the event to add

removeEvent

public void removeEvent(MuleEvent event)
Remove the given event from the group.

Parameters:
event - the evnt to remove

getCreated

public long getCreated()
Return the creation timestamp of the current group in nanoseconds.

Returns:
the timestamp when this group was instantiated.

size

public int size()
Returns the number of events collected so far.

Returns:
number of events in this group or 0 if the group is empty.

expectedSize

public int expectedSize()
Returns the number of events that this EventGroup is expecting before correlation can proceed.

Returns:
expected number of events or -1 if no expected size was specified.

clear

public void clear()
Removes all events from this group.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toMessageCollection

public MuleMessageCollection toMessageCollection()

getMessageCollectionEvent

public MuleEvent getMessageCollectionEvent()


Copyright © 2003-2010 MuleSoft, Inc.. All Rights Reserved.