org.apache.s4.core
Class Stream<T extends Event>

java.lang.Object
  extended by org.apache.s4.core.Stream<T>
All Implemented Interfaces:
java.lang.Runnable, Streamable

public class Stream<T extends Event>
extends java.lang.Object
implements java.lang.Runnable, Streamable

Stream and ProcessingElement objects represent the links and nodes in the application graph. A stream sends an Event object to ProcessingElement instances located anywhere in a cluster.

Once a stream is instantiated, it is immutable.

To build an application, create stream objects using relevant methods in the App class.


Field Summary
protected  Key<T> key
           
protected  java.util.concurrent.BlockingQueue<EventMessage> queue
           
 
Constructor Summary
Stream(App app)
          Send events using a KeyFinder.
 
Method Summary
 void close()
          Stop and close this stream.
 App getApp()
           
 Key<T> getKey()
           
 java.lang.String getName()
           
 Receiver getReceiver()
           
 Sender getSender()
           
 ProcessingElement[] getTargetPEs()
           
 void put(Event event)
          Sends an event.
 void receiveEvent(EventMessage event)
          The low level Receiver object call this method when a new Event is available.
 Stream<T> register()
           
 void run()
           
 Stream<T> setKey(KeyFinder<T> keyFinder)
          Define the key finder for this stream.
 Stream<T> setKey(java.lang.String keyName)
          Define the key finder for this stream using a descriptor.
 Stream<T> setName(java.lang.String name)
          Name the stream.
 Stream<T> setPE(ProcessingElement pe)
          Send events from this stream to a PE.
 Stream<T> setPEs(ProcessingElement[] pes)
          Send events from this stream to various PEs.
 void start()
          Starting the stream starts the associated dequeuing thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

key

protected Key<T extends Event> key

queue

protected final java.util.concurrent.BlockingQueue<EventMessage> queue
Constructor Detail

Stream

public Stream(App app)
Send events using a KeyFinder. The key finder extracts the value of the key which is used to determine the target ClusterNode for an event.

Parameters:
app - we always register streams with the parent application.
Method Detail

start

public void start()
Description copied from interface: Streamable
Starting the stream starts the associated dequeuing thread.

Specified by:
start in interface Streamable

setName

public Stream<T> setName(java.lang.String name)
Name the stream.

Parameters:
name - the stream name, default is an empty string.
Returns:
the stream object

setKey

public Stream<T> setKey(KeyFinder<T> keyFinder)
Define the key finder for this stream.

Parameters:
keyFinder - a function to lookup the value of the key.
Returns:
the stream object

setKey

public Stream<T> setKey(java.lang.String keyName)
Define the key finder for this stream using a descriptor.

Parameters:
keyName - a descriptor to lookup up the value of the key.
Returns:
the stream object

setPE

public Stream<T> setPE(ProcessingElement pe)
Send events from this stream to a PE.

Parameters:
pe - a target PE.
Returns:
the stream object

setPEs

public Stream<T> setPEs(ProcessingElement[] pes)
Send events from this stream to various PEs.

Parameters:
pes - a target PE array.
Returns:
the stream object

put

public void put(Event event)
Sends an event.

Specified by:
put in interface Streamable
Parameters:
event -

receiveEvent

public void receiveEvent(EventMessage event)
The low level Receiver object call this method when a new Event is available.


getName

public java.lang.String getName()
Specified by:
getName in interface Streamable
Returns:
the name

getKey

public Key<T> getKey()
Returns:
the key

getApp

public App getApp()
Returns:
the app

getTargetPEs

public ProcessingElement[] getTargetPEs()
Returns:
the list of target processing element prototypes.

close

public void close()
Stop and close this stream.

Specified by:
close in interface Streamable

getSender

public Sender getSender()
Returns:
the sender object

getReceiver

public Receiver getReceiver()
Returns:
the receiver object

run

public void run()
Specified by:
run in interface java.lang.Runnable

register

public Stream<T> register()