HOME

com.ireasoning.protocol.tl1
Class TL1Session

java.lang.Object
  extended bycom.ireasoning.protocol.ListenerManager
      extended bycom.ireasoning.protocol.Session
          extended bycom.ireasoning.protocol.tl1.TL1Session
All Implemented Interfaces:
Serializable, State

public class TL1Session
extends Session

This class represents an open sesssion between TL1 agent and manager.

See Also:
Serialized Form

Field Summary
static int SSH
           
 
Fields inherited from class com.ireasoning.protocol.Session
_localAddr, _localPort, _state, _target, _thread, _timeout, _transportLayer, _tries, DEFAULT_TIME_OUT, TCP, UDP
 
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
TL1Session()
          Constructs a new TL1Session.
TL1Session(String host, int port)
          Constructs a new TL1Session, and connect to passed host.
TL1Session(String host, int port, int transportLayer)
          Constructs a new TL1Session, and connect to passed host.
TL1Session(String host, int port, int transportLayer, int connectionTimeout)
          Constructs a new TL1Session, and connect to passed host.
TL1Session(String host, int port, String username, String password)
          Constructs a new SSH based TL1Session, and connect to passed host.
TL1Session(String host, int port, String username, String password, int connectionTimeout)
          Constructs a new SSH based TL1Session, and connect to passed host.
 
Method Summary
 void asyncSend(TL1Command request)
          Used for asynchronous communication.
 boolean isKeepAliveThreadRunning()
          Returns true if keep-alive thread is running, which send dummy command to keep connection open
 void launchKeepAliveThread(String tl1command, int interval)
          Some TL1 agents terminate idle connection.
 void launchKeepAliveThread(String tl1command, int interval, boolean syncMode)
          Some TL1 agents terminate idle connection.
protected  void open(String host, int port)
          Opens a connection to TL1 agent
protected  Object receiveObject()
          Returns received response message
 TL1ResponseMsg[] send(TL1Command request)
          Sends out TL1 command to the agent.
 TL1ResponseMsg[] send(TL1Command request, int numOfResponses)
          Sends out TL1 command to the agent.
 void sendHandShakingCode(String code, String end)
          Some TL1 agents have banner page, such as "...
 void setSkipParsing(boolean skipParsing)
          Set to skip parsing the incoming messages or not.
 void setTimeout(int timeout)
          Sets time out value of underlying Socket
 TL1NotificationMsg[] waitForNotificationMsg()
          Blocked and waits for TL1 notification message
 void write(TL1Command request)
          Similar to send(TL1Command), but does not block until response comes back.
 
Methods inherited from class com.ireasoning.protocol.Session
close, finalize, getRetries, getState, getStateString, getTarget, getTimeout, getTransportLayer, getTransportLayer, open, open, open, reopen, setRetries, setTarget, setTransportLayer, setTransportLayer, startThread
 
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

SSH

public static final int SSH
See Also:
Constant Field Values
Constructor Detail

TL1Session

public TL1Session(String host,
                  int port)
           throws IOException
Constructs a new TL1Session, and connect to passed host.

Parameters:
host - host name of TL1 agent
port - port number of TL1 agent
Throws:
IOException - raised if can't connect to remote host

TL1Session

public TL1Session()
Constructs a new TL1Session. open(String host, int port) needs to be called later to connect to TL1 agent


TL1Session

public TL1Session(String host,
                  int port,
                  String username,
                  String password)
           throws IOException
Constructs a new SSH based TL1Session, and connect to passed host.

Parameters:
host - host name of TL1 agent
port - port number of TL1 agent
username - SSH login user name
password - SSH login passowrd
Throws:
IOException - raised if can't connect to remote host
com.ireasoning.core.network.AuthenticationException - raised if authentication failed

TL1Session

public TL1Session(String host,
                  int port,
                  String username,
                  String password,
                  int connectionTimeout)
           throws IOException
Constructs a new SSH based TL1Session, and connect to passed host.

Parameters:
host - host name of TL1 agent
port - port number of TL1 agent
username - SSH login user name
password - SSH login passowrd
connectionTimeout - Connects this socket to the server with this timeout value, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
Throws:
IOException - raised if can't connect to remote host
com.ireasoning.core.network.AuthenticationException - raised if authentication failed

TL1Session

public TL1Session(String host,
                  int port,
                  int transportLayer,
                  int connectionTimeout)
           throws IOException
Constructs a new TL1Session, and connect to passed host.

Parameters:
host - host name of TL1 agent
port - port number of TL1 agent
transportLayer - transport layer to use, default is TCP transport layer (TransportLayer.TCP).
connectionTimeout - Connects this socket to the server with this timeout value, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
Throws:
IOException - raised if can't connect to remote host
See Also:
TL1Session(String, int)

TL1Session

public TL1Session(String host,
                  int port,
                  int transportLayer)
           throws IOException
Constructs a new TL1Session, and connect to passed host.

Parameters:
host - host name of TL1 agent
port - port number of TL1 agent
transportLayer - transport layer to use, default is TCP transport layer (TransportLayer.TCP).
Throws:
IOException - raised if can't connect to remote host
See Also:
TL1Session(String, int)
Method Detail

open

protected void open(String host,
                    int port)
             throws IOException
Opens a connection to TL1 agent

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

setSkipParsing

public void setSkipParsing(boolean skipParsing)
Set to skip parsing the incoming messages or not.

Parameters:
skipParsing - true if not to parse incoming message.

launchKeepAliveThread

public void launchKeepAliveThread(String tl1command,
                                  int interval)
                           throws TL1ParsingException
Some TL1 agents terminate idle connection. This method can launch a thread which sends dummny command periodically so this connection can keep open. It can be useful for a long session with lots of idle time.

Parameters:
tl1command - dummy TL1 command to send to keep connection alive
interval - time interval to send dummy tl1 command, in seconds
Throws:
TL1ParsingException - if the passed tl1command is not valid.
See Also:
isKeepAliveThreadRunning()

launchKeepAliveThread

public void launchKeepAliveThread(String tl1command,
                                  int interval,
                                  boolean syncMode)
                           throws TL1ParsingException
Some TL1 agents terminate idle connection. This method can launch a thread which sends dummny command periodically so this connection can keep open. It can be useful for a long session with lots of idle time.

Parameters:
tl1command - dummy TL1 command to send to keep connection alive
interval - time interval to send dummy tl1 command, in seconds
syncMode - if true, keep-alive thread uses synchronous send. Default value is 'true'.
Throws:
TL1ParsingException - if the passed tl1command is not valid.
See Also:
isKeepAliveThreadRunning()

isKeepAliveThreadRunning

public boolean isKeepAliveThreadRunning()
Returns true if keep-alive thread is running, which send dummy command to keep connection open

See Also:
launchKeepAliveThread(java.lang.String, int)

waitForNotificationMsg

public TL1NotificationMsg[] waitForNotificationMsg()
                                            throws IOException
Blocked and waits for TL1 notification message

Returns:
TL1NotificationMsg TL1 notification messages received.
Throws:
IOException
See Also:
launchKeepAliveThread(java.lang.String, int)

setTimeout

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

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

receiveObject

protected Object receiveObject()
                        throws IOException
Returns received response message

Specified by:
receiveObject in class Session
Throws:
TimeoutException - raised if timeout after retries
IOException

send

public TL1ResponseMsg[] send(TL1Command request)
                      throws IOException
Sends out TL1 command to the agent. It blocks until it get responses. If you do not care about the response, write(TL1Command) method is a better choice. If you know how many response messages you'll receive, send(TL1Command request, int numOfResponses) method can be used to receive all expected response messages.

Parameters:
request - the TL1 command to be sent
Returns:
TL1ResponseMsg[] an array of TL1ResponseMsg received.
Throws:
IOException - if time out (after retries) or socket is not valid.
TimeoutException - if time out after retries (TimeoutException is a subclass of IOException)
See Also:
write(TL1Command), send(TL1Command , int ), asyncSend(com.ireasoning.protocol.tl1.TL1Command)

send

public TL1ResponseMsg[] send(TL1Command request,
                             int numOfResponses)
                      throws IOException
Sends out TL1 command to the agent. It blocks until it get expected number of responses.

Parameters:
request - the TL1 command to be sent
numOfResponses - number of response message expected.
Returns:
TL1ResponseMsg[] an array of TL1ResponseMsg received, or null if it can't get expected number of results.
Throws:
IOException - if time out (after retries) or socket is not valid.
TimeoutException - if time out after retries (TimeoutException is a subclass of IOException)
See Also:
send(TL1Command), write(TL1Command), asyncSend(com.ireasoning.protocol.tl1.TL1Command)

asyncSend

public void asyncSend(TL1Command request)
               throws IOException
Used for asynchronous communication. Caller needs call addListener(Listener) first to register itself, then call this method to send out TL1Command, a separate thread will notify caller later about received TL1 response. It doesn't block after calling this method.

Parameters:
request - the TL1 command to be sent
Throws:
IOException - if socket exception occurs.
See Also:
send(TL1Command), tl1asyncsend.java example

write

public void write(TL1Command request)
           throws IOException
Similar to send(TL1Command), but does not block until response comes back. It returns immediately after data is sent out.

Throws:
IOException - if socket exception occurs.
See Also:
send(TL1Command)

sendHandShakingCode

public void sendHandShakingCode(String code,
                                String end)
                         throws IOException
Some TL1 agents have banner page, such as "... Press any key to continue ...". In this case, user can programmactically send handshaking code to pass this stage.

Parameters:
code - the handshaking code to send. If it's null or an empty string, nothing will be sent out first.
end - after sending handshaking code, when receive "end" string, the program should get out of receiving. If "end" is an empty string "" or null, the program won't call receive code.
Throws:
TimeoutException - if time out after retries (TimeoutException is a subclass of IOException)
IOException - if socket exception occurs.

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.