|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.apama.event.Event
public class Event
An Event object representing an event instance in flat event string format and/or
structured format (as defined by its associated EventType
).
To get a parsed Event object from an event string, call EventParser.parse(String)
(or EventType.parse(String)
); to build up an Event from a set of field
values, start by using the Event(EventType)
constructor.
The event field values can be updated or retrieved by
calling the setField(Field, Object)
and getField(Field)
methods respectively.
See the com.apama.event.parser package documentation for an example of how event strings may be generated and parsed using this class.
In order to make the Event "known" to the Correlator, the event definition must be injected to the correlator before any events of that type are sent into it.
EventParser
,
EventType
,
FieldTypes
,
Field
Constructor Summary | |
---|---|
Event(EventType eventType)
Constructor to create an Event based on an EventType. |
|
Event(java.lang.String eventString)
Constructor to create an Event based on a raw event string (for advanced uses only). |
Method Summary | ||
---|---|---|
java.lang.String |
getChannel()
Method to retrieve the channel name for an event. |
|
EventType |
getEventType()
Get the EventType for this Event. |
|
|
getField(Field<T> fieldDefinition)
Get the value of a field in this event instance. |
|
java.lang.Object |
getField(java.lang.String name)
Get the value of a field in this event instance. |
|
|
getField(java.lang.String fieldName,
FieldType<T> fieldType)
Get the value of a field in this event instance. |
|
java.util.Map<java.lang.String,java.lang.Object> |
getFieldsMap()
Method to retrieve the fieldName/value map of the event fields. |
|
java.lang.String |
getName()
Retrieve the name of the event type. |
|
java.lang.String |
getText()
Retrieve the Apama string representation of the event. |
|
double |
getTime()
Method to retrieve the timestamp for the event. |
|
void |
setChannel(java.lang.String newChannel)
Method to set the channel name for an event. |
|
void |
setEventParser(EventParser eventParser)
Method to set a user-provided EventParser. |
|
|
setField(Field<T> fieldDefinition,
T value)
Set the value of a field in this event instance. |
|
|
setField(java.lang.String fieldName,
FieldType<T> fieldType,
T value)
Set the value of a field in this event instance. |
|
void |
setField(java.lang.String name,
java.lang.Object value)
Set the value of a field in this event instance. |
|
void |
setTime(double t)
Method to set the timestamp for the event. |
|
java.lang.String |
toString()
Retrieve the event's type and its contents as a String. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Event(java.lang.String eventString)
Note that this constructor is provided only for rare/advanced use cases
such as needing an Event object to send to the Correlator based on an existing
event string that was already generated by some other means.
For more common use cases, the best way to get an Event from an event string is to call
EventParser.parse(String)
(or EventType.parse(String)
),
and the best way to build up an Event of a known type from a set of field
values is the Event(EventType)
constructor.
No parsing will be performed until user makes the first request to the event field, for example by calling the setField() or getField() method. Once the parsing has taken place, the parsed fields will be stored in the Event object.
The user is responsible for registering the corresponding EventType
for this particular event with the EventParser before it will be able to parse events of
that type (by calling setEventParser(EventParser)
; otherwise, the singleton
EventParser.getDefaultParser()
is used).
Otherwise, a ParserRuntimeException will be thrown.
eventString
- the event text (raw event). Can be null or "", in
which case null or "" will be returned if user asked for the text
with the getText() methodEventParser.parse(String)
,
Event(EventType)
public Event(EventType eventType)
eventType
- to use to create the EventMethod Detail |
---|
public java.lang.String getText()
public EventType getEventType()
public java.lang.String getName()
public java.lang.String toString()
toString
in class java.lang.Object
public void setEventParser(EventParser eventParser)
EventParser.getDefaultParser()
) will be used for parsing
the event.
eventParser
- the eventParser for parsing the event.public void setField(java.lang.String name, java.lang.Object value) throws ParserRuntimeException
setField(Field, Object)
or setField(String, FieldType, Object)
instead of
this method.
The type of the value that must be provided depends on which Apama
FieldType is associated with this field in the EventType definition.
For example, if the field's type is a new SequenceFieldType(FloatFieldType.TYPE)
then the value must be an object that implements the java.util.List
interface,
and contains Double
objects for each float in the sequence. More information about the
classes used to represent field values is available in the documentation for each
com.apama.event.parser.*FieldType
class.
name
- the name of the fieldvalue
- the value of the field. The specified value must be assignable to
the Java type associated with the Apama FieldType for this field in the event definition.
Setting the value to null is discouraged, but currently allowed.
ParserRuntimeException
- if there was a problem during initial parsing of a textual event, or
if the specified field name is not a valid field in this event type.FieldType
public <T> Event setField(Field<T> fieldDefinition, T value) throws ParserRuntimeException
fieldDefinition
- A field object representing the field's name and type.value
- The value of the field. Must not be null.
ParserRuntimeException
- If there was a problem during initial parsing of a textual event,
if the specified field name is not a valid field in this event type, or if the provided value is null.FieldType
public <T> Event setField(java.lang.String fieldName, FieldType<T> fieldType, T value) throws ParserRuntimeException
fieldName
- The name of the field.fieldType
- The type of the field.value
- The value of the field. Must not be null.
ParserRuntimeException
- If there was a problem during initial parsing of a textual event,
if the specified field name is not a valid field in this event type, or if the provided value is null.FieldType
public java.lang.Object getField(java.lang.String name) throws ParserRuntimeException
getField(Field)
or getField(String, FieldType)
instead of
this method.
The type of the value that is returned depends on which Apama
FieldType is associated with the field in the EventType definition.
For example, if the field's type is a new SequenceFieldType(FloatFieldType.TYPE)
then the returned value will be an object that implements the java.util.List
interface,
and contains Double
objects for each float in the sequence. More information about the
classes used to represent field values is available in the documentation for each
com.apama.event.parser.*FieldType
class.
name
- the name of the field to retrieve
ParserRuntimeException
- if there was a problem during parsing of a event stringgetField(Field)
,
FieldType
public <T> T getField(Field<T> fieldDefinition) throws ParserRuntimeException
fieldDefinition
- The field of interest. This is typically (but not necessarily) the Field object that was
used to construct the EventType registered with the parser.
ParserRuntimeException
- if there was a problem during parsing of a event string or if the specified
field does not exist in this event or has a null (invalid) value because it has not yet been set.
An exception should never be thrown if the field exists and the event was parsed from an event string.getField(Field)
,
FieldType
public <T> T getField(java.lang.String fieldName, FieldType<T> fieldType) throws ParserRuntimeException
fieldName
- The name of the field whose value should be retrieved.fieldType
- The type of the field.
ParserRuntimeException
- if there was a problem during parsing of a event string or if the specified
field does not exist in this event or has a null (invalid) value.
An exception should never be thrown if the field exists and the event was parsed from an event string.getField(Field)
,
FieldType
public java.util.Map<java.lang.String,java.lang.Object> getFieldsMap() throws ParserRuntimeException
ParserRuntimeException
- if there was a problem during initial
parsing of a textual eventgetField(String)
public double getTime()
This timestamp currently only has meaning for events which have been source from the correlator, in which case it is set to the correlator time at which it was created, or the value it was set to explicitly by code running within the correlator.
To use the returned value with Java time and date routines, you will need to convert to milliseconds as a long.long millis = (long)(event.getTime() * 1000.0)
public void setTime(double t)
t
- the new timestamp of the eventpublic java.lang.String getChannel()
This currently only has meaning for events which have been sourced from the correlator, in which case it is set to the name of the channel the event was emitted from, or "" (the empty string) for the wildcard channel.
public void setChannel(java.lang.String newChannel)
newChannel
- The new channel name.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |