Class SocketControllerBuilder
- java.lang.Object
-
- com.thecoderscorner.menu.remote.socket.SocketControllerBuilder
-
- All Implemented Interfaces:
ConnectorFactory
public class SocketControllerBuilder extends java.lang.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 Summary
Constructors Constructor Description SocketControllerBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanattemptPairing(java.util.Optional<java.util.function.Consumer<PairingHelper.PairingState>> maybePairingListener)RemoteMenuControllerbuild()Once the above methods have been called to fill in the blanks, then call build to get the actual instance.SocketControllerBuilderwithAddress(java.lang.String address)Mandatory, the address on which this socket is to bind to receive and send datagrams.SocketControllerBuilderwithClock(java.time.Clock clock)Optional, defaults to system clock but can be overridenSocketControllerBuilderwithExecutor(java.util.concurrent.ScheduledExecutorService executor)Optional, defaults to creating a suitable executor for single connectivitySocketControllerBuilderwithLocalName(java.lang.String name)Mandatory, Set the name of this connectionSocketControllerBuilderwithMenuTree(MenuTree tree)Mandatory, the menuTree instance to store the menu items retrieved from the remote side.SocketControllerBuilderwithPort(int port)Mandatory, the port locally on which to bind for multicast packets.SocketControllerBuilderwithProtocol(MenuCommandProtocol protocol)Optional, defaults to the standard protocol.SocketControllerBuilderwithUUID(java.util.UUID uuid)Mandatory, Set the UUID of this instance of the client
-
-
-
Method Detail
-
withClock
public SocketControllerBuilder withClock(java.time.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(java.util.concurrent.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(java.lang.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(java.util.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(java.lang.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:
-
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:
buildin interfaceConnectorFactory- Returns:
- the actual instance.
-
attemptPairing
public boolean attemptPairing(java.util.Optional<java.util.function.Consumer<PairingHelper.PairingState>> maybePairingListener)
- Specified by:
attemptPairingin interfaceConnectorFactory
-
-