Class SocketControllerBuilder
- java.lang.Object
-
- com.thecoderscorner.menu.remote.socket.SocketControllerBuilder
-
public class SocketControllerBuilder extends java.lang.ObjectCreates 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") .build(); controller.start();
-
-
Constructor Summary
Constructors Constructor Description SocketControllerBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 connectivitySocketControllerBuilderwithHeartbeatFrequency(int frequency)Optional, defaults to 10 seconds between heartbeats.SocketControllerBuilderwithLocalName(java.lang.String name)Optional, Set the name of this connection, defaults to NoNameSocketControllerBuilderwithMenuTree(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.
-
-
-
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.
-
withHeartbeatFrequency
public SocketControllerBuilder withHeartbeatFrequency(int frequency)
Optional, defaults to 10 seconds between heartbeats. This must be the same at both sides.- Parameters:
frequency- the frequency, must align with remote device.- 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)
Optional, Set the name of this connection, defaults to NoName- Parameters:
name- the name the remote will see.- 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() throws java.io.IOException
Once the above methods have been called to fill in the blanks, then call build to get the actual instance.- Returns:
- the actual instance.
- Throws:
java.io.IOException
-
-