Class ProtocolRouter

  • All Implemented Interfaces:
    Router

    public class ProtocolRouter
    extends java.lang.Object
    implements Router
    The ProtocolRouter is used when there are multiple services that can be used. Each service is selected based on the protocol sent in the initiating request. If a match cannot be made based on the request then a default service us chosen.
    See Also:
    RouterContainer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Service primary
      This is the default service chosen if there is no match.
      private java.util.Map<java.lang.String,​Service> registry
      This is the set of services that can be selected.
    • Constructor Summary

      Constructors 
      Constructor Description
      ProtocolRouter​(java.util.Map<java.lang.String,​Service> registry, Service primary)
      Constructor for the ProtocolRouter object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Service route​(Request request, Response response)
      This is used to route an incoming request to a service if the request represents a WebSocket handshake as defined by RFC 6455.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • registry

        private final java.util.Map<java.lang.String,​Service> registry
        This is the set of services that can be selected.
      • primary

        private final Service primary
        This is the default service chosen if there is no match.
    • Constructor Detail

      • ProtocolRouter

        public ProtocolRouter​(java.util.Map<java.lang.String,​Service> registry,
                              Service primary)
                       throws java.io.IOException
        Constructor for the ProtocolRouter object. This is used to create a router using a selection of services that can be selected using the Sec-WebSocket-Protocol header sent in the initiating request by the client.
        Parameters:
        registry - this is the registry of available services
        primary - this is the default service to use
        Throws:
        java.io.IOException
    • Method Detail

      • route

        public Service route​(Request request,
                             Response response)
        This is used to route an incoming request to a service if the request represents a WebSocket handshake as defined by RFC 6455. If the request is not a session initiating handshake then this will return a null value to allow it to be processed by some other part of the server.
        Specified by:
        route in interface Router
        Parameters:
        request - this is the request to use for routing
        response - this is the response to establish the session
        Returns:
        a service that can be used to process the session