|
jAER project on SourceForge | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jaer.event.EventPacket<E>
public class EventPacket<E extends BasicEvent>
A packet of events that is used for rendering and event processing. For efficiency, these packets are designed to be re-used; they should be allocated rarely and allowed to grow in size. If a packet capacity needs to be increased a substantial peformance hit will occur e.g. 1 ms per resizing or initial allocation.
The EventPacket is prefilled with Events that have default values. One constructor lets you fill the EventPacket with a subclass of BasicEvent. This prefilling avoids the overhead of object creation. It also allows easy access to all information contained in the event and it allows storing arbitrary event information, including extended type information, in EventPackets.
However, this reuse of existing objects means that you need to take particular precautions. The events that are stored in a packet are references to objects. Therefore you can assign an event to a different packet but this event will still be referenced in the original packet and can change.
Generally in event processing, you will iterate over an input packet to produce an output packet. You iterate over an exsiting EventPacket that has input data using the iterator(). This lets you access the events in the input packet.
When you want to write these events to an existing output packet, then you need to use the target event's copyFrom(Event e) method that copies all the fields in the source packet to the target packet. This lets you copy data such as timestamp, x,y location to a target event. You can then fill in the target event's extended type infomation.
When you iterate over an input packet to write to a target packet, you obtain the target event to write your results to by using the target packet's output enumeration by using the outputIterator() method. This enumeration has a method nextOutput() that returns the next output event to write to. This nextOutput() method also expands the packet if they current capacity needs to be enlarged. The iterator is initialized by the call to outputIterator().
The amount of time iterating over events can also be limited by using the time limiter. This static (class) method starts a timer when it is restarted and after timeout, no more events are returned from input iteration. These methods are used in FilterChain to limit processing time.
Field Summary | |
---|---|
int |
DEFAULT_INITIAL_CAPACITY
Default capacity in events for new EventPackets |
Constructor Summary | |
---|---|
EventPacket()
Constructs a new EventPacket filled with BasicEvent. |
|
EventPacket(java.lang.Class<? extends BasicEvent> eventClass)
Constructs a new EventPacket filled with the given event class. |
Method Summary | |
---|---|
void |
clear()
Sets the size to zero. |
java.lang.String |
getDescription()
|
int |
getDurationUs()
Returns duration of packet in microseconds. |
E |
getEvent(int k)
Returns the k'th event. |
java.lang.Class |
getEventClass()
Returns the class of event in this packet. |
E |
getEventPrototype()
Returns a prototype of the events in the packet. |
float |
getEventRateHz()
|
E |
getFirstEvent()
Returns first event, or null if there are no events. |
int |
getFirstTimestamp()
Returns first timestamp or 0 if there are no events. |
E |
getLastEvent()
Returns last event, or null if there are no events. |
int |
getLastTimestamp()
|
int |
getNumCellTypes()
Returns the number of 'types' of events. |
int |
getSize()
Returns the number of events in the packet. |
static int |
getTimeLimitMs()
Gets the class time limit for iteration in ms |
protected void |
initializeEvents()
Fills this with DEFAULT_INITIAL_CAPACITY of the event class |
java.util.Iterator<E> |
inputIterator()
Returns after initializng the iterator over input events. |
boolean |
isEmpty()
Reports if the packet is empty. |
static boolean |
isTimedOut()
Returns true if timeLimitTimer is timed out and timeLimitEnabled |
static boolean |
isTimeLimitEnabled()
Returns status of time limiting |
java.util.Iterator<E> |
iterator()
Initializes and returns the iterator |
OutputEventIterator<E> |
outputIterator()
Returns an iterator that iterates over the output events. |
static void |
restartTimeLimiter()
Resets the time limiter for input iteration. |
static void |
restartTimeLimiter(int timeLimitMs)
restart the time limiter with limit timeLimitMs |
void |
setEventClass(java.lang.Class<? extends BasicEvent> eventClass)
Sets the event class for this packet and fills the packet with these events. |
protected void |
setSize(int n)
|
static void |
setTimeLimitEnabled(boolean yes)
|
static void |
setTimeLimitMs(int timeLimitMs)
Sets the class time limit for filtering a packet through the filter chain in ms. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final int DEFAULT_INITIAL_CAPACITY
Constructor Detail |
---|
public EventPacket()
BasicEvent
public EventPacket(java.lang.Class<? extends BasicEvent> eventClass)
BasicEvent
Method Detail |
---|
public static void restartTimeLimiter()
public static void restartTimeLimiter(int timeLimitMs)
timeLimitMs
- time in msprotected void initializeEvents()
public int getDurationUs()
public java.lang.String getDescription()
public void clear()
protected void setSize(int n)
public float getEventRateHz()
public E getFirstEvent()
public E getLastEvent()
public int getFirstTimestamp()
public int getLastTimestamp()
public final E getEvent(int k)
java.lang.ArrayIndexOutOfBoundsException
- if out of bounds of packet.public final java.util.Iterator<E> inputIterator()
public final OutputEventIterator<E> outputIterator()
public final int getSize()
public boolean isEmpty()
public java.lang.String toString()
toString
in class java.lang.Object
public final int getNumCellTypes()
public final E getEventPrototype()
public final java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E extends BasicEvent>
public final java.lang.Class getEventClass()
public final void setEventClass(java.lang.Class<? extends BasicEvent> eventClass)
eventClass
- which much extend BasicEventpublic static final int getTimeLimitMs()
public static final void setTimeLimitMs(int timeLimitMs)
timeLimitMs
- the time limit in msrestartTimeLimiter()
public static final void setTimeLimitEnabled(boolean yes)
public static final boolean isTimeLimitEnabled()
public static final boolean isTimedOut()
|
jAER project on SourceForge | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |