org.apache.s4.base
Class Event

java.lang.Object
  extended by org.apache.s4.base.Event

public class Event
extends java.lang.Object

The base event class in S4. The base class supports generic key/value pairs which us useful for rapid prototyping and for inter-application communication. For greater efficiency and type safety, extend this class to create custom event types.


Constructor Summary
Event()
          Default constructor sets time using system time.
Event(long time)
          This constructor explicitly sets the time.
 
Method Summary
 boolean containsKey(java.lang.String key)
           
 java.lang.String get(java.lang.String key)
          Returns the value for key as a String.
<T> T
get(java.lang.String key, java.lang.Class<T> type)
          Get value for key.
 int getAppId()
          All events must be assigned the unique App ID of the App that owns the stream to which this event is injected.
 java.util.Map<java.lang.String,java.lang.String> getAttributesAsMap()
           
 java.lang.String getStreamName()
          The stream id is used to identify streams uniquely in a cluster configuration.
 long getTime()
           
 boolean hasAttributes()
           
<T> void
put(java.lang.String key, java.lang.Class<T> type, T value)
          Put an arbitrary key-value pair in the event.
 void setAppId(int appId)
          All events must be assigned the unique App ID of the App that owns the stream to which this event is injected.
 void setStreamId(java.lang.String streamName)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Event

public Event()
Default constructor sets time using system time.


Event

public Event(long time)
This constructor explicitly sets the time. Event that need to explicitly set the time must call {super(time)}

Method Detail

getTime

public long getTime()
Returns:
the create time

getStreamName

public java.lang.String getStreamName()
The stream id is used to identify streams uniquely in a cluster configuration. It is not required to operate in local mode.

Returns:
the target stream id

setStreamId

public void setStreamId(java.lang.String streamName)
Parameters:
streamName - used to identify streams uniquely in a cluster configuration. It is not required to operate in local mode.

getAppId

public int getAppId()
All events must be assigned the unique App ID of the App that owns the stream to which this event is injected. The assignment must be done automatically by the stream that receives the event. Each application has a unique ID. We use the app ID in combination with the stream ID to identify stream instances in a cluster.

Returns:
the unique application ID.

setAppId

public void setAppId(int appId)
All events must be assigned the unique App ID of the App that owns the stream to which this event is injected. The assignment must be done automatically by the stream that receives the event. Each application has a unique ID. We use the app ID in combination with the stream ID to identify stream instances in a cluster.

Parameters:
appId - a unique application identifier, typically assigned by the deployment system.

put

public <T> void put(java.lang.String key,
                    java.lang.Class<T> type,
                    T value)
Put an arbitrary key-value pair in the event. The type of the value is T.

Parameters:
type - the type of the value
key - the key
value - the value

get

public <T> T get(java.lang.String key,
                 java.lang.Class<T> type)
Get value for key. The caller must know the type of the value.

Parameters:
key -
Returns:
the value

get

public java.lang.String get(java.lang.String key)
Returns the value for key as a String.

Parameters:
key -
Returns:
the value as a string.

hasAttributes

public boolean hasAttributes()

containsKey

public boolean containsKey(java.lang.String key)

getAttributesAsMap

public java.util.Map<java.lang.String,java.lang.String> getAttributesAsMap()

toString

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