org.lwes.emitter
Class UnicastEventEmitter

java.lang.Object
  extended by org.lwes.emitter.UnicastEventEmitter
All Implemented Interfaces:
EventEmitter

public class UnicastEventEmitter
extends java.lang.Object
implements EventEmitter

UnicastEventEmitter emits events as unicast datagrams on the network.

Since:
0.0.1 Example code:
 UnicastEventEmitter emitter = new UnicastEventEmitter();
 emitter.setESFFilePath("/path/to/esf/file");
 emitter.setMulticastAddress(InetAddress.getByName("224.0.0.69"));
 emitter.setMulticastPort(9191);
 emitter.initialize();

 Event e = emitter.createEvent("MyEvent", false);
 e.setString("key","value");
 emitter.emit(e);
 
Author:
Michael P. Lum, Anthony Molinaro

Constructor Summary
UnicastEventEmitter()
          Default constructor.
 
Method Summary
 Event createEvent(java.lang.String eventName)
          Creates a new event named eventName.
 Event createEvent(java.lang.String eventName, boolean validate)
          Creates a new event named eventName.
protected  void emit(byte[] bytes)
          Emits a byte array to the network.
protected  void emit(byte[] bytes, java.net.InetAddress address, int port)
           
 void emit(Event event)
          Emits the event to the network.
 java.net.InetAddress getAddress()
          Gets the address for this emitter.
 java.lang.String getESFFilePath()
          Gets the ESF file used for event validation
 java.io.InputStream getESFInputStream()
          Gets the InputStream being used for event validation.
 int getPort()
          Gets the destination port for this emitter.
 void initialize()
          Initializes the emitter.
 void setAddress(java.net.InetAddress address)
          Sets the destination address for this emitter.
 void setESFFilePath(java.lang.String esfFilePath)
          Sets the ESF file used for event validation.
 void setESFInputStream(java.io.InputStream esfInputStream)
          Sets an InputStream to be used for event validation.
 void setPort(int port)
          Sets the destination port for this emitter.
 void shutdown()
          Called before the system is shut down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnicastEventEmitter

public UnicastEventEmitter()
Default constructor.

Method Detail

setAddress

public void setAddress(java.net.InetAddress address)
Sets the destination address for this emitter.

Parameters:
address - the multicast address

getAddress

public java.net.InetAddress getAddress()
Gets the address for this emitter.

Returns:
the address

setPort

public void setPort(int port)
Sets the destination port for this emitter.

Parameters:
port - the multicast port

getPort

public int getPort()
Gets the destination port for this emitter.

Returns:
the multicast port

setESFFilePath

public void setESFFilePath(java.lang.String esfFilePath)
Sets the ESF file used for event validation.

Specified by:
setESFFilePath in interface EventEmitter
Parameters:
esfFilePath - the path of the ESF file

getESFFilePath

public java.lang.String getESFFilePath()
Gets the ESF file used for event validation

Specified by:
getESFFilePath in interface EventEmitter
Returns:
the ESF file path

setESFInputStream

public void setESFInputStream(java.io.InputStream esfInputStream)
Sets an InputStream to be used for event validation.

Specified by:
setESFInputStream in interface EventEmitter
Parameters:
esfInputStream - an InputStream used for event validation

getESFInputStream

public java.io.InputStream getESFInputStream()
Gets the InputStream being used for event validation.

Specified by:
getESFInputStream in interface EventEmitter
Returns:
the InputStream of the ESF validator

initialize

public void initialize()
                throws java.io.IOException
Initializes the emitter.

Specified by:
initialize in interface EventEmitter
Throws:
java.io.IOException - if an I/O error occurs during initialization

shutdown

public void shutdown()
              throws java.io.IOException
Description copied from interface: EventEmitter
Called before the system is shut down. Allows for cleanup of data and destruction of network sockets, where applicable.

Specified by:
shutdown in interface EventEmitter
Throws:
java.io.IOException - if an I/O error occurs during initialization

createEvent

public Event createEvent(java.lang.String eventName)
                  throws EventSystemException
Creates a new event named eventName.

Specified by:
createEvent in interface EventEmitter
Parameters:
eventName - the name of the event to be created
Returns:
a new Event
Throws:
EventSystemException - if there is a problem creating the event

createEvent

public Event createEvent(java.lang.String eventName,
                         boolean validate)
                  throws EventSystemException
Creates a new event named eventName.

Specified by:
createEvent in interface EventEmitter
Parameters:
eventName - the name of the event to be created
validate - whether or not to validate the event against the EventTemplateDB
Returns:
a new Event
Throws:
EventSystemException - if there is a problem creating the event

emit

public void emit(Event event)
          throws java.io.IOException
Emits the event to the network.

Specified by:
emit in interface EventEmitter
Parameters:
event - the event to emit
Throws:
java.io.IOException - throws an IOException is there is a network error.

emit

protected void emit(byte[] bytes)
             throws java.io.IOException
Emits a byte array to the network.

Parameters:
bytes - the byte array to emit
Throws:
java.io.IOException - throws an IOException if there is a network error.

emit

protected void emit(byte[] bytes,
                    java.net.InetAddress address,
                    int port)
             throws java.io.IOException
Parameters:
bytes - the byte array to emit
address - the address to use
port - the port to use
Throws:
java.io.IOException - throws an IOException if there is a network error