Class MultiEndpointPoolSample

java.lang.Object
org.glassfish.grizzly.samples.connectionpool.MultiEndpointPoolSample
All Implemented Interfaces:
ClientCallback

public class MultiEndpointPoolSample extends Object implements 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 Details

    • MultiEndpointPoolSample

      public MultiEndpointPoolSample()
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception
    • exec

      public void exec() throws Exception
      Throws:
      Exception
    • onConnectionEstablished

      public void onConnectionEstablished(org.glassfish.grizzly.Connection connection)
      The callback operation will be executed once new client-side Connection is established.
      Specified by:
      onConnectionEstablished in interface ClientCallback
      Parameters:
      connection - the new Connection
    • onResponseReceived

      public void onResponseReceived(org.glassfish.grizzly.Connection connection, String responseMessage)
      The callback operation will be executed once a client Connection receives response from a server.
      Specified by:
      onResponseReceived in interface ClientCallback
      Parameters:
      connection - the client-side Connection
      responseMessage - the response