OpenNMS API 1.2.9

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

    java.lang.Object
      org.opennms.netmgt.eventd.adaptors.tcp.TcpEventReceiver

All Implemented Interfaces:
  EventReceiver, Fiber, InitializableFiber, TcpEventReceiverMBean

public final class TcpEventReceiver
extends java.lang.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 5814 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
`private java.util.List` `m_handlers` The registered list of event handlers.
`private java.lang.String` `m_logPrefix` The logging prefix
`private int` `m_recsPerConn` The number of event records per connection.
`private TcpServer` `m_server` The server socket
`private int` `m_status` The fiber's status.
`private int` `m_tcpPort` The TCP server to listen on
`private java.lang.Thread` `m_worker` The main server thread.
`(package private) 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)` 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(java.lang.String name)` Adds a new event handler by its managed name.
`void` `destroy()` Called when the fiber is destroyed
`java.lang.String` `getName()` Returns the name of this Fiber.
`java.lang.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(java.lang.String name)` Removes an event handler.
`void` `setEventsPerConnection(java.lang.Integer number)` The number of event records a new connection is allowed to send before the connection is terminated by the server.
`void` `setLogPrefix(java.lang.String prefix)` The logging prefix to use
`void` `setPort(java.lang.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

    static final int UNLIMITED_EVENTS

  The value that defines unlimited events per connection.

  See Also:
    Constant Field Values

### m_worker

    private java.lang.Thread m_worker

  The main server thread. This thread of execution is used to handle all incomming connection requests.

### m_server

    private TcpServer m_server

  The server socket

### m_handlers

    private java.util.List m_handlers

  The registered list of event handlers. Each incomming event will be passed to all event handlers. The event handlers MUST NOT modify the passed event.

### m_status

    private volatile int m_status

  The fiber's status.

### m_tcpPort

    private int m_tcpPort

  The TCP server to listen on

### m_logPrefix

    private java.lang.String m_logPrefix

  The logging prefix

### m_recsPerConn

    private int m_recsPerConn

  The number of event records per connection.

Constructor Detail

### TcpEventReceiver

    public TcpEventReceiver()
                     throws java.io.IOException

  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.

### TcpEventReceiver

    public TcpEventReceiver(int port)
                     throws java.io.IOException

  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.

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 exception`is thrown.

  Specified by:
    `start` in interface `Fiber`
  Throws:
    `java.lang.reflect.UndeclaredThrowableException` - Thrown if an error occurs allocating the server socket.
    `java.lang.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`

### getName

    public java.lang.String getName()

  Returns the name of this Fiber.

  Specified by:
    `getName` in interface `Fiber`
  Returns:
    The name of the `Fiber`.

### getStatus

    public int getStatus()

  Returns the status of this Fiber.

  Specified by:
    `getStatus` in interface `Fiber`
  Returns:
    The current status of the `Fiber`.

### init

    public void init()

  Called when the fiber is initialized

  Specified by:
    `init` in interface `InitializableFiber`

### destroy

    public void destroy()

  Called when the fiber is destroyed

  Specified by:
    `destroy` in interface `InitializableFiber`

### 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.

### getPort

    public java.lang.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(java.lang.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(java.lang.String name)
                         throws javax.management.MalformedObjectNameException,
                                javax.management.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:
    `javax.management.InstanceNotFoundException` - Thrown if no managed bean can be found that matches the name.
    `javax.management.MalformedObjectNameException` - Thrown if the passed name is not a valid ObjectName.

### removeEventHandler

    public void removeEventHandler(java.lang.String name)
                            throws javax.management.MalformedObjectNameException,
                                   javax.management.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:
    `javax.management.MalformedObjectNameException` - Thrown if the passed name is not a valid ObjectName.
    `javax.management.InstanceNotFoundException` - Thrown if no managed bean can be found that matches the name.

### setLogPrefix

    public void setLogPrefix(java.lang.String prefix)

  Description copied from interface: `TcpEventReceiverMBean`
  The logging prefix to use

  Specified by:
    `setLogPrefix` in interface `TcpEventReceiverMBean`

### setEventsPerConnection

    public void setEventsPerConnection(java.lang.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.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.