org.eclipse.ecf.provider.comm.tcp
Class Client

java.lang.Object
  extended by org.eclipse.ecf.provider.comm.tcp.Client
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, IAsynchConnection, IConnection, ISynchAsynchConnection, ISynchConnection

public final class Client
extends java.lang.Object
implements ISynchAsynchConnection


Field Summary
protected  long closeTimeout
           
protected  ID containerID
           
static long DEFAULT_CLOSE_TIMEOUT
           
static int DEFAULT_MAX_BUFFER_MSG
           
static int DEFAULT_RCVR_PRIORITY
           
static int DEFAULT_SNDR_PRIORITY
           
static int DEFAULT_WAIT_INTERVAL
           
protected  ISynchAsynchEventHandler handler
           
protected  java.io.ObjectInputStream inputStream
           
protected  boolean isClosing
           
protected  int keepAlive
           
protected  java.lang.Thread keepAliveThread
           
protected  int maxMsg
           
protected  java.io.ObjectOutputStream outputStream
           
protected  java.lang.Object outputStreamLock
           
protected  PingMessage ping
           
protected  java.lang.Object pingLock
           
protected  PingResponseMessage pingResp
           
protected  java.util.Map properties
           
static java.lang.String PROTOCOL
           
protected  SimpleFIFOQueue queue
           
protected  java.lang.Thread rcvThread
           
protected  java.lang.Thread sendThread
           
protected  java.net.Socket socket
           
protected  boolean waitForPing
           
 
Constructor Summary
Client(ISynchAsynchEventHandler handler, int keepAlive)
           
Client(java.net.Socket aSocket, java.io.ObjectInputStream iStream, java.io.ObjectOutputStream oStream, ISynchAsynchEventHandler handler)
           
Client(java.net.Socket aSocket, java.io.ObjectInputStream iStream, java.io.ObjectOutputStream oStream, ISynchAsynchEventHandler handler, int maxmsgs)
           
 
Method Summary
 void addListener(IConnectionListener l)
          Add comm layer event listener
 java.lang.Object connect(ID remote, java.lang.Object data, int timeout)
          Connect to a remote process
protected  void debug(java.lang.String msg)
           
 void disconnect()
          Disconnect
 java.lang.Object getAdapter(java.lang.Class clazz)
           
 ID getLocalID()
          Get local ID for this connection
 java.util.Map getProperties()
          Get properties for this connection
 boolean isConnected()
           
 boolean isStarted()
           
 void queueObject(ID recipient, java.io.Serializable obj)
           
 void removeListener(IConnectionListener l)
          remove comm layer event listener
 void sendAsynch(ID recipient, byte[] obj)
          Send data asynchronously.
 void sendAsynch(ID recipient, java.lang.Object obj)
           
 java.io.Serializable sendObject(ID recipient, java.io.Serializable obj)
           
 java.lang.Object sendSynch(ID rec, byte[] obj)
          Send data synchronously, blocking until a result is received
 java.lang.Object sendSynch(ID rec, java.lang.Object obj)
           
 void setCloseTimeout(long t)
           
 void setProperties(java.util.Map props)
           
 void start()
          Start connection
 void stop()
          Stop connection
protected  void traceStack(java.lang.String msg, java.lang.Throwable e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL

public static final java.lang.String PROTOCOL
See Also:
Constant Field Values

DEFAULT_SNDR_PRIORITY

public static final int DEFAULT_SNDR_PRIORITY
See Also:
Constant Field Values

DEFAULT_RCVR_PRIORITY

public static final int DEFAULT_RCVR_PRIORITY
See Also:
Constant Field Values

DEFAULT_CLOSE_TIMEOUT

public static final long DEFAULT_CLOSE_TIMEOUT
See Also:
Constant Field Values

DEFAULT_MAX_BUFFER_MSG

public static final int DEFAULT_MAX_BUFFER_MSG
See Also:
Constant Field Values

DEFAULT_WAIT_INTERVAL

public static final int DEFAULT_WAIT_INTERVAL
See Also:
Constant Field Values

socket

protected java.net.Socket socket

outputStream

protected java.io.ObjectOutputStream outputStream

inputStream

protected java.io.ObjectInputStream inputStream

handler

protected ISynchAsynchEventHandler handler

queue

protected SimpleFIFOQueue queue

keepAlive

protected int keepAlive

sendThread

protected java.lang.Thread sendThread

rcvThread

protected java.lang.Thread rcvThread

keepAliveThread

protected java.lang.Thread keepAliveThread

isClosing

protected boolean isClosing

waitForPing

protected boolean waitForPing

ping

protected PingMessage ping

pingResp

protected PingResponseMessage pingResp

maxMsg

protected int maxMsg

closeTimeout

protected long closeTimeout

properties

protected java.util.Map properties

containerID

protected ID containerID

pingLock

protected java.lang.Object pingLock

outputStreamLock

protected final java.lang.Object outputStreamLock
Constructor Detail

Client

public Client(java.net.Socket aSocket,
              java.io.ObjectInputStream iStream,
              java.io.ObjectOutputStream oStream,
              ISynchAsynchEventHandler handler)
       throws java.io.IOException
Throws:
java.io.IOException

Client

public Client(java.net.Socket aSocket,
              java.io.ObjectInputStream iStream,
              java.io.ObjectOutputStream oStream,
              ISynchAsynchEventHandler handler,
              int maxmsgs)
       throws java.io.IOException
Throws:
java.io.IOException

Client

public Client(ISynchAsynchEventHandler handler,
              int keepAlive)
Method Detail

getLocalID

public ID getLocalID()
Description copied from interface: IConnection
Get local ID for this connection

Specified by:
getLocalID in interface IConnection
Returns:
ID associated with local instance

removeListener

public void removeListener(IConnectionListener l)
Description copied from interface: IConnection
remove comm layer event listener

Specified by:
removeListener in interface IConnection
Parameters:
l - the listener to remove

addListener

public void addListener(IConnectionListener l)
Description copied from interface: IConnection
Add comm layer event listener

Specified by:
addListener in interface IConnection
Parameters:
l - the listener to add

isConnected

public boolean isConnected()
Specified by:
isConnected in interface IConnection
Returns:
true if the implementing class has been previously connected, false if not connected

isStarted

public boolean isStarted()
Specified by:
isStarted in interface IConnection
Returns:
true if connection is started, false otherwise

connect

public java.lang.Object connect(ID remote,
                                java.lang.Object data,
                                int timeout)
                         throws ECFException
Description copied from interface: IConnection
Connect to a remote process

Specified by:
connect in interface IConnection
Parameters:
remote - the identity of the remote to connect to. Must not be null.
data - any data to send with the connection request (e.g. password or other authentication data)
timeout - the timeout (in ms) for the connection to occur
Returns:
a result object that is of type specific to provider implementation
Throws:
ECFException - thrown if some problem with connect

setCloseTimeout

public void setCloseTimeout(long t)

start

public void start()
Description copied from interface: IConnection
Start connection

Specified by:
start in interface IConnection

stop

public void stop()
Description copied from interface: IConnection
Stop connection

Specified by:
stop in interface IConnection

disconnect

public void disconnect()
Description copied from interface: IConnection
Disconnect

Specified by:
disconnect in interface IConnection

sendAsynch

public void sendAsynch(ID recipient,
                       byte[] obj)
                throws java.io.IOException
Description copied from interface: IAsynchConnection
Send data asynchronously. Implementing classes should not block on sending the given data and return immediately.

Specified by:
sendAsynch in interface IAsynchConnection
Parameters:
recipient - the ID of the intended receiver
obj - the data to send
Throws:
java.io.IOException - thrown if data cannot be sent (e.g. disconnected)

sendAsynch

public void sendAsynch(ID recipient,
                       java.lang.Object obj)
                throws java.io.IOException
Throws:
java.io.IOException

queueObject

public void queueObject(ID recipient,
                        java.io.Serializable obj)
                 throws java.io.IOException
Throws:
java.io.IOException

sendObject

public java.io.Serializable sendObject(ID recipient,
                                       java.io.Serializable obj)
                                throws java.io.IOException
Throws:
java.io.IOException

sendSynch

public java.lang.Object sendSynch(ID rec,
                                  java.lang.Object obj)
                           throws java.io.IOException
Throws:
java.io.IOException

sendSynch

public java.lang.Object sendSynch(ID rec,
                                  byte[] obj)
                           throws java.io.IOException
Description copied from interface: ISynchConnection
Send data synchronously, blocking until a result is received

Specified by:
sendSynch in interface ISynchConnection
Parameters:
rec - the receiver to receive the synchronous request
obj - the data to send
Returns:
the data received. The return type will be specific to the provider implementation.
Throws:
java.io.IOException - thrown if sending cannot occur (e.g. not connected)

getProperties

public java.util.Map getProperties()
Description copied from interface: IConnection
Get properties for this connection

Specified by:
getProperties in interface IConnection
Returns:
Map the properties associated with this connection. May be null.

getAdapter

public java.lang.Object getAdapter(java.lang.Class clazz)
Specified by:
getAdapter in interface org.eclipse.core.runtime.IAdaptable

debug

protected void debug(java.lang.String msg)

traceStack

protected void traceStack(java.lang.String msg,
                          java.lang.Throwable e)

setProperties

public void setProperties(java.util.Map props)