org.jboss.remoting.transport.socket
Class MicroSocketClientInvoker

java.lang.Object
  extended by org.jboss.remoting.AbstractInvoker
      extended by org.jboss.remoting.MicroRemoteClientInvoker
          extended by org.jboss.remoting.RemoteClientInvoker
              extended by org.jboss.remoting.transport.socket.MicroSocketClientInvoker
All Implemented Interfaces:
Invoker, ClientInvoker
Direct Known Subclasses:
SocketClientInvoker

public class MicroSocketClientInvoker
extends RemoteClientInvoker

SocketClientInvoker uses Sockets to remotely connect to the a remote ServerInvoker, which must be a SocketServerInvoker.

Version:
$Revision: 5037 $
Author:
Jeff Haynie, Tom Elrod, Ovidiu Feodorov

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jboss.remoting.AbstractInvoker
AbstractInvoker.CallbackLocatorHolder
 
Field Summary
protected  java.net.InetAddress addr
           
protected  ServerAddress address
          connection information
static java.lang.String CLIENT_SOCKET_CLASS_FLAG
          Specifies the fully qualified class name for the custom SocketWrapper implementation to use on the client.
protected  java.lang.Class clientSocketClass
           
protected  java.lang.String clientSocketClassName
           
static java.lang.String CONNECTION_WAIT
          Key for setting time to wait to get permission to get a connection
static int CONNECTION_WAIT_DEFAULT
          Default time to wait to get permission to get a connection
protected static java.util.Map connectionPools
           
protected  int connectionWait
           
static long deserializeTime
           
protected  boolean enableTcpNoDelay
          If the TcpNoDelay option should be used on the socket.
static long getSocketTime
           
protected  Home home
           
protected  boolean keepAlive
          Socket configuration parameters.
protected  boolean keepAliveSet
           
static int MAX_CALL_RETRIES
          Default maximum number of times a invocation will be made when it gets a SocketException.
static int MAX_POOL_SIZE
          Default maximum number of socket connections allowed at any point in time.
static java.lang.String MAX_POOL_SIZE_FLAG
          The client side maximum number of threads.
protected  int maxPoolSize
           
protected  int numberOfCallRetries
           
static java.lang.String ONEWAY_CONNECTION_TIMEOUT
          Key for setting timeout used by OnewayConnectionTask
static int ONEWAY_CONNECTION_TIMEOUT_DEFAULT
          Default timeout value used by OnewayConnectionTask.
protected  int onewayConnectionTimeout
           
protected  boolean oOBInline
           
protected  boolean oOBInlineSet
           
protected  java.util.LinkedList pool
          Pool for this invoker.
protected  int port
           
static long readTime
           
protected  int receiveBufferSize
           
protected  EDU.oswego.cs.dl.util.concurrent.Semaphore semaphore
           
protected static java.util.Map semaphores
           
protected  int sendBufferSize
           
static long serializeTime
           
protected  boolean shouldCheckConnection
          Indicates if will check the socket connection when getting from pool by sending byte over the connection to validate is still good.
protected  boolean soLinger
           
protected  int soLingerDuration
           
protected  boolean soLingerSet
           
static boolean TCP_NODELAY_DEFAULT
          Default value for enable TCP nodelay.
static java.lang.String TCP_NODELAY_FLAG
          Can be either true or false and will indicate if client socket should have TCP_NODELAY turned on or off.
protected  int trafficClass
           
static java.lang.String USE_ONEWAY_CONNECTION_TIMEOUT
          Key to determine if client side oneway invocations should wait to read version.
protected  boolean useOnewayConnectionTimeout
           
static long writeTime
           
 
Fields inherited from class org.jboss.remoting.MicroRemoteClientInvoker
connected, connectHomes, parentFirstClassLoading
 
Fields inherited from class org.jboss.remoting.AbstractInvoker
classbyteloader, configuration, localServerLocators, locator, serializationType, socketFactory, socketFactoryCreatedFromSSLParameters, version
 
Constructor Summary
MicroSocketClientInvoker(InvokerLocator locator)
           
MicroSocketClientInvoker(InvokerLocator locator, java.util.Map configuration)
           
 
Method Summary
 boolean checkingConnection()
          Indicates if will check socket connection when returning from pool by sending byte to the server.
static void clearPool(java.util.LinkedList thepool)
          Close all sockets in a specific pool.
static void clearPools()
          Close all sockets in all pools.
protected  void configureParameters()
           
protected  void configureSocket(java.net.Socket s)
           
protected  SocketWrapper createClientSocket(java.net.Socket socket, int timeout, java.util.Map metadata)
           
protected  ServerAddress createServerAddress(java.net.InetAddress addr, int port)
           
protected  java.net.Socket createSocket(java.lang.String address, int port, int timeout)
           
 void disconnect()
          disconnect from the remote invokere
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 void flushConnectionPool()
           
protected  SocketWrapper getConnection(Marshaller marshaller, UnMarshaller unmarshaller, boolean tryPool, int timeAllowed)
           
 int getConnectionWait()
           
protected  java.lang.String getDefaultDataType()
          Each implementation of the remote client invoker should have a default data type that is used in the case it is not specified in the invoker locator URI.
 Home getHomeInUse()
           
 int getNumberOfAvailableConnections()
           
 int getNumberOfCallRetries()
           
 int getNumberOfRetries()
           
 int getNumberOfUsedConnections()
           
protected  SocketWrapper getPooledConnection()
           
 int getReceiveBufferSize()
           
 boolean getReuseAddress()
          Returns if newly created sockets will have SO_REUSEADDR enabled.
 int getSendBufferSize()
           
 java.lang.String getServerHostName()
          The name of of the server.
 int getSoLingerDuration()
           
 int getTrafficClass()
           
protected  Home getUsableAddress(InvokerLocator locator)
           
protected  void handleConnect()
          Subclasses must implement this method to provide a hook to connect to the remote server, if this applies to the specific transport.
protected  void handleDisconnect()
          Subclasses must implement this method to provide a hook to disconnect from the remote server, if this applies to the specific transport.
protected  java.lang.Object handleException(java.lang.Exception ex, SocketWrapper socketWrapper)
           
protected  void handleRetriableException(SocketWrapper socketWrapper, java.lang.Exception e, int retryCount)
           
protected  void initPool()
           
 boolean isKeepAlive()
           
 boolean isOOBInline()
           
 boolean isSoLinger()
           
 void setConnectionWait(int connectionWait)
           
 void setKeepAlive(boolean keepAlive)
           
 void setNumberOfCallRetries(int numberOfCallRetries)
          Sets the number of times an invocation will retry based on getting SocketException.
 void setNumberOfRetries(int numberOfRetries)
          Sets the number of retries to get a socket connection.
 void setOOBInline(boolean inline)
           
 void setReceiveBufferSize(int receiveBufferSize)
           
 void setReuseAddress(boolean reuse)
          Sets if newly created socket should have SO_REUSEADDR enable.
 void setSendBufferSize(int sendBufferSize)
           
 void setSoLinger(boolean soLinger)
           
 void setSoLingerDuration(int soLingerDuration)
           
 void setTrafficClass(int trafficClass)
           
protected  void setup()
           
protected  java.lang.Object transport(java.lang.String sessionID, java.lang.Object invocation, java.util.Map metadata, Marshaller marshaller, UnMarshaller unmarshaller)
           
 
Methods inherited from class org.jboss.remoting.MicroRemoteClientInvoker
connect, establishLease, getConnectHomes, getLeasePeriod, getMarshaller, getSessionId, getUnMarshaller, init, invoke, isConnected, postProcess, preProcess, setMarshaller, setUnMarshaller, terminateLease
 
Methods inherited from class org.jboss.remoting.AbstractInvoker
addClientLocator, createSocketFactory, getClassLoader, getClientLocator, getClientLocators, getConfiguration, getLocator, getSerializationType, getSocketFactory, getVersion, isCompleteSocketFactory, isSocketFactoryCreatedFromSSLParameters, needsCustomSSLConfiguration, setClassLoader, setSerializationType, setSocketFactory, setVersion, wrapSocketFactory
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.remoting.transport.ClientInvoker
addClientLocator, getClientLocator, getClientLocators, getSocketFactory, setSocketFactory
 
Methods inherited from interface org.jboss.remoting.Invoker
getLocator
 

Field Detail

TCP_NODELAY_FLAG

public static final java.lang.String TCP_NODELAY_FLAG
Can be either true or false and will indicate if client socket should have TCP_NODELAY turned on or off. TCP_NODELAY is for a specific purpose; to disable the Nagle buffering algorithm. It should only be set for applications that send frequent small bursts of information without getting an immediate response; where timely delivery of data is required (the canonical example is mouse movements). The default is false.

See Also:
Constant Field Values

MAX_POOL_SIZE_FLAG

public static final java.lang.String MAX_POOL_SIZE_FLAG
The client side maximum number of threads. The default is MAX_POOL_SIZE.

See Also:
Constant Field Values

CLIENT_SOCKET_CLASS_FLAG

public static final java.lang.String CLIENT_SOCKET_CLASS_FLAG
Specifies the fully qualified class name for the custom SocketWrapper implementation to use on the client. Note, will need to make sure this is marked as a client parameter (using the 'isParam' attribute). Making this change will not affect the marshaller/unmarshaller that is used, which may also be a requirement.

See Also:
Constant Field Values

ONEWAY_CONNECTION_TIMEOUT

public static final java.lang.String ONEWAY_CONNECTION_TIMEOUT
Key for setting timeout used by OnewayConnectionTask

See Also:
Constant Field Values

USE_ONEWAY_CONNECTION_TIMEOUT

public static final java.lang.String USE_ONEWAY_CONNECTION_TIMEOUT
Key to determine if client side oneway invocations should wait to read version. See JBREM-706.

See Also:
Constant Field Values

CONNECTION_WAIT

public static final java.lang.String CONNECTION_WAIT
Key for setting time to wait to get permission to get a connection

See Also:
Constant Field Values

TCP_NODELAY_DEFAULT

public static final boolean TCP_NODELAY_DEFAULT
Default value for enable TCP nodelay. Value is false.

See Also:
Constant Field Values

MAX_CALL_RETRIES

public static final int MAX_CALL_RETRIES
Default maximum number of times a invocation will be made when it gets a SocketException. Default is 3.

See Also:
Constant Field Values

MAX_POOL_SIZE

public static final int MAX_POOL_SIZE
Default maximum number of socket connections allowed at any point in time. Default is 50.

See Also:
Constant Field Values

ONEWAY_CONNECTION_TIMEOUT_DEFAULT

public static final int ONEWAY_CONNECTION_TIMEOUT_DEFAULT
Default timeout value used by OnewayConnectionTask. Value is 2 seconds.

See Also:
Constant Field Values

CONNECTION_WAIT_DEFAULT

public static final int CONNECTION_WAIT_DEFAULT
Default time to wait to get permission to get a connection

See Also:
Constant Field Values

connectionPools

protected static final java.util.Map connectionPools

semaphores

protected static final java.util.Map semaphores

getSocketTime

public static long getSocketTime

readTime

public static long readTime

writeTime

public static long writeTime

serializeTime

public static long serializeTime

deserializeTime

public static long deserializeTime

addr

protected java.net.InetAddress addr

port

protected int port

shouldCheckConnection

protected boolean shouldCheckConnection
Indicates if will check the socket connection when getting from pool by sending byte over the connection to validate is still good.


enableTcpNoDelay

protected boolean enableTcpNoDelay
If the TcpNoDelay option should be used on the socket.


clientSocketClassName

protected java.lang.String clientSocketClassName

clientSocketClass

protected java.lang.Class clientSocketClass

numberOfCallRetries

protected int numberOfCallRetries

maxPoolSize

protected int maxPoolSize

onewayConnectionTimeout

protected int onewayConnectionTimeout

useOnewayConnectionTimeout

protected boolean useOnewayConnectionTimeout

connectionWait

protected int connectionWait

pool

protected java.util.LinkedList pool
Pool for this invoker. This is shared between all instances of proxies attached to a specific invoker.


semaphore

protected EDU.oswego.cs.dl.util.concurrent.Semaphore semaphore

address

protected ServerAddress address
connection information


home

protected Home home

keepAlive

protected boolean keepAlive
Socket configuration parameters.


keepAliveSet

protected boolean keepAliveSet

oOBInline

protected boolean oOBInline

oOBInlineSet

protected boolean oOBInlineSet

receiveBufferSize

protected int receiveBufferSize

sendBufferSize

protected int sendBufferSize

soLinger

protected boolean soLinger

soLingerSet

protected boolean soLingerSet

soLingerDuration

protected int soLingerDuration

trafficClass

protected int trafficClass
Constructor Detail

MicroSocketClientInvoker

public MicroSocketClientInvoker(InvokerLocator locator)

MicroSocketClientInvoker

public MicroSocketClientInvoker(InvokerLocator locator,
                                java.util.Map configuration)
Method Detail

clearPool

public static void clearPool(java.util.LinkedList thepool)
Close all sockets in a specific pool.


clearPools

public static void clearPools()
Close all sockets in all pools.


checkingConnection

public boolean checkingConnection()
Indicates if will check socket connection when returning from pool by sending byte to the server. Default value will be false.


getReuseAddress

public boolean getReuseAddress()
Returns if newly created sockets will have SO_REUSEADDR enabled. Default is for this to be true.


setReuseAddress

public void setReuseAddress(boolean reuse)
Sets if newly created socket should have SO_REUSEADDR enable. Default is true.


isKeepAlive

public boolean isKeepAlive()

setKeepAlive

public void setKeepAlive(boolean keepAlive)

isOOBInline

public boolean isOOBInline()

setOOBInline

public void setOOBInline(boolean inline)

getReceiveBufferSize

public int getReceiveBufferSize()

setReceiveBufferSize

public void setReceiveBufferSize(int receiveBufferSize)

getSendBufferSize

public int getSendBufferSize()

setSendBufferSize

public void setSendBufferSize(int sendBufferSize)

isSoLinger

public boolean isSoLinger()

getSoLingerDuration

public int getSoLingerDuration()

setSoLinger

public void setSoLinger(boolean soLinger)

setSoLingerDuration

public void setSoLingerDuration(int soLingerDuration)

getTrafficClass

public int getTrafficClass()

setTrafficClass

public void setTrafficClass(int trafficClass)

disconnect

public void disconnect()
Description copied from class: MicroRemoteClientInvoker
disconnect from the remote invokere

Specified by:
disconnect in interface ClientInvoker
Overrides:
disconnect in class MicroRemoteClientInvoker

flushConnectionPool

public void flushConnectionPool()

getConnectionWait

public int getConnectionWait()

setConnectionWait

public void setConnectionWait(int connectionWait)

getHomeInUse

public Home getHomeInUse()

setNumberOfCallRetries

public void setNumberOfCallRetries(int numberOfCallRetries)
Sets the number of times an invocation will retry based on getting SocketException.


getNumberOfCallRetries

public int getNumberOfCallRetries()

setNumberOfRetries

public void setNumberOfRetries(int numberOfRetries)
Sets the number of retries to get a socket connection.

Parameters:
numberOfRetries - Must be a number greater than 0.

getNumberOfRetries

public int getNumberOfRetries()

getServerHostName

public java.lang.String getServerHostName()
                                   throws java.lang.Exception
The name of of the server.

Throws:
java.lang.Exception

getNumberOfUsedConnections

public int getNumberOfUsedConnections()

getNumberOfAvailableConnections

public int getNumberOfAvailableConnections()

setup

protected void setup()
              throws java.lang.Exception
Throws:
java.lang.Exception

configureParameters

protected void configureParameters()

createServerAddress

protected ServerAddress createServerAddress(java.net.InetAddress addr,
                                            int port)

finalize

protected void finalize()
                 throws java.lang.Throwable
Description copied from class: MicroRemoteClientInvoker
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will transport the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Overrides:
finalize in class MicroRemoteClientInvoker
Throws:
java.lang.Throwable - the Exception raised by this method

handleConnect

protected void handleConnect()
                      throws ConnectionFailedException
Description copied from class: MicroRemoteClientInvoker
Subclasses must implement this method to provide a hook to connect to the remote server, if this applies to the specific transport. However, in some transport implementations, this may not make must difference since the connection is not persistent among invocations, such as SOAP. In these cases, the method should silently return without any processing.

Specified by:
handleConnect in class MicroRemoteClientInvoker
Throws:
ConnectionFailedException

getUsableAddress

protected Home getUsableAddress(InvokerLocator locator)

handleDisconnect

protected void handleDisconnect()
Description copied from class: MicroRemoteClientInvoker
Subclasses must implement this method to provide a hook to disconnect from the remote server, if this applies to the specific transport. However, in some transport implementations, this may not make must difference since the connection is not persistent among invocations, such as SOAP. In these cases, the method should silently return without any processing.

Specified by:
handleDisconnect in class MicroRemoteClientInvoker

getDefaultDataType

protected java.lang.String getDefaultDataType()
Each implementation of the remote client invoker should have a default data type that is used in the case it is not specified in the invoker locator URI.

Specified by:
getDefaultDataType in class MicroRemoteClientInvoker

transport

protected java.lang.Object transport(java.lang.String sessionID,
                                     java.lang.Object invocation,
                                     java.util.Map metadata,
                                     Marshaller marshaller,
                                     UnMarshaller unmarshaller)
                              throws java.io.IOException,
                                     ConnectionFailedException,
                                     java.lang.ClassNotFoundException
Specified by:
transport in class MicroRemoteClientInvoker
Throws:
java.io.IOException
ConnectionFailedException
java.lang.ClassNotFoundException

handleException

protected java.lang.Object handleException(java.lang.Exception ex,
                                           SocketWrapper socketWrapper)
                                    throws java.lang.ClassNotFoundException,
                                           InvocationFailureException
Throws:
java.lang.ClassNotFoundException
InvocationFailureException

handleRetriableException

protected void handleRetriableException(SocketWrapper socketWrapper,
                                        java.lang.Exception e,
                                        int retryCount)

initPool

protected void initPool()

getConnection

protected SocketWrapper getConnection(Marshaller marshaller,
                                      UnMarshaller unmarshaller,
                                      boolean tryPool,
                                      int timeAllowed)
                               throws java.lang.Exception
Throws:
java.lang.Exception

createClientSocket

protected SocketWrapper createClientSocket(java.net.Socket socket,
                                           int timeout,
                                           java.util.Map metadata)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

createSocket

protected java.net.Socket createSocket(java.lang.String address,
                                       int port,
                                       int timeout)
                                throws java.io.IOException
Throws:
java.io.IOException

configureSocket

protected void configureSocket(java.net.Socket s)
                        throws java.net.SocketException
Throws:
java.net.SocketException

getPooledConnection

protected SocketWrapper getPooledConnection()


Copyright ? 1998-2005 JBoss Inc . All Rights Reserved.