Class ResponseServer

java.lang.Object
io.aeron.response.ResponseServer
All Implemented Interfaces:
AutoCloseable, Agent

public class ResponseServer extends Object implements AutoCloseable, Agent
A basic sample response server that allows the users to specify a simple function to represent the handling of a request and then return a response. This approach will be effective when request processing is very short. For certain types of response servers, e.g. returning a large volume of data from a database, this pattern will be ineffective. For those types of use cases, something more complex, likely involving thread pooling would be required.
  • Constructor Details

    • ResponseServer

      public ResponseServer(Aeron aeron, Function<Image,ResponseServer.ResponseHandler> handlerFactory, String requestEndpoint, int requestStreamId, String responseControl, int responseStreamId, String requestChannel, String responseChannel)
      Constructs the server.
      Parameters:
      aeron - connected Aeron client.
      handlerFactory - factor to produce handler instances for each incoming session.
      requestEndpoint - channel to listen for requests and new connections.
      requestStreamId - streamId to listen for requests and new connections.
      responseControl - channel to send responses back on.
      responseStreamId - streamId to send responses back on.
      requestChannel - fragment to aid in configuration of the subscription (can be null)
      responseChannel - fragment to aid in configuration of the response publication (can be null)
  • Method Details

    • usePrototype

      public void usePrototype(boolean usePrototype)
      Indicate whether or not to create a prototype response publication.
      Parameters:
      usePrototype - true or false.
    • doWork

      public int doWork()
      Poll the server process messages and state.
      Specified by:
      doWork in interface Agent
      Returns:
      amount of work done.
    • sessionCount

      public int sessionCount()
      The number of connected clients.
      Returns:
      the number of connected clients.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • roleName

      public String roleName()
      Specified by:
      roleName in interface Agent