HOME

com.ireasoning.protocol
Class Session

java.lang.Object
  extended bycom.ireasoning.protocol.ListenerManager
      extended bycom.ireasoning.protocol.Session
All Implemented Interfaces:
Serializable, State
Direct Known Subclasses:
SnmpBaseSession, TL1Session

public abstract class Session
extends ListenerManager
implements Serializable, State

This class represents an open communication channel between client and server.

See Also:
Serialized Form

Field Summary
protected  InetAddress _localAddr
           
protected  int _localPort
           
protected  int _state
          The state of session
protected  Target _target
          Target object representing agent
protected  ListenThread _thread
           
protected  int _timeout
          Time out value
protected  TransportLayer _transportLayer
          Transport layer, ether TCP or UDP
protected  int _tries
          Number of tries, default value is 3.
static int DEFAULT_TIME_OUT
          default time out is 60 seconds
static int TCP
          Tcp transport layer, the default one used by TL1Session
static int UDP
          Udp tranpsport layer, the default one used by SnmpSession
 
Fields inherited from class com.ireasoning.protocol.ListenerManager
_listeners
 
Fields inherited from interface com.ireasoning.core.jmx.State
STARTED, STARTING, STATES, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
protected Session()
           
protected Session(int transportLayer)
          Constructs a new daemon Session
protected Session(String host, int port, int transportLayer)
          Constructs a new Session and connects to host
protected Session(String host, int port, int transportLayer, InetAddress localAddr, int localPort)
          Constructs a new Session and connects to host
protected Session(String host, int port, int transportLayer, InetAddress localAddr, int localPort, int connectionTimeout)
          Constructs a new Session and connects to host
protected Session(String host, int port, TransportLayer transportLayer, InetAddress localAddr, int localPort, int connectionTimeout)
           
protected Session(Target target, int transportLayer, InetAddress localAddr, int localPort)
          Constructs a new Session and connect to host
protected Session(TransportLayer transportLayer)
          Constructs a new daemon Session
 
Method Summary
 void close()
          close the session
protected  void finalize()
          Cleanup.
 int getRetries()
          Returns the number of retries after timeout, default value is 3.
 int getState()
          Returns the state of session, one of {Session.STARTING, Session.STARTED, Session.STOPPING, Session.STARTED}
 String getStateString()
          Returns the string representation of current state.
 Target getTarget()
          Returns the target which represents agent
 int getTimeout()
          Returns the time out value, in milliseconds.
 TransportLayer getTransportLayer()
          Returns the transport layer
protected  TransportLayer getTransportLayer(int i)
          Returns the transport layer
protected  void open(String host, int port, InetAddress localAddr, int localPort)
          Opens a new connection.
protected  void open(String host, int port, InetAddress localAddr, int localPort, int connectionTimeout)
          Opens a new connection.
protected  void open(Target target, InetAddress localAddr, int localPort)
          Opens a new connection to the Target
protected abstract  Object receiveObject()
          Returns received message
protected  void reopen(Target target)
          Reopens connection to the destination
 void setRetries(int retries)
          Sets the number of retries after timeout
 void setTarget(Target target)
          Sets a new target
 void setTimeout(int timeout)
          Sets time out value of underlying Socket
 void setTransportLayer(int transportLayer)
          Sets a new transport layer
 void setTransportLayer(TransportLayer transportLayer)
          Sets a custom transport layer
 void startThread()
          Starts thread for asynchronous communication
 
Methods inherited from class com.ireasoning.protocol.ListenerManager
addListener, listenerExists, notifyListeners, notifyListeners, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UDP

public static final int UDP
Udp tranpsport layer, the default one used by SnmpSession

See Also:
Constant Field Values

TCP

public static final int TCP
Tcp transport layer, the default one used by TL1Session

See Also:
Constant Field Values

DEFAULT_TIME_OUT

public static final int DEFAULT_TIME_OUT
default time out is 60 seconds

See Also:
Constant Field Values

_target

protected Target _target
Target object representing agent


_transportLayer

protected TransportLayer _transportLayer
Transport layer, ether TCP or UDP


_timeout

protected int _timeout
Time out value


_tries

protected int _tries
Number of tries, default value is 3.


_state

protected int _state
The state of session


_thread

protected ListenThread _thread

_localAddr

protected transient InetAddress _localAddr

_localPort

protected transient int _localPort
Constructor Detail

Session

protected Session()

Session

protected Session(int transportLayer)
Constructs a new daemon Session

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)

Session

protected Session(TransportLayer transportLayer)
Constructs a new daemon Session

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)

Session

protected Session(String host,
                  int port,
                  int transportLayer)
           throws IOException
Constructs a new Session and connects to host

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)
host - host name of agent
port - port number of agent
Throws:
IOException - raised if can't connect to remote host

Session

protected Session(String host,
                  int port,
                  int transportLayer,
                  InetAddress localAddr,
                  int localPort)
           throws IOException
Constructs a new Session and connects to host

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)
host - host name of agent
port - port number of agent
Throws:
IOException - raised if can't connect to remote host

Session

protected Session(String host,
                  int port,
                  int transportLayer,
                  InetAddress localAddr,
                  int localPort,
                  int connectionTimeout)
           throws IOException
Constructs a new Session and connects to host

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)
host - host name of agent
port - port number of agent
Throws:
IOException - raised if can't connect to remote host

Session

protected Session(String host,
                  int port,
                  TransportLayer transportLayer,
                  InetAddress localAddr,
                  int localPort,
                  int connectionTimeout)
           throws IOException

Session

protected Session(Target target,
                  int transportLayer,
                  InetAddress localAddr,
                  int localPort)
           throws IOException
Constructs a new Session and connect to host

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)
target - represents the agent
Throws:
IOException - raised if can't connect to remote host
Method Detail

reopen

protected void reopen(Target target)
               throws IOException
Reopens connection to the destination

Throws:
IOException

open

protected void open(String host,
                    int port,
                    InetAddress localAddr,
                    int localPort)
             throws IOException
Opens a new connection. It does nothing if this session is already active.

Parameters:
host - host name of agent
port - port number of agent
Throws:
IOException

open

protected void open(String host,
                    int port,
                    InetAddress localAddr,
                    int localPort,
                    int connectionTimeout)
             throws IOException
Opens a new connection. It does nothing if this session is already active.

Parameters:
host - host name of agent
port - port number of agent
Throws:
IOException

open

protected void open(Target target,
                    InetAddress localAddr,
                    int localPort)
             throws IOException
Opens a new connection to the Target

Parameters:
target - represents the agent
Throws:
IOException

setTransportLayer

public void setTransportLayer(int transportLayer)
Sets a new transport layer

Parameters:
transportLayer - transport layer, ether Session.TCP (TCP tranport layer) or Session.UDP (UDP tranport layer)

setTransportLayer

public void setTransportLayer(TransportLayer transportLayer)
Sets a custom transport layer

Parameters:
transportLayer - transport layer implementation

getTransportLayer

public TransportLayer getTransportLayer()
Returns the transport layer


getTimeout

public int getTimeout()
Returns the time out value, in milliseconds.


setTimeout

public void setTimeout(int timeout)
                throws SocketException
Sets time out value of underlying Socket

Parameters:
timeout - the specified timeout in milliseconds
Throws:
SocketException
See Also:
java.net.Socket.setSoTimeout(int)

getRetries

public int getRetries()
Returns the number of retries after timeout, default value is 3.


setRetries

public void setRetries(int retries)
Sets the number of retries after timeout

Parameters:
retries - number of retries after timeout

close

public void close()
close the session


getTarget

public Target getTarget()
Returns the target which represents agent


setTarget

public void setTarget(Target target)
Sets a new target

Parameters:
target - new target object

finalize

protected void finalize()
                 throws Throwable
Cleanup. Closes connection.

Throws:
Throwable

getState

public int getState()
Returns the state of session, one of {Session.STARTING, Session.STARTED, Session.STOPPING, Session.STARTED}

Specified by:
getState in interface State

getStateString

public String getStateString()
Description copied from interface: State
Returns the string representation of current state. Possible values are {"Starting","Started", "Stopping", "Stopped"}

Specified by:
getStateString in interface State

getTransportLayer

protected TransportLayer getTransportLayer(int i)
Returns the transport layer


startThread

public void startThread()
Starts thread for asynchronous communication


receiveObject

protected abstract Object receiveObject()
                                 throws IOException
Returns received message

Throws:
IOException

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.