public class SocketConnection extends Object implements SocketHandler
SocketHandler
using a standard socket.Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected Daemon |
daemon |
protected DaemonContext |
daemonContext |
protected SelectionKey |
key |
protected SocketAddress |
localAddr |
protected int |
localPort |
protected ProtocolEngine |
protocolEngine |
protected SocketAddress |
remoteAddr |
protected int |
remotePort |
protected SelectorThread |
selectorThread |
protected SocketChannel |
socketChannel |
protected ByteBuffer |
socketDataIn |
protected ByteBuffer |
socketDataOut |
Constructor and Description |
---|
SocketConnection()
Construct the socket.
|
Modifier and Type | Method and Description |
---|---|
void |
closeConnection()
Close this socket connection.
|
DaemonContext |
getDaemonContext()
Get the daemon process for this socket.
|
IdleStateManager |
getIdleStates()
Get the idle state manager.
|
int |
getInterestedOps()
Get the initial interested ops for this socket.
|
SocketAddress |
getLocalAddress()
Returns the local address to which the remote socket is connected.
|
int |
getLocalPort()
Returns the local port to which the remote socket is connected.
|
int |
getPort()
Returns the local port to which the remote socket is connected.
|
ProtocolEngine |
getProtocolEngine()
Get the protocol engine for this socket.
|
SocketAddress |
getRemoteAddress()
Returns the address of the remote socket.
|
SocketChannel |
getSocketChannel()
Get the SocketChannel for this socket.
|
SelectorThread |
getThread()
Get the selector thread for this connection
|
String |
getUuid() |
void |
initialize(ProtocolEngine protocolEngine,
Daemon daemon,
SelectableChannel sc,
SelectorThread selectorThread)
Initialize the socket with the protocol engine and the daemon process.
|
protected boolean |
isConnected()
Is the socket still connected?
|
protected boolean |
isDeferredConnectEvent() |
boolean |
isSelectorThread()
Is the current thread this sockets
SelectorThread ? |
boolean |
processReadEvent()
The selector is ready to be read.
|
boolean |
processWriteEvent()
The selector is ready to be written to.
|
void |
registrationCompleted(SelectableChannel channel,
SelectionKey key)
The sockets channel has completed registration.
|
void |
setSelectionKey(SelectionKey key) |
void |
setThread(SelectorThread thread)
Set the selector thread for this connection
|
void |
setWriteState(boolean wantsWrite)
Sets the write state of the socket.
|
protected SocketChannel socketChannel
protected ProtocolEngine protocolEngine
protected DaemonContext daemonContext
protected SelectorThread selectorThread
protected SelectionKey key
protected Daemon daemon
protected ByteBuffer socketDataIn
protected ByteBuffer socketDataOut
protected boolean closed
protected SocketAddress remoteAddr
protected SocketAddress localAddr
protected int localPort
protected int remotePort
public String getUuid()
getUuid
in interface SocketHandler
public void initialize(ProtocolEngine protocolEngine, Daemon daemon, SelectableChannel sc, SelectorThread selectorThread)
initialize
in interface SocketHandler
protocolEngine
- ProtocolEnginedaemon
- Daemonprotected boolean isDeferredConnectEvent()
public void registrationCompleted(SelectableChannel channel, SelectionKey key)
registrationCompleted
in interface SelectorRegistrationListener
channel
- SelectableChannelkey
- SelectionKeyselectorThread
- SelectorThreadpublic void setSelectionKey(SelectionKey key)
setSelectionKey
in interface SelectionKeyAware
public void closeConnection()
public ProtocolEngine getProtocolEngine()
public DaemonContext getDaemonContext()
public SocketAddress getLocalAddress()
public int getLocalPort()
public int getPort()
public SocketAddress getRemoteAddress()
public SocketChannel getSocketChannel()
public IdleStateManager getIdleStates()
public boolean isSelectorThread()
SelectorThread
?public void setWriteState(boolean wantsWrite)
wantsWrite
- booleanprotected boolean isConnected()
public SelectorThread getThread()
public int getInterestedOps()
getInterestedOps
in interface SocketHandler
public boolean processReadEvent()
processReadEvent
in interface SocketHandler
public boolean processWriteEvent()
processWriteEvent
in interface SocketHandler
public void setThread(SelectorThread thread)
setThread
in interface SocketHandler
thread
- SelectorThreadCopyright © 2024. All rights reserved.