org.opennms.protocols.icmpd
Class DaemonConnection

java.lang.Object
  |
  +--org.opennms.protocols.icmpd.DaemonConnection

public class DaemonConnection
extends Object

Creates a default connection to the ICMP daemon for sending and receiving ICMP messages.

Version:
0.1
Author:
Brian Weaver

Field Summary
static int DEFAULT_PORT
          The default port to connect on the local host.
(package private)  Socket m_channel
           
private  Object m_recvSync
           
private  Object m_sendSync
           
static String SERVICE_NAME
          The default service name for the ICMP daemon.
 
Constructor Summary
DaemonConnection()
          Creates a new connection on the local host to the default port.
DaemonConnection(int port)
          Creates a new daemon connnection to the specified port on on the local machine.
 
Method Summary
 void close()
          Closes the connection with the icmp daemon
 MessageHeader recvMessage()
          Receives a message from the daemon and returns message header object.
 void sendMessage(MessageHeader hdr)
          Sends the message to the icmp daemon.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_channel

Socket m_channel

m_sendSync

private Object m_sendSync

m_recvSync

private Object m_recvSync

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to connect on the local host.

SERVICE_NAME

public static final String SERVICE_NAME
The default service name for the ICMP daemon.
Constructor Detail

DaemonConnection

public DaemonConnection()
                 throws UnknownHostException,
                        IOException
Creates a new connection on the local host to the default port.
Throws:
UnknownHostException - Thrown if 127.0.0.1 is an unknown host
IOException - Thrown if an error occurs connecting to the port.

DaemonConnection

public DaemonConnection(int port)
                 throws UnknownHostException,
                        IOException
Creates a new daemon connnection to the specified port on on the local machine.
Parameters:
port - The port to connect to on the loopback interface.
Throws:
UnknownHostException - Thrown if 127.0.0.1 is an unknown host
IOException - Thrown if an error occurs connecting to the port.
Method Detail

close

public void close()
           throws IOException
Closes the connection with the icmp daemon
Throws:
IOException - Thrown if an error occurs closing the connection.

sendMessage

public void sendMessage(MessageHeader hdr)
                 throws IOException
Sends the message to the icmp daemon.
Parameters:
hdr - The message to be sent
Throws:
IOException - Thrown if an error occurs writing the object.

recvMessage

public MessageHeader recvMessage()
                          throws IOException
Receives a message from the daemon and returns message header object. The object is actually one of the derived classes.
Returns:
The MessageHeader base object received.
Throws:
IOException - Thrown if an error occurs.