Package com.sshtools.synergy.nio
Class SocketConnection
java.lang.Object
com.sshtools.synergy.nio.SocketConnection
- All Implemented Interfaces:
SelectionKeyAware,SelectorRegistrationListener,SocketHandler
- Direct Known Subclasses:
SSLContextConnection,SSLSocketConnection
This class implements a
SocketHandler using a standard socket.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected SshEngineprotected SshEngineContextprotected SelectionKeyprotected ProtocolEngineprotected SelectorThreadprotected SocketChannelprotected ByteBufferprotected ByteBuffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTask(ConnectionAwareTask task) Add a task to the executorvoidClose this socket connection.voidcloseConnection(boolean closeProtocol) voidConnection<? extends SshContext>Get the Connection for this handlerGet the current contextGet the daemon process for this socket.Get the idle state manager.intGet the initial interested ops for this socket.Returns the local address to which the remote socket is connected.intReturns the local port to which the remote socket is connected.getName()A name for this SocketintgetPort()Returns the local port to which the remote socket is connected.Get the protocol engine for this socket.Returns the address of the remote socket.Get the selector thread this handler is connected to.Get the SocketChannel for this socket.Get the selector thread for this connectionvoidinitialize(ProtocolEngine protocolEngine, SshEngine daemon, SelectableChannel channel) Initialize the socket with the protocol engine and the daemon process.protected booleanIs the socket still connected?booleanIs the current thread this socketsSelectorThread?booleanThe selector is ready to be read.booleanThe selector is ready to be written to.voidregistrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) The sockets channel has completed registration.voidsetProtocolEngine(ProtocolEngine protocolEngine) Set a new ProtocolEngine to handle this sockets data.voidvoidsetThread(SelectorThread thread) Set the selector thread for this connectionbooleanTell the selector that the handler wants to read.booleanTell the selector that the handler wants to write.
-
Field Details
-
socketChannel
-
protocolEngine
-
daemonContext
-
selectorThread
-
key
-
daemon
-
socketDataIn
-
socketDataOut
-
closed
protected boolean closed
-
-
Constructor Details
-
SocketConnection
public SocketConnection()Construct the socket.
-
-
Method Details
-
initialize
public void initialize(ProtocolEngine protocolEngine, SshEngine daemon, SelectableChannel channel) throws IOException Initialize the socket with the protocol engine and the daemon process.- Specified by:
initializein interfaceSocketHandler- Parameters:
protocolEngine- ProtocolEnginedaemon- Daemon- Throws:
IOException
-
registrationCompleted
public void registrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) throws IOException The sockets channel has completed registration.- Specified by:
registrationCompletedin interfaceSelectorRegistrationListener- Parameters:
channel- SelectableChannelkey- SelectionKeyselectorThread- SelectorThread- Throws:
IOException
-
setSelectionKey
- Specified by:
setSelectionKeyin interfaceSelectionKeyAware
-
setProtocolEngine
Set a new ProtocolEngine to handle this sockets data.- Parameters:
protocolEngine-
-
closeConnection
public void closeConnection()Close this socket connection. -
closeConnection
public void closeConnection(boolean closeProtocol) -
getProtocolEngine
Get the protocol engine for this socket.- Returns:
- ProtocolEngine
-
getDaemonContext
Get the daemon process for this socket.- Returns:
- DaemonContext
-
getLocalAddress
Returns the local address to which the remote socket is connected.- Returns:
-
getLocalPort
public int getLocalPort()Returns the local port to which the remote socket is connected.- Returns:
-
getPort
public int getPort()Returns the local port to which the remote socket is connected.- Returns:
-
getRemoteAddress
Returns the address of the remote socket.- Returns:
-
getSocketChannel
Get the SocketChannel for this socket.- Returns:
- SocketChannel
-
getIdleStates
Get the idle state manager.- Returns:
- IdleStateManager
-
isSelectorThread
public boolean isSelectorThread()Is the current thread this socketsSelectorThread?- Returns:
- boolean
-
isConnected
protected boolean isConnected()Is the socket still connected?- Returns:
- boolean
-
getThread
Get the selector thread for this connection- Returns:
- SelectorThread
-
getInitialOps
public int getInitialOps()Get the initial interested ops for this socket.- Specified by:
getInitialOpsin interfaceSocketHandler- Returns:
- int
-
processReadEvent
public boolean processReadEvent()The selector is ready to be read.- Specified by:
processReadEventin interfaceSocketHandler- Returns:
- boolean
-
processWriteEvent
public boolean processWriteEvent()The selector is ready to be written to.- Specified by:
processWriteEventin interfaceSocketHandler- Returns:
- boolean
-
setThread
Set the selector thread for this connection- Specified by:
setThreadin interfaceSocketHandler- Parameters:
thread- SelectorThread
-
addTask
Description copied from interface:SocketHandlerAdd a task to the executor- Specified by:
addTaskin interfaceSocketHandler
-
wantsWrite
public boolean wantsWrite()Description copied from interface:SocketHandlerTell the selector that the handler wants to write.- Specified by:
wantsWritein interfaceSocketHandler- Returns:
-
getSelectorThread
Description copied from interface:SocketHandlerGet the selector thread this handler is connected to.- Specified by:
getSelectorThreadin interfaceSocketHandler- Returns:
-
flagWrite
public void flagWrite() -
getName
Description copied from interface:SocketHandlerA name for this Socket- Specified by:
getNamein interfaceSocketHandler- Returns:
-
getContext
Description copied from interface:SocketHandlerGet the current context- Specified by:
getContextin interfaceSocketHandler- Returns:
-
getConnection
Description copied from interface:SocketHandlerGet the Connection for this handler- Specified by:
getConnectionin interfaceSocketHandler- Returns:
-
wantsRead
public boolean wantsRead()Description copied from interface:SocketHandlerTell the selector that the handler wants to read.- Specified by:
wantsReadin interfaceSocketHandler- Returns:
-