com.sap.mw.jco
Class JCO.Pool

java.lang.Object
  |
  +--com.sap.mw.jco.JCO.Pool
Enclosing class:
JCO

public static class JCO.Pool
extends java.lang.Object

This class encapsulates a connection pool. A pool is a set of client-connections to a certain destination. The pool may automatically create new connections to the specified remote system or return an already existing one. It also provides methods to return a connection back to the pool when it is no longer needed.
It checks periodically which connections are no longer in use and can be closed in order to save valuable system resources. The time period after which the pool checks the connections as well as the time after which a connection will time-out can be configured by the calling application.


Field Summary
 int INFINITE
          The max of connections these can be created by the pool
 
Method Summary
 void detachFromPool(JCO.Client client)
          Detaches a client-connection from the pool.
 boolean getAbapDebug()
          Returns true if ABAP debugging is enabled for the connections of this pool, and false otherwise.
 long getConnectionTimeout()
          Returns the connection timeout (in milliseconds).
 int getCurrentPoolSize()
          Returns the current pool size, i.e. the number of connections which are opened by the pool and internally held.
 int getMaxConnections()
          Returns the max. connections, count of connections that can be allocated from pool.
 int getMaxPoolSize()
          Returns the max. count of connections that will be pooled.
 int getMaxUsed()
          Returns the max. number of connections used so far
 long getMaxWaitTime()
          Returns the max. time to wait for a connection request when the pool is exhausted.
 java.lang.String getName()
          Returns the pool's name
 int getNumUsed()
          Returns the number of connections in the pool which are currently reserved by the application due to calls to JCO.getClient().
 int getNumWaitingThreads()
          Returns the number of threads that are waiting for a connection.
 JCO.PoolManager getPoolManager()
          Returns the pool manager this pool is a member of
 boolean getResetOnRelease()
          Returns true if a connection is being cleaned up in JCO.releaseClient(), false otherwise.
 byte[] getStates()
          Returns the states of all existing client connections in this pool
 long getTimeoutCheckPeriod()
          Returns the timeout check period in (ms), i.e. the time after which all connections are being checked for timeouts periodically.
The default value is 60 seconds (60000 ms).
 boolean getTrace()
          Returns whether trace for this pool is enabled or not.
 void setAbapDebug(boolean debug)
          Enables/disables ABAP debug
 void setConnectionTimeout(long connection_timeout)
          Sets the new connection timeout (in milliseconds).
 void setMaxConnections(int max_connections)
          Set the new max. connections, count of connections that can be allocated from pool.
 void setMaxPoolSize(int max_pool_size)
          Set the maximal count of connections, which will be hold in the pool opened, after connections are returned to pool.
 void setMaxWaitTime(long max_wait_time)
          Sets the max. time to wait in a connection request when the pool is exhausted.
 void setResetOnRelease(boolean reset_on_release)
          Enables/disables cleanup when the client is being returned to its pool.
 void setTimeoutCheckPeriod(long timeout_check_period)
          Sets the timeout check period (in milliseconds), i.e. the time after which all connections are being checked for timeouts periodically.
 void setTrace(boolean trace)
          Enables/disables trace for the connections of the pool.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITE

public final int INFINITE
The max of connections these can be created by the pool
Method Detail

setResetOnRelease

public final void setResetOnRelease(boolean reset_on_release)
Enables/disables cleanup when the client is being returned to its pool. The default is resetting the connection after each JCO.releaseClient().
Parameters:
reset_on_release - if true reset the connection, e.g. free all resources that might have been allocated on either the server side or by the local middleware layer. On systems below SAP 4.0A resetting a connection effectively means closing and subsequently reopening the connection which is a very expensive process. However, several scenarios (e.g. BAPIs) need reinitialized connections while others might not. This depends strongly on the function modules and their implementation in the mySAP system. In certain cases it might be worthwhile to switch the cleanup off for performance reasons. Use with care !

getResetOnRelease

public final boolean getResetOnRelease()
Returns true if a connection is being cleaned up in JCO.releaseClient(), false otherwise.
Returns:
true if a connection is being cleaned up, false otherwise.

setAbapDebug

public void setAbapDebug(boolean debug)
Enables/disables ABAP debug
Parameters:
debug - if true enables ABAP debugging, disables it otherwise

getAbapDebug

public final boolean getAbapDebug()
Returns true if ABAP debugging is enabled for the connections of this pool, and false otherwise.
Returns:
true if ABAP debugging is enabled, false otherwise

getTrace

public final boolean getTrace()
Returns whether trace for this pool is enabled or not.
Returns:
true if trace is enabled, false otherwise

setTrace

public final void setTrace(boolean trace)
Enables/disables trace for the connections of the pool.
Parameters:
trace - if true enables the trace and disables it otherwise.

getName

public final java.lang.String getName()
Returns the pool's name
Returns:
the name of the pool

getPoolManager

public final JCO.PoolManager getPoolManager()
Returns the pool manager this pool is a member of
Returns:
the pool manager

getMaxPoolSize

public final int getMaxPoolSize()
Returns the max. count of connections that will be pooled. If
getMaxPoolSize() < getMaxConnections()
the superfluous connections will be closed immediately.
Returns:
the max. number of connections allowed in this pool

setMaxPoolSize

public final void setMaxPoolSize(int max_pool_size)
Set the maximal count of connections, which will be hold in the pool opened, after connections are returned to pool. All further connection will be closed on release. Note: If max_pool_size is greater than getMaxConnections() the max count of allocable connections will be set to max_pool_size.
Throws:
java.lang.IllegalArgumentException - if max_pool_size less than zero.

getMaxConnections

public final int getMaxConnections()
Returns the max. connections, count of connections that can be allocated from pool. If all connections are used and pool exhausted, the pool has to wait a getMaxWaitTime() until a connection is released. If during the wait time any connections aren't released, the pool throws an exception.
Returns:
the max. count of connections that can be allocated from pool

setMaxConnections

public final void setMaxConnections(int max_connections)
Set the new max. connections, count of connections that can be allocated from pool.
Throws:
JCO.Exception - if an error occurs during resize of pool

getCurrentPoolSize

public final int getCurrentPoolSize()
Returns the current pool size, i.e. the number of connections which are opened by the pool and internally held.
Returns:
the current pool size

getMaxUsed

public final int getMaxUsed()
Returns the max. number of connections used so far
Returns:
the max. number of connections used so far

getNumUsed

public final int getNumUsed()
Returns the number of connections in the pool which are currently reserved by the application due to calls to JCO.getClient().
Returns:
the current number of reserved connections in the pool

getNumWaitingThreads

public final int getNumWaitingThreads()
Returns the number of threads that are waiting for a connection.
Returns:
the current number of threads waiting for a connection.

setMaxWaitTime

public final void setMaxWaitTime(long max_wait_time)
Sets the max. time to wait in a connection request when the pool is exhausted. The default value is 30 seconds.
Parameters:
max_wait_time - the time to wait for a connection request in milliseconds

getMaxWaitTime

public final long getMaxWaitTime()
Returns the max. time to wait for a connection request when the pool is exhausted.
Returns:
Returns the max. time to wait for a connection in milliseconds

getConnectionTimeout

public long getConnectionTimeout()
Returns the connection timeout (in milliseconds). A connection is being regarded * as timed out when there has been no activity on it for the specified time interval.
The default value is 10 minutes (600000 ms)
Returns:
the connection timeout in units of milliseconds

setConnectionTimeout

public void setConnectionTimeout(long connection_timeout)
Sets the new connection timeout (in milliseconds). A connection is being regarded as timed-out when there has been no activity on it for the specified time interval.
The default value is 10 minutes (600000 ms).
Parameters:
connection_timeout - the new value for the connection timeout in milliseconds

getTimeoutCheckPeriod

public long getTimeoutCheckPeriod()
Returns the timeout check period in (ms), i.e. the time after which all connections are being checked for timeouts periodically.
The default value is 60 seconds (60000 ms).
Returns:
the time interval in milliseconds

setTimeoutCheckPeriod

public void setTimeoutCheckPeriod(long timeout_check_period)
Sets the timeout check period (in milliseconds), i.e. the time after which all connections are being checked for timeouts periodically. An interval of 0 disables checkings.
The default value is 60 seconds (60000 ms).
Parameters:
timeout_check_period - the new interval after which the connections will be checked for timeouts.
Throws:
java.lang.IllegalArgumentException - if timeout_check_period is negative.

getStates

public final byte[] getStates()
Returns the states of all existing client connections in this pool
Returns:
the list of states of all currently existing connections
See Also:
getNumUsed(), getCurrentPoolSize()

detachFromPool

public void detachFromPool(JCO.Client client)
Detaches a client-connection from the pool. The client wont be closed. This method converts a pooled client to a single client. Only pooled clients, those aren't released, can be detached from its pool.
Parameters:
client - the client connection which is being returned to its pool
Throws:
JCO.Exception - thrown if a connection could not be removed from pool cleanly