Package com.thecoderscorner.menu.remote
Class StreamRemoteConnector
java.lang.Object
com.thecoderscorner.menu.remote.StreamRemoteConnector
- All Implemented Interfaces:
RemoteConnector,RemoteConnectorContext
- Direct Known Subclasses:
SocketBasedConnector
public abstract class StreamRemoteConnector
extends Object
implements RemoteConnector, RemoteConnectorContext
Stream remote connector is the base class for all stream implementations, such as Socket and RS232. Any remote
with stream like semantics can use this as the base for building out an adapter.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Clockprotected ScheduledExecutorServiceprotected System.Loggerprotected Map<AuthStatus,Class<? extends RemoteConnectorState>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStreamRemoteConnector(LocalIdentifier ourLocalId, MenuCommandProtocol protocol, ScheduledExecutorService executor, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeState(AuthStatus desiredState)voidchangeState(RemoteConnectorState newState)voidclose()Force close a connection when its known to be bad, the connector will try and establish a new connection.protected voidprotected voidconnectionLog(System.Logger.Level l, String s, Throwable e)static booleandoesBufferHaveEOM(ByteBuffer inputBuffer)protected abstract voidgetAtLeastBytes(ByteBuffer inputBuffer, int len, StreamRemoteConnector.ReadMode mode)Reads at least the number of bytes requested waiting if need be for more data.getClock()protected voidhandleCoreConnectionStates(ConnectMode connectMode)protected voidlogByteBuffer(String msg, ByteBuffer inBuffer)Helper method that logs the entire message buffer when at debug logging level.protected voidHelper method that notifies all connection listeners of a change in connectivityvoidHelper method that notifies all listeners of a new command messageprotected voidreadCompleteMessage(ByteBuffer inputBuffer)voidRegister for connection change events, when there is a change in connectivity status on the underlying transport.voidregisterConnectorListener(RemoteConnectorListener listener)Register for connector messages, when new messages are received from this stream.voidsendAcknowledgement(AckStatus ackStatus)voidsendHeartbeat(int frequency, MenuHeartbeatCommand.HeartbeatMode mode)protected abstract voidsendInternal(ByteBuffer outputBuffer)performs a send of all bytes in the output buffer until the output buffer is emptyvoidsendJoin()voidsendMenuCommand(MenuCommand msg)Sends a command to the remote with the protocol and usual headers.voidvoidsetRemoteParty(RemoteInformation remote)protected voidprotected voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.thecoderscorner.menu.remote.RemoteConnector
getConnectionName, isDeviceConnected, start, stopMethods inherited from interface com.thecoderscorner.menu.remote.states.RemoteConnectorContext
getConnectionName, isDeviceConnected, performConnection
-
Field Details
-
logger
-
executor
-
clock
-
stateMachineMappings
-
-
Constructor Details
-
Method Details
-
readCommandFromStream
- Specified by:
readCommandFromStreamin interfaceRemoteConnectorContext- Throws:
IOException
-
stopThreadProc
protected void stopThreadProc() -
startThreadProc
protected void startThreadProc() -
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
-
sendInternal
performs a send of all bytes in the output buffer until the output buffer is empty- Parameters:
outputBuffer- the buffer data to be sent- Throws:
IOException- if there are problems writing
-
readCompleteMessage
- Throws:
IOException
-
notifyConnection
protected void notifyConnection()Helper method that notifies all connection listeners of a change in connectivity -
logByteBuffer
Helper method that logs the entire message buffer when at debug logging level.- Parameters:
msg- the message to print firstinBuffer- the buffer to be logged
-
doesBufferHaveEOM
-
getRemoteParty
- Specified by:
getRemotePartyin interfaceRemoteConnector- Returns:
- the remote party information of the current connection
-
getAuthenticationStatus
- Specified by:
getAuthenticationStatusin interfaceRemoteConnector- Returns:
- the status of the connection and authentication.
-
sendJoin
- Specified by:
sendJoinin interfaceRemoteConnectorContext- Throws:
IOException
-
sendPairing
- Specified by:
sendPairingin interfaceRemoteConnectorContext- Throws:
IOException
-
getScheduledExecutor
- Specified by:
getScheduledExecutorin interfaceRemoteConnectorContext
-
getClock
- Specified by:
getClockin interfaceRemoteConnectorContext
-
connectionLog
-
connectionLog
-