Class MultiEndpointPoolSample
java.lang.Object
org.glassfish.grizzly.samples.connectionpool.MultiEndpointPoolSample
- All Implemented Interfaces:
ClientCallback
The sample to demonstrate how Grizzly client-side connection pool could be
used in multi-threaded application in asynchronous/non-blocking fashion.
To simulate real-world usecase we initialize 2 TCP-based echo servers,
listening on two different TCP ports. On the client-side we initialize
MultiEndpointPool, which caches TCP Connections to the
servers.
To test the connection pool - we run 100000 requests simultaneously
using custom ExecutorService (we randomly chose the
target server for each request). After we got responses from the
servers - we print out statistics: number of requests sent
(expected value is 100000), number of responses missed (expected value is 0),
the total number of client-side Connections been established
(expected value is <= 4).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexec()static voidvoidonConnectionEstablished(org.glassfish.grizzly.Connection connection) The callback operation will be executed once new client-sideConnectionis established.voidonResponseReceived(org.glassfish.grizzly.Connection connection, String responseMessage) The callback operation will be executed once a clientConnectionreceives response from a server.
-
Constructor Details
-
MultiEndpointPoolSample
public MultiEndpointPoolSample()
-
-
Method Details
-
main
- Throws:
Exception
-
exec
- Throws:
Exception
-
onConnectionEstablished
public void onConnectionEstablished(org.glassfish.grizzly.Connection connection) The callback operation will be executed once new client-sideConnectionis established.- Specified by:
onConnectionEstablishedin interfaceClientCallback- Parameters:
connection- the newConnection
-
onResponseReceived
The callback operation will be executed once a clientConnectionreceives response from a server.- Specified by:
onResponseReceivedin interfaceClientCallback- Parameters:
connection- the client-sideConnectionresponseMessage- the response
-