org.lwes.listener
Class DatagramEventListener

java.lang.Object
  extended by org.lwes.listener.ThreadedEventListener
      extended by org.lwes.listener.DatagramEventListener
All Implemented Interfaces:
EventListener

public class DatagramEventListener
extends ThreadedEventListener

This is an event listener that handles UDP packets. Automatically detects multicast addresses and joins those groups. Sample code that prints multicast events to stdout:

 EventHandler myHandler = new EventPrintingHandler();
 InetAddress address = InetAddress.getByName("224.0.0.69");
 
 DatagramEventListener listener = new DatagramEventListener();
 listener.setAddress(address);
 listener.setPort(9191);
 listener.addHandler(myHandler);
 listener.initialize();
 

Author:
Michael P. Lum

Field Summary
 
Fields inherited from class org.lwes.listener.ThreadedEventListener
processor
 
Constructor Summary
DatagramEventListener()
          Default constructor.
 
Method Summary
 void addHandler(EventHandler handler)
          Adds an event handler to this listener.
 java.net.InetAddress getAddress()
          Gets the address to use for this listener
 java.net.InetAddress getInterface()
          Get the interface to use for this listener
 int getMaxThreads()
          Returns the max number of threads allowed by the system.
 int getPort()
          Gets the port to use for this listener
 int getTimeToLive()
          Get the TTL to use for this listener.
 void initialize()
          Initializes the listener.
 void removeHandler(EventHandler handler)
          Removes an event handler from the system.
 void setAddress(java.net.InetAddress address)
          Sets the address to use for this listener
 void setInterface(java.net.InetAddress iface)
          Sets the interface to use for this listener
 void setMaxThreads(int threads)
          Sets the max number of threads allowed by the system.
 void setPort(int port)
          Sets the port to use for this listener
 void setTimeToLive(int ttl)
          Sets the TTL to use for this listener.
 
Methods inherited from class org.lwes.listener.ThreadedEventListener
getDequeuer, getEnqueuer, setDequeuer, setEnqueuer, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatagramEventListener

public DatagramEventListener()
Default constructor.

Method Detail

getAddress

public java.net.InetAddress getAddress()
Gets the address to use for this listener

Returns:
the address

setAddress

public void setAddress(java.net.InetAddress address)
Sets the address to use for this listener

Parameters:
address - the address

getPort

public int getPort()
Gets the port to use for this listener

Returns:
the port

setPort

public void setPort(int port)
Sets the port to use for this listener

Parameters:
port - the port

getInterface

public java.net.InetAddress getInterface()
Get the interface to use for this listener

Returns:
the interface

setInterface

public void setInterface(java.net.InetAddress iface)
Sets the interface to use for this listener

Parameters:
iface - the interface

getTimeToLive

public int getTimeToLive()
Get the TTL to use for this listener. Only applies to multicast listeners. Typically this does not need to be changed.

Returns:
the interface

setTimeToLive

public void setTimeToLive(int ttl)
Sets the TTL to use for this listener. Only applies to multicast listeners. Typically this does not need to be changed.

Parameters:
ttl - the TTL value

getMaxThreads

public int getMaxThreads()
Returns the max number of threads allowed by the system.

Returns:
the allowed threads

setMaxThreads

public void setMaxThreads(int threads)
Sets the max number of threads allowed by the system.

Parameters:
threads - the max number of threads

addHandler

public void addHandler(EventHandler handler)
Adds an event handler to this listener. This has a callback that will be invoked for every event coming through the system.

Specified by:
addHandler in interface EventListener
Overrides:
addHandler in class ThreadedEventListener
Parameters:
handler - the EventHandler to add

removeHandler

public void removeHandler(EventHandler handler)
Removes an event handler from the system. This causes the event handler to no longer receive events coming through the system.

Parameters:
handler - the EventHandler to remove

initialize

public void initialize()
                throws EventSystemException
Initializes the listener.

Overrides:
initialize in class ThreadedEventListener
Throws:
EventSystemException - thrown if there is a problem initializing the listener