org.clazzes.remoting.client
Class ClientPool

java.lang.Object
  extended by org.clazzes.remoting.client.ClientPool
All Implemented Interfaces:
javax.security.auth.Destroyable, ClientManager

public class ClientPool
extends java.lang.Object
implements Destroyable, ClientManager

A thread-safe pool of clients.

Author:
wglas

Constructor Summary
ClientPool()
          Construct a client pool with the default parameters minPoolSize4 maxPoolSize8 idleTimeout60000 fetchTimeout30000 soTimeout60000 tcpNoDelaytrue
 
Method Summary
 Client activateClient()
           
 void destroy()
          Cleanup internal resources.
 java.util.Map<java.lang.String,OneWayHandler> getBroadcastHandlers()
           
 ClientParameters getClientParameters()
           
 java.net.URI getConnectURI()
           
 java.util.concurrent.ExecutorService getExecutorService()
           
 long getFetchTimeout()
           
 long getIdleTimeout()
           
 int getMaxPoolSize()
           
 int getMinPoolSize()
           
 boolean isDestroyed()
           
 boolean isLoadRemoteClasses()
           
 void passivateClient(Client client)
           
 void setBroadcastHandlers(java.util.Map<java.lang.String,OneWayHandler> broadcastHandlers)
           
 void setClientParameters(ClientParameters clientParameters)
           
 void setConnectURI(java.net.URI connectURI)
           
 void setExecutorService(java.util.concurrent.ExecutorService executorService)
           
 void setFetchTimeout(long fetchTimeout)
           
 void setIdleTimeout(long idleTimeout)
           
 void setLoadRemoteClasses(boolean loadRemoteClasses)
           
 void setMaxPoolSize(int maxPoolSize)
           
 void setMinPoolSize(int minPoolSize)
           
 void start()
          Start the client pool after setting a relevant properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientPool

public ClientPool()
Construct a client pool with the default parameters
minPoolSize4
maxPoolSize8
idleTimeout60000
fetchTimeout30000
soTimeout60000
tcpNoDelaytrue

Method Detail

getClientParameters

public ClientParameters getClientParameters()
Returns:
The client configuration object. If not set via setClientParameters(ClientParameters), a new instance of the base class ClientParameters is returned.

setClientParameters

public void setClientParameters(ClientParameters clientParameters)
Parameters:
clientParameters - The client parameters to set.

getExecutorService

public java.util.concurrent.ExecutorService getExecutorService()
Returns:
The executor service used to execute the asynchronous reader process. If no set via setExecutorService(ExecutorService), the result of Executors.newCachedThreadPool() is returned.

setExecutorService

public void setExecutorService(java.util.concurrent.ExecutorService executorService)
Parameters:
executorService - The executor service used to execute the asynchronous reader process.

isDestroyed

public boolean isDestroyed()
Specified by:
isDestroyed in interface javax.security.auth.Destroyable

destroy

public void destroy()
Description copied from interface: Destroyable
Cleanup internal resources. An implementation must be safe to be called twice. Any error should be logged rather than thrown as exceptions. If this bean implements Initializable too, the general contract is, that after calling this method, Initializable.isInitialized() returns false.

Specified by:
destroy in interface javax.security.auth.Destroyable

start

public void start()
           throws java.io.IOException
Description copied from interface: ClientManager
Start the client pool after setting a relevant properties.

Specified by:
start in interface ClientManager
Throws:
java.io.IOException - Upon connection errors.

activateClient

public Client activateClient()
                      throws java.util.concurrent.TimeoutException
Specified by:
activateClient in interface ClientManager
Returns:
A client pulled from the pool.
Throws:
java.util.concurrent.TimeoutException - Upon connection errors or when the pool has no more clients available within a given timeout.

passivateClient

public void passivateClient(Client client)
Specified by:
passivateClient in interface ClientManager
Parameters:
client - A client which previously has been pulled from the pool using ClientManager.activateClient() and may now be used by other consumers.

getMinPoolSize

public int getMinPoolSize()
Returns:
the minimal size of the client pool. The default value is 4.

setMinPoolSize

public void setMinPoolSize(int minPoolSize)
Parameters:
minPoolSize - the minimal size of the client pool to set.

getMaxPoolSize

public int getMaxPoolSize()
Returns:
the maximal size of the client pool. The default value is 8.

setMaxPoolSize

public void setMaxPoolSize(int maxPoolSize)
Parameters:
maxPoolSize - the maximal size of the client pool to set.

getIdleTimeout

public long getIdleTimeout()
Returns:
The timeout in milliseconds after which idle clients are disposed. The default value is 60000.

setIdleTimeout

public void setIdleTimeout(long idleTimeout)
Parameters:
idleTimeout - the idleTimeout to set

getConnectURI

public java.net.URI getConnectURI()
Returns:
The URI to which the generated clients will connect.

setConnectURI

public void setConnectURI(java.net.URI connectURI)
Parameters:
connectURI - The connect URI to set.

isLoadRemoteClasses

public boolean isLoadRemoteClasses()
Returns:
Whether to load classes from the remote server on demand.

setLoadRemoteClasses

public void setLoadRemoteClasses(boolean loadRemoteClasses)
Parameters:
loadRemoteClasses - Whether to load classes from the remote server on demand.

getFetchTimeout

public long getFetchTimeout()
Returns:
the maximal time in milliseconds to wait until a client becomes available. The default value is 3000.

setFetchTimeout

public void setFetchTimeout(long fetchTimeout)
Parameters:
fetchTimeout - the fetchTimeout to set

getBroadcastHandlers

public java.util.Map<java.lang.String,OneWayHandler> getBroadcastHandlers()
Returns:
The broadcast handlers, which will be registered at generated clients.

setBroadcastHandlers

public void setBroadcastHandlers(java.util.Map<java.lang.String,OneWayHandler> broadcastHandlers)
Parameters:
broadcastHandlers - The broadcast handlers to set.


Copyright © 2010. All Rights Reserved.