Package org.apache.vinci.transport
Class PooledVinciClient
java.lang.Object
org.apache.vinci.transport.PooledVinciClient
Maintains a pool of connections to a given service and allows thread-safe querying of that
service. This provides a set of sendAndReceive methods with signatures equivalent to those in
VinciClient, but unlike VinciClient, the methods can be invoked concurrently by multiple threads.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate VinciClient[]
private int
(package private) boolean
(package private) int
private VinciContext
private TransportableFactory
private int
private String
(package private) int
-
Constructor Summary
ConstructorsConstructorDescriptionPooledVinciClient
(String serviceName, int maxPoolSize) Create a PooledVinciClient that will establish at most maxPoolSize connections to the designated service. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(boolean wait) Close this pooled client.private VinciClient
Retrieve a client from the pool, blocking for at most "socketTimeout" seconds.Get the service name to which this client connects.private void
Release a client that has been obtained from getClientFromPool.Send a request to the service and receive the response.sendAndReceive
(Transportable in, int socketTimeout) Send a request to the service and receive the response, using the provided socketTimeout in place of the client-provided one.Send a request to the service and receive the response, using the provided transportable factory in place of the client-provided one.sendAndReceive
(Transportable in, TransportableFactory f, int socketTimeout) Send a request to the service and receive the response, using the provided transportable factory and socketTimeout in place of the client-provided ones.void
setConnectTimeout
(int connectTimeoutMillis) Set a connect timeout that will be used in place of BaseClient.DEFAULT_CONNECT_TIMEOUTvoid
setContext
(VinciContext context) Set a VinciContext that will be used by this PooledVinciClient instead of the default global context.void
setSocketTimeout
(int socketTimeoutMillis) Set a socket timeout that will be used in place of BaseClient.DEFAULT_SOCKET_TIMEOUTvoid
Set a transportable factory that will be used in place of the VinciFrame factory.
-
Field Details
-
context
-
factory
-
connectTimeout
int connectTimeout -
socketTimeout
int socketTimeout -
serviceName
-
maxPoolSize
private int maxPoolSize -
availableClients
-
availableClientsStartIndex
private int availableClientsStartIndex -
closed
boolean closed
-
-
Constructor Details
-
PooledVinciClient
Create a PooledVinciClient that will establish at most maxPoolSize connections to the designated service.
-
-
Method Details
-
setContext
Set a VinciContext that will be used by this PooledVinciClient instead of the default global context. -
setConnectTimeout
public void setConnectTimeout(int connectTimeoutMillis) Set a connect timeout that will be used in place of BaseClient.DEFAULT_CONNECT_TIMEOUT -
setSocketTimeout
public void setSocketTimeout(int socketTimeoutMillis) Set a socket timeout that will be used in place of BaseClient.DEFAULT_SOCKET_TIMEOUT -
setTransportableFactory
Set a transportable factory that will be used in place of the VinciFrame factory. -
getServiceName
Get the service name to which this client connects. -
sendAndReceive
Send a request to the service and receive the response. This method is tread safe.- Throws:
IOException
ServiceException
-
sendAndReceive
public Transportable sendAndReceive(Transportable in, TransportableFactory f) throws IOException, ServiceException Send a request to the service and receive the response, using the provided transportable factory in place of the client-provided one. This method is tread safe.- Throws:
IOException
ServiceException
-
sendAndReceive
public Transportable sendAndReceive(Transportable in, TransportableFactory f, int socketTimeout) throws IOException, ServiceException Send a request to the service and receive the response, using the provided transportable factory and socketTimeout in place of the client-provided ones. This method is tread safe.- Throws:
IOException
ServiceException
-
sendAndReceive
public Transportable sendAndReceive(Transportable in, int socketTimeout) throws IOException, ServiceException Send a request to the service and receive the response, using the provided socketTimeout in place of the client-provided one. This method is tread safe.- Throws:
IOException
ServiceException
-
close
public void close(boolean wait) Close this pooled client. Blocked requests will return IOException, as will any requests following the invocation of this method. Once a pooled client is closed it cannot be reused.- Parameters:
wait
- If true, this method will block until all in-progress requests have completed, otherwise this method will return immediately (though in progress requests will still be allowed to complete)
-
getClientFromPool
Retrieve a client from the pool, blocking for at most "socketTimeout" seconds. If the wait block time is exceeded, an IOException will be thrown. Connections obtained by this method *must* be released by calling releaseClient().- Throws:
IOException
- if the wait() time before a connectoin becomes available exceeds the socketTimeout value, or if thrown by a failed service connection attempt.
-
releaseClient
Release a client that has been obtained from getClientFromPool.
-