Class SocketBasedConnector
- java.lang.Object
-
- com.thecoderscorner.menu.remote.StreamRemoteConnector
-
- com.thecoderscorner.menu.remote.socket.SocketBasedConnector
-
- All Implemented Interfaces:
RemoteConnector,RemoteConnectorContext
public class SocketBasedConnector extends StreamRemoteConnector
A remote connector that will communicate using a client socket. Normally configured with a host and port. Create using the builder below.- See Also:
SocketControllerBuilder
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.thecoderscorner.menu.remote.StreamRemoteConnector
StreamRemoteConnector.ReadMode
-
-
Field Summary
-
Fields inherited from class com.thecoderscorner.menu.remote.StreamRemoteConnector
clock, executor, logger, stateMachineMappings
-
-
Constructor Summary
Constructors Constructor Description SocketBasedConnector(LocalIdentifier localId, java.util.concurrent.ScheduledExecutorService executor, java.time.Clock clock, MenuCommandProtocol protocol, java.lang.String remoteHost, int remotePort, ConnectMode mode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Force close a connection when its known to be bad, the connector will try and establish a new connection.protected voidgetAtLeastBytes(java.nio.ByteBuffer inputBuffer, int len, StreamRemoteConnector.ReadMode mode)Reads at least the number of bytes requested waiting if need be for more data.java.lang.StringgetConnectionName()Gets the name of this connector locallybooleanisDeviceConnected()Indicates if the underlying device is actually connected.voidperformConnection()protected voidsendInternal(java.nio.ByteBuffer outputBuffer)performs a send of all bytes in the output buffer until the output buffer is emptyvoidstart()Starts the communication channel, so it will attempt to connect with the configured devicevoidstop()Stops the library and attempts to also stop any threads and other resources associated.-
Methods inherited from class com.thecoderscorner.menu.remote.StreamRemoteConnector
changeState, changeState, doesBufferHaveEOM, getAuthenticationStatus, getClock, getRemoteParty, getScheduledExecutor, handleCoreConnectionStates, logByteBuffer, notifyConnection, notifyListeners, readCommandFromStream, readCompleteMessage, registerConnectionChangeListener, registerConnectorListener, sendAcknowledgement, sendHeartbeat, sendJoin, sendMenuCommand, sendPairing, setRemoteParty
-
-
-
-
Constructor Detail
-
SocketBasedConnector
public SocketBasedConnector(LocalIdentifier localId, java.util.concurrent.ScheduledExecutorService executor, java.time.Clock clock, MenuCommandProtocol protocol, java.lang.String remoteHost, int remotePort, ConnectMode mode)
-
-
Method Detail
-
start
public void start()
Description copied from interface:RemoteConnectorStarts the communication channel, so it will attempt to connect with the configured device
-
stop
public void stop()
Description copied from interface:RemoteConnectorStops the library and attempts to also stop any threads and other resources associated.
-
performConnection
public void performConnection() throws java.io.IOException- Throws:
java.io.IOException
-
getAtLeastBytes
protected void getAtLeastBytes(java.nio.ByteBuffer inputBuffer, int len, StreamRemoteConnector.ReadMode mode) throws java.io.IOExceptionDescription copied from class:StreamRemoteConnectorReads at least the number of bytes requested waiting if need be for more data.- Specified by:
getAtLeastBytesin classStreamRemoteConnector- Parameters:
inputBuffer- the buffer to read fromlen- the minimum number of bytes needed- Throws:
java.io.IOException- if there are problems reading.
-
sendInternal
protected void sendInternal(java.nio.ByteBuffer outputBuffer) throws java.io.IOExceptionDescription copied from class:StreamRemoteConnectorperforms a send of all bytes in the output buffer until the output buffer is empty- Specified by:
sendInternalin classStreamRemoteConnector- Parameters:
outputBuffer- the buffer data to be sent- Throws:
java.io.IOException- if there are problems writing
-
isDeviceConnected
public boolean isDeviceConnected()
Description copied from interface:RemoteConnectorIndicates if the underlying device is actually connected.- Returns:
- true if the underlying device is connected
-
getConnectionName
public java.lang.String getConnectionName()
Description copied from interface:RemoteConnectorGets the name of this connector locally
-
close
public void close()
Description copied from interface:RemoteConnectorForce close a connection when its known to be bad, the connector will try and establish a new connection.- Specified by:
closein interfaceRemoteConnector- Specified by:
closein interfaceRemoteConnectorContext- Overrides:
closein classStreamRemoteConnector
-
-