Class SocketControllerBuilder

java.lang.Object
com.thecoderscorner.menu.remote.socket.SocketControllerBuilder
All Implemented Interfaces:
ConnectorFactory

public class SocketControllerBuilder extends Object implements ConnectorFactory
Creates an instance of a socket based controller to a given port, and connects it with the selected menu. This implements the standard builder pattern, an example of use would be along the lines of:
     RemoteMenuController controller = new SocketControllerBuilder()
       .withAddress(hostName)
       .withPort(3333)
       .withMenuTree(myMenuTree)
       .withLocalName("My App")
       .withUUID(myUUID)
       .build();
     controller.start();
 
  • Constructor Details

    • SocketControllerBuilder

      public SocketControllerBuilder()
  • Method Details

    • withClock

      public SocketControllerBuilder withClock(Clock clock)
      Optional, defaults to system clock but can be overriden
      Parameters:
      clock - the clock to use
      Returns:
      itself, can be chained
    • withExecutor

      public SocketControllerBuilder withExecutor(ScheduledExecutorService executor)
      Optional, defaults to creating a suitable executor for single connectivity
      Parameters:
      executor - the executor which must implement ScheduledExecutorService
      Returns:
      itself, suitable for chaining.
    • withMenuTree

      public SocketControllerBuilder withMenuTree(MenuTree tree)
      Mandatory, the menuTree instance to store the menu items retrieved from the remote side. this menuTree must only be used with one remote.
      Parameters:
      tree - the menu tree to be populated (only use a menu tree with one remote)
      Returns:
      itself, suitable for chaining.
    • withProtocol

      public SocketControllerBuilder withProtocol(MenuCommandProtocol protocol)
      Optional, defaults to the standard protocol. Only use if changing the protocol which is not advised.
      Parameters:
      protocol - a protocol object.
      Returns:
      itself, suitable for chaining.
    • withLocalName

      public SocketControllerBuilder withLocalName(String name)
      Mandatory, Set the name of this connection
      Parameters:
      name - the name the remote will see.
      Returns:
      itself, suitable for chaining.
    • withUUID

      public SocketControllerBuilder withUUID(UUID uuid)
      Mandatory, Set the UUID of this instance of the client
      Parameters:
      uuid - the UUID for this instance of the App
      Returns:
      itself, suitable for chaining.
    • withAddress

      public SocketControllerBuilder withAddress(String address)
      Mandatory, the address on which this socket is to bind to receive and send datagrams.
      Parameters:
      address - address on which to send and receive.
      Returns:
      itself, suitable for chaining.
    • withPort

      public SocketControllerBuilder withPort(int port)
      Mandatory, the port locally on which to bind for multicast packets.
      Parameters:
      port - the bind port
      Returns:
      itself, suitable for chaining
    • build

      public RemoteMenuController build()
      Once the above methods have been called to fill in the blanks, then call build to get the actual instance.
      Specified by:
      build in interface ConnectorFactory
      Returns:
      the actual instance.
    • attemptPairing

      public boolean attemptPairing(Optional<Consumer<AuthStatus>> maybePairingListener)
      Description copied from interface: ConnectorFactory
      Attempt to pair with a remote optionally providing a listener that gets notified of status for updating a UI for example. It returns when pairing is complete.
      Specified by:
      attemptPairing in interface ConnectorFactory
      Parameters:
      maybePairingListener - an optional pairing listener to listen for status updates
      Returns:
      true if successful, otherwise false.