- java.lang.Object
-
- swim.io.SocketModem<I,O>
-
- All Implemented Interfaces:
ConnectionContext
,FlowContext
,ModemContext<I,O>
,Socket
public class SocketModem<I,O> extends Object implements Socket, ModemContext<I,O>
-
-
Field Summary
Fields Modifier and Type Field Description protected SocketContext
context
-
Constructor Summary
Constructors Constructor Description SocketModem(Modem<I,O> modem)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
become(Socket socket)
Rebinds the underlyingSocketContext
to a newsocket
implementation, thereby changing theSocket
handler that receives network I/O callbacks.String
cipherSuite()
Returns the cryptographic cipher suite used by the underlying network connection.void
close()
Closes the underlying network socket.void
didBecome(Socket socket)
Lifecycle callback invoked by the socket context after it hasbecome
a newsocket
implementation.void
didConnect()
Lifecycle callback invoked by the socket context after the underlying network socket has opened a connection.void
didDisconnect()
Lifecycle callback invoked by the socket context after the underlying network connection has disconnected.void
didFail(Throwable error)
Lifecycle callback invoked by the socket context when the underlying network socket fails by throwing anerror
.void
didSecure()
Lifecycle callback invoked by the socket context after the underlying network socket has established a secure connection.void
didTimeout()
Lifecycle callback invoked by the socket context after the underlying network connection has timed out.void
didWrite()
I/O callback invoked by the socket context after the underlying network socket has completed writing all data in itsoutputBuffer
.void
doRead()
I/O callback invoked by the socket context asking thisSocket
to read input data out of the socket context'sinputBuffer
.void
doWrite()
I/O callback invoked by the socket context asking thisSocket
to write output data into the socket context'soutputBuffer
.FlowControl
flowControl()
Returns the currentFlowControl
state of the underlying network channel.void
flowControl(FlowControl flowControl)
Enqueues an atomic replacement of the underlying network channel's flow control state with a newflowControl
.FlowControl
flowControl(FlowModifier flowModifier)
Enqueues an atomic modification to the underlying network channel's flow control state by applying aflowModifier
delta.long
idleTimeout()
Returns the number of idle milliseconds after which thisSocket
should be closed due to inactivity.boolean
isClient()
Returnstrue
if the underlying network channel initiated an outgoing connection.boolean
isConnected()
Returnstrue
if the underlying network channel is currently connected.boolean
isSecure()
Returnstrue
if the underlying network transport is encrypted.boolean
isServer()
Returnstrue
if the underlying network channel accepted an incoming connection.InetSocketAddress
localAddress()
Returns the IP address and port of the local endpoint of the underlying network connection.Collection<Certificate>
localCertificates()
Returns the certificate chain used to authenticate the local endpoint of the underlying network connection.Principal
localPrincipal()
Returns the authenticated identity of the local endpoint of the underlying network connection.<I2 extends I>
voidread(Decoder<I2> reader)
Enqueues a readdecoder
to which input data will be asynchronously fed.InetSocketAddress
remoteAddress()
Returns the IP address and port of the remote endpoint of the underlying network connection.Collection<Certificate>
remoteCertificates()
Returns the certificate chain used to authenticate the remote endpoint of the underlying network connection.Principal
remotePrincipal()
Returns the authenticated identity of the remote endpoint of the underlying network connection.String
securityProtocol()
Returns the name of the transport-layer security protocol used by the underlying network connection.void
setSocketContext(SocketContext context)
Sets the network socket context to which thisSocket
is bound.SocketContext
socketContext()
Returns the network socket context to which thisSocket
is bound; returnsnull
if thisSocket
is unbound.SocketSettings
socketSettings()
Returns the configuration parameters that govern the underlying network socket.void
willBecome(Socket socket)
Lifecycle callback invoked by the socket context before it hasbecome
a newsocket
implementation.void
willConnect()
Lifecycle callback invoked by the socket context before the underlying network socket attempts to open a connection.void
willSecure()
Lifecycle callback invoked by the socket context before the underlying network socket establishes a secure connection.<O2 extends O>
voidwrite(Encoder<?,O2> writer)
Enqueues a writeencoder
from which output data will be asynchronously pulled.
-
-
-
Field Detail
-
context
protected volatile SocketContext context
-
-
Method Detail
-
socketContext
public SocketContext socketContext()
Description copied from interface:Socket
Returns the network socket context to which thisSocket
is bound; returnsnull
if thisSocket
is unbound.- Specified by:
socketContext
in interfaceSocket
-
setSocketContext
public void setSocketContext(SocketContext context)
Description copied from interface:Socket
Sets the network socket context to which thisSocket
is bound.- Specified by:
setSocketContext
in interfaceSocket
-
isConnected
public boolean isConnected()
Description copied from interface:ConnectionContext
Returnstrue
if the underlying network channel is currently connected.- Specified by:
isConnected
in interfaceConnectionContext
-
isClient
public boolean isClient()
Description copied from interface:ConnectionContext
Returnstrue
if the underlying network channel initiated an outgoing connection.- Specified by:
isClient
in interfaceConnectionContext
-
isServer
public boolean isServer()
Description copied from interface:ConnectionContext
Returnstrue
if the underlying network channel accepted an incoming connection.- Specified by:
isServer
in interfaceConnectionContext
-
isSecure
public boolean isSecure()
Description copied from interface:ConnectionContext
Returnstrue
if the underlying network transport is encrypted.- Specified by:
isSecure
in interfaceConnectionContext
-
securityProtocol
public String securityProtocol()
Description copied from interface:ConnectionContext
Returns the name of the transport-layer security protocol used by the underlying network connection. Returnsnull
if the underlying network channel is not currently connected, or if the underlying network connection is not secure.- Specified by:
securityProtocol
in interfaceConnectionContext
-
cipherSuite
public String cipherSuite()
Description copied from interface:ConnectionContext
Returns the cryptographic cipher suite used by the underlying network connection. Returnsnull
if the underlying network channel is not currently connected, or if the underlying network connection is not secure.- Specified by:
cipherSuite
in interfaceConnectionContext
-
localAddress
public InetSocketAddress localAddress()
Description copied from interface:ConnectionContext
Returns the IP address and port of the local endpoint of the underlying network connection. Returnsnull
if the underlying network channel is not currently connected.- Specified by:
localAddress
in interfaceConnectionContext
-
localPrincipal
public Principal localPrincipal()
Description copied from interface:ConnectionContext
Returns the authenticated identity of the local endpoint of the underlying network connection. Returnsnull
if the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
localPrincipal
in interfaceConnectionContext
-
localCertificates
public Collection<Certificate> localCertificates()
Description copied from interface:ConnectionContext
Returns the certificate chain used to authenticate the local endpoint of the underlying network connection. Returnsnull
if the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
localCertificates
in interfaceConnectionContext
-
remoteAddress
public InetSocketAddress remoteAddress()
Description copied from interface:ConnectionContext
Returns the IP address and port of the remote endpoint of the underlying network connection. Returnsnull
if the underlying network channel is not currently connected.- Specified by:
remoteAddress
in interfaceConnectionContext
-
remotePrincipal
public Principal remotePrincipal()
Description copied from interface:ConnectionContext
Returns the authenticated identity of the remote endpoint of the underlying network connection. Returnsnull
if the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
remotePrincipal
in interfaceConnectionContext
-
remoteCertificates
public Collection<Certificate> remoteCertificates()
Description copied from interface:ConnectionContext
Returns the certificate chain used to authenticate the remote endpoint of the underlying network connection. Returnsnull
if the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
remoteCertificates
in interfaceConnectionContext
-
socketSettings
public SocketSettings socketSettings()
Description copied from interface:ModemContext
Returns the configuration parameters that govern the underlying network socket.- Specified by:
socketSettings
in interfaceModemContext<I,O>
-
read
public <I2 extends I> void read(Decoder<I2> reader)
Description copied from interface:ModemContext
Enqueues a readdecoder
to which input data will be asynchronously fed. The read flow control of the underlying network socket is automatically managed using the state of the readdecoder
. When the readdecoder
transitions into the done state, thedidRead
callback of the boundModem
will be invoked with the decoded result. If the readdecoder
transitions into the error state, then thedidFail
callback of the boundModem
will be invoked with the decode error.- Specified by:
read
in interfaceModemContext<I,O>
-
write
public <O2 extends O> void write(Encoder<?,O2> writer)
Description copied from interface:ModemContext
Enqueues a writeencoder
from which output data will be asynchronously pulled. The write flow control of the underlying network socket is automatically managed using the state of the writeencoder
. When the writeencoder
transitions into the done state, thedidWrite
callback of the boundModem
will be invoked with the encoded result. If the writeencoder
transitions into the error state, then thedidFail
callback of the boundModem
will be invoked with the encode error.- Specified by:
write
in interfaceModemContext<I,O>
-
idleTimeout
public long idleTimeout()
Description copied from interface:Socket
Returns the number of idle milliseconds after which thisSocket
should be closed due to inactivity. Returns-1
if a default idle timeout should be used. Returns0
if the underlying network socket should not time out.- Specified by:
idleTimeout
in interfaceSocket
-
doRead
public void doRead()
Description copied from interface:Socket
I/O callback invoked by the socket context asking thisSocket
to read input data out of the socket context'sinputBuffer
. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoRead
calls.
-
doWrite
public void doWrite()
Description copied from interface:Socket
I/O callback invoked by the socket context asking thisSocket
to write output data into the socket context'soutputBuffer
. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoWrite
ordidWrite
calls.
-
didWrite
public void didWrite()
Description copied from interface:Socket
I/O callback invoked by the socket context after the underlying network socket has completed writing all data in itsoutputBuffer
. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoWrite
ordidWrite
calls.
-
willConnect
public void willConnect()
Description copied from interface:Socket
Lifecycle callback invoked by the socket context before the underlying network socket attempts to open a connection.- Specified by:
willConnect
in interfaceSocket
-
didConnect
public void didConnect()
Description copied from interface:Socket
Lifecycle callback invoked by the socket context after the underlying network socket has opened a connection.- Specified by:
didConnect
in interfaceSocket
-
willSecure
public void willSecure()
Description copied from interface:Socket
Lifecycle callback invoked by the socket context before the underlying network socket establishes a secure connection.- Specified by:
willSecure
in interfaceSocket
-
didSecure
public void didSecure()
Description copied from interface:Socket
Lifecycle callback invoked by the socket context after the underlying network socket has established a secure connection.
-
willBecome
public void willBecome(Socket socket)
Description copied from interface:Socket
Lifecycle callback invoked by the socket context before it hasbecome
a newsocket
implementation.- Specified by:
willBecome
in interfaceSocket
-
didBecome
public void didBecome(Socket socket)
Description copied from interface:Socket
Lifecycle callback invoked by the socket context after it hasbecome
a newsocket
implementation.
-
didTimeout
public void didTimeout()
Description copied from interface:Socket
Lifecycle callback invoked by the socket context after the underlying network connection has timed out. The socket will automatically be closed.- Specified by:
didTimeout
in interfaceSocket
-
didDisconnect
public void didDisconnect()
Description copied from interface:Socket
Lifecycle callback invoked by the socket context after the underlying network connection has disconnected.- Specified by:
didDisconnect
in interfaceSocket
-
didFail
public void didFail(Throwable error)
Description copied from interface:Socket
Lifecycle callback invoked by the socket context when the underlying network socket fails by throwing anerror
. The socket will automatically be closed.
-
flowControl
public FlowControl flowControl()
Description copied from interface:FlowContext
Returns the currentFlowControl
state of the underlying network channel.- Specified by:
flowControl
in interfaceFlowContext
-
flowControl
public void flowControl(FlowControl flowControl)
Description copied from interface:FlowContext
Enqueues an atomic replacement of the underlying network channel's flow control state with a newflowControl
.- Specified by:
flowControl
in interfaceFlowContext
-
flowControl
public FlowControl flowControl(FlowModifier flowModifier)
Description copied from interface:FlowContext
Enqueues an atomic modification to the underlying network channel's flow control state by applying aflowModifier
delta.- Specified by:
flowControl
in interfaceFlowContext
-
become
public void become(Socket socket)
Description copied from interface:ModemContext
Rebinds the underlyingSocketContext
to a newsocket
implementation, thereby changing theSocket
handler that receives network I/O callbacks.- Specified by:
become
in interfaceModemContext<I,O>
-
close
public void close()
Description copied from interface:ModemContext
Closes the underlying network socket.- Specified by:
close
in interfaceModemContext<I,O>
-
-