org.opennms.netmgt.eventd.adaptors.tcp
Class TcpEventReceiver

java.lang.Object
  extended by org.opennms.netmgt.eventd.adaptors.tcp.TcpEventReceiver
All Implemented Interfaces:
Fiber, InitializableFiber, EventReceiver, TcpEventReceiverMBean

public final class TcpEventReceiver
extends Object
implements EventReceiver, TcpEventReceiverMBean

This class is the access point for the agents to hook into the event queue. This fiber sets up an server socket that accepts incomming connections on the configured port (port 5817 by default). When a connection is established a new thread is started to process the socket connection. The event document is decoded and each of the events are passed to the handlers. Based upon the action of the handlers an event recipt is generated and sent to the remote client.

Author:
Brian Weaver , OpenNMS

Field Summary
static int UNLIMITED_EVENTS
          The value that defines unlimited events per connection.
 
Fields inherited from interface org.opennms.core.fiber.Fiber
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
 
Constructor Summary
TcpEventReceiver()
          Constructs a new TCP/IP event receiver on the default TCP/IP port.
TcpEventReceiver(int port, String ipAddress)
          Constructs a new TCP/IP event receiver on the passed port.
 
Method Summary
 void addEventHandler(EventHandler handler)
          Adds a new event handler to receiver.
 void addEventHandler(String name)
          Adds a new event handler by its managed name.
 void destroy()
          Called when the fiber is destroyed
 List<EventHandler> getEventHandlers()
           
 String getIpAddress()
           
 String getName()
          Returns the name of this Fiber.
 Integer getPort()
          Returns the where a listener is waiting to process new request.
 int getStatus()
          Returns the status of this Fiber.
 void init()
          Called when the fiber is initialized
 void removeEventHandler(EventHandler handler)
          Removes an event handler from the list of handler called when an event is received.
 void removeEventHandler(String name)
          Removes an event handler.
 void setEventHandlers(List<EventHandler> eventHandlers)
           
 void setEventsPerConnection(Integer number)
          The number of event records a new connection is allowed to send before the connection is terminated by the server.
 void setIpAddress(String ipAddress)
           
 void setLogPrefix(String prefix)
          The logging prefix to use
 void setPort(Integer port)
          Sets the port where new requests will be handled.
 void start()
          Allocates the server socket and starts up the server socket processor thread.
 void stop()
          Stops the TCP/IP event receiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNLIMITED_EVENTS

public static final int UNLIMITED_EVENTS
The value that defines unlimited events per connection.

See Also:
Constant Field Values
Constructor Detail

TcpEventReceiver

public TcpEventReceiver()
                 throws UnknownHostException
Constructs a new TCP/IP event receiver on the default TCP/IP port. The server socket allocation is delayed until the fiber is actually started.

Throws:
UnknownHostException

TcpEventReceiver

public TcpEventReceiver(int port,
                        String ipAddress)
                 throws UnknownHostException
Constructs a new TCP/IP event receiver on the passed port. The server socket allocation is delayed until the fiber is actually started.

Parameters:
port - The binding port for the TCP/IP server socket.
ipAddress - TODO
Throws:
UnknownHostException
Method Detail

start

public void start()
Allocates the server socket and starts up the server socket processor thread. If an error occurs allocating the server socket or the Fiber is in an erronous state then a runtime exceptionis thrown.

Specified by:
start in interface Fiber
Specified by:
start in interface TcpEventReceiverMBean
Throws:
UndeclaredThrowableException - Thrown if an error occurs allocating the server socket.
RuntimeException - Thrown if the fiber is in an erronous state or the underlying thread cannot be started.

stop

public void stop()
Stops the TCP/IP event receiver. This method will block until all the children threads of this object are terminated and joined.

Specified by:
stop in interface Fiber
Specified by:
stop in interface TcpEventReceiverMBean

getName

public String getName()
Returns the name of this Fiber.

Specified by:
getName in interface Fiber

getStatus

public int getStatus()
Returns the status of this Fiber.

Specified by:
getStatus in interface Fiber
Specified by:
getStatus in interface TcpEventReceiverMBean

init

public void init()
Called when the fiber is initialized

Specified by:
init in interface InitializableFiber
Specified by:
init in interface TcpEventReceiverMBean

destroy

public void destroy()
Called when the fiber is destroyed

Specified by:
destroy in interface InitializableFiber
Specified by:
destroy in interface TcpEventReceiverMBean

addEventHandler

public void addEventHandler(EventHandler handler)
Adds a new event handler to receiver. When new events are received the decoded event is passed to the handler.

Specified by:
addEventHandler in interface EventReceiver
Parameters:
handler - A reference to an event handler

removeEventHandler

public void removeEventHandler(EventHandler handler)
Removes an event handler from the list of handler called when an event is received. The handler is removed based upon the method equals() inherieted from the Object class.

Specified by:
removeEventHandler in interface EventReceiver
Parameters:
handler - A reference to the event handler.

getEventHandlers

public List<EventHandler> getEventHandlers()

setEventHandlers

public void setEventHandlers(List<EventHandler> eventHandlers)

getIpAddress

public String getIpAddress()

setIpAddress

public void setIpAddress(String ipAddress)

getPort

public Integer getPort()
Description copied from interface: TcpEventReceiverMBean
Returns the where a listener is waiting to process new request.

Specified by:
getPort in interface TcpEventReceiverMBean
Returns:
The listening port.

setPort

public void setPort(Integer port)
Description copied from interface: TcpEventReceiverMBean
Sets the port where new requests will be handled. This can only be done prior to starting the managed bean. If the managed bean is already running then an exception is thrown.

Specified by:
setPort in interface TcpEventReceiverMBean
Parameters:
port - The port to listen on.

addEventHandler

public void addEventHandler(String name)
                     throws MalformedObjectNameException,
                            InstanceNotFoundException
Description copied from interface: TcpEventReceiverMBean
Adds a new event handler by its managed name.

Specified by:
addEventHandler in interface TcpEventReceiverMBean
Parameters:
name - The name of the handler to add.
Throws:
MalformedObjectNameException - Thrown if the passed name is not a valid ObjectName.
InstanceNotFoundException - Thrown if no managed bean can be found that matches the name.

removeEventHandler

public void removeEventHandler(String name)
                        throws MalformedObjectNameException,
                               InstanceNotFoundException
Description copied from interface: TcpEventReceiverMBean
Removes an event handler. The passed name must be a valid JMX object name.

Specified by:
removeEventHandler in interface TcpEventReceiverMBean
Parameters:
name - The name of the handler to remove.
Throws:
MalformedObjectNameException - Thrown if the passed name is not a valid ObjectName.
InstanceNotFoundException - Thrown if no managed bean can be found that matches the name.

setLogPrefix

public void setLogPrefix(String prefix)
Description copied from interface: TcpEventReceiverMBean
The logging prefix to use

Specified by:
setLogPrefix in interface TcpEventReceiverMBean

setEventsPerConnection

public void setEventsPerConnection(Integer number)
The number of event records a new connection is allowed to send before the connection is terminated by the server. The connection is always terminated after an event receipt is generated, if one is required.

Specified by:
setEventsPerConnection in interface TcpEventReceiverMBean
Parameters:
number - The number of event records.


Copyright © 2009. All Rights Reserved.