- java.lang.Object
-
- swim.io.IpSocketModem<I,O>
-
- All Implemented Interfaces:
FlowContext,IpContext,IpModemContext<I,O>,IpSocket
public class IpSocketModem<I,O> extends Object implements IpSocket, IpModemContext<I,O>
-
-
Field Summary
Fields Modifier and Type Field Description protected IpSocketContextcontext
-
Constructor Summary
Constructors Constructor Description IpSocketModem(IpModem<I,O> modem)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbecome(IpSocket socket)Rebinds the underlyingIpSocketContextto a newsocketimplementation, thereby changing theIpSockethandler that receives network I/O callbacks.StringcipherSuite()Returns the cryptographic cipher suite used by the underlying network connection.voidclose()Closes the underlying network socket.voiddidBecome(IpSocket socket)Lifecycle callback invoked by the socket context after it hasbecomea newsocketimplementation.voiddidConnect()Lifecycle callback invoked by the socket context after the underlying network socket has opened a connection.voiddidDisconnect()Lifecycle callback invoked by the socket context after the underlying network connection has disconnected.voiddidFail(Throwable error)Lifecycle callback invoked by the socket context when the underlying network socket fails by throwing anerror.voiddidSecure()Lifecycle callback invoked by the socket context after the underlying network socket has established a secure connection.voiddidTimeout()Lifecycle callback invoked by the socket context after the underlying network connection has timed out.voiddidWrite()I/O callback invoked by the socket context after the underlying network socket has completed writing all data in itsoutputBuffer.voiddoRead()I/O callback invoked by the socket context asking thisIpSocketto read input data out of the socket context'sinputBuffer.voiddoWrite()I/O callback invoked by the socket context asking thisIpSocketto write output data into the socket context'soutputBuffer.FlowControlflowControl()Returns the currentFlowControlstate of the underlying network channel.voidflowControl(FlowControl flowControl)Enqueues an atomic replacement of the underlying network channel's flow control state with a newflowControl.FlowControlflowControl(FlowModifier flowModifier)Enqueues an atomic modification to the underlying network channel's flow control state by applying aflowModifierdelta.longidleTimeout()Returns the number of idle milliseconds after which thisIpSocketshould be closed due to inactivity.IpSettingsipSettings()Returns the configuration parameters that govern the underlying network socket.IpSocketContextipSocketContext()Returns the network socket context to which thisIpSocketis bound; returnsnullif thisIpSocketis unbound.booleanisClient()Returnstrueif the underlying network channel initiated an outgoing connection.booleanisConnected()Returnstrueif the underlying network channel is currently connected.booleanisSecure()Returnstrueif the underlying network transport is encrypted.booleanisServer()Returnstrueif the underlying network channel accepted an incoming connection.InetSocketAddresslocalAddress()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.PrincipallocalPrincipal()Returns the authenticated identity of the local endpoint of the underlying network connection.<I2 extends I>
voidread(Decoder<I2> reader)Enqueues a readdecoderto which input data will be asynchronously fed.InetSocketAddressremoteAddress()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.PrincipalremotePrincipal()Returns the authenticated identity of the remote endpoint of the underlying network connection.StringsecurityProtocol()Returns the name of the transport-layer security protocol used by the underlying network connection.voidsetIpSocketContext(IpSocketContext context)Sets the network socket context to which thisIpSocketis bound.voidwillBecome(IpSocket socket)Lifecycle callback invoked by the socket context before it hasbecomea newsocketimplementation.voidwillConnect()Lifecycle callback invoked by the socket context before the underlying network socket attempts to open a connection.voidwillSecure()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 writeencoderfrom which output data will be asynchronously pulled.
-
-
-
Field Detail
-
context
protected volatile IpSocketContext context
-
-
Method Detail
-
ipSocketContext
public IpSocketContext ipSocketContext()
Description copied from interface:IpSocketReturns the network socket context to which thisIpSocketis bound; returnsnullif thisIpSocketis unbound.- Specified by:
ipSocketContextin interfaceIpSocket
-
setIpSocketContext
public void setIpSocketContext(IpSocketContext context)
Description copied from interface:IpSocketSets the network socket context to which thisIpSocketis bound.- Specified by:
setIpSocketContextin interfaceIpSocket
-
isConnected
public boolean isConnected()
Description copied from interface:IpContextReturnstrueif the underlying network channel is currently connected.- Specified by:
isConnectedin interfaceIpContext
-
isClient
public boolean isClient()
Description copied from interface:IpContextReturnstrueif the underlying network channel initiated an outgoing connection.
-
isServer
public boolean isServer()
Description copied from interface:IpContextReturnstrueif the underlying network channel accepted an incoming connection.
-
isSecure
public boolean isSecure()
Description copied from interface:IpContextReturnstrueif the underlying network transport is encrypted.
-
securityProtocol
public String securityProtocol()
Description copied from interface:IpContextReturns the name of the transport-layer security protocol used by the underlying network connection. Returnsnullif the underlying network channel is not currently connected, or if the underlying network connection is not secure.- Specified by:
securityProtocolin interfaceIpContext
-
cipherSuite
public String cipherSuite()
Description copied from interface:IpContextReturns the cryptographic cipher suite used by the underlying network connection. Returnsnullif the underlying network channel is not currently connected, or if the underlying network connection is not secure.- Specified by:
cipherSuitein interfaceIpContext
-
localAddress
public InetSocketAddress localAddress()
Description copied from interface:IpContextReturns the IP address and port of the local endpoint of the underlying network connection. Returnsnullif the underlying network channel is not currently connected.- Specified by:
localAddressin interfaceIpContext
-
localPrincipal
public Principal localPrincipal()
Description copied from interface:IpContextReturns the authenticated identity of the local endpoint of the underlying network connection. Returnsnullif the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
localPrincipalin interfaceIpContext
-
localCertificates
public Collection<Certificate> localCertificates()
Description copied from interface:IpContextReturns the certificate chain used to authenticate the local endpoint of the underlying network connection. Returnsnullif the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
localCertificatesin interfaceIpContext
-
remoteAddress
public InetSocketAddress remoteAddress()
Description copied from interface:IpContextReturns the IP address and port of the remote endpoint of the underlying network connection. Returnsnullif the underlying network channel is not currently connected.- Specified by:
remoteAddressin interfaceIpContext
-
remotePrincipal
public Principal remotePrincipal()
Description copied from interface:IpContextReturns the authenticated identity of the remote endpoint of the underlying network connection. Returnsnullif the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
remotePrincipalin interfaceIpContext
-
remoteCertificates
public Collection<Certificate> remoteCertificates()
Description copied from interface:IpContextReturns the certificate chain used to authenticate the remote endpoint of the underlying network connection. Returnsnullif the underlying network channel is not currently connected, or if the underlying network connection is not authenticated.- Specified by:
remoteCertificatesin interfaceIpContext
-
ipSettings
public IpSettings ipSettings()
Description copied from interface:IpModemContextReturns the configuration parameters that govern the underlying network socket.- Specified by:
ipSettingsin interfaceIpModemContext<I,O>
-
read
public <I2 extends I> void read(Decoder<I2> reader)
Description copied from interface:IpModemContextEnqueues a readdecoderto 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 readdecodertransitions into the done state, thedidReadcallback of the boundIpModemwill be invoked with the decoded result. If the readdecodertransitions into the error state, then thedidFailcallback of the boundIpModemwill be invoked with the decode error.- Specified by:
readin interfaceIpModemContext<I,O>
-
write
public <O2 extends O> void write(Encoder<?,O2> writer)
Description copied from interface:IpModemContextEnqueues a writeencoderfrom 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 writeencodertransitions into the done state, thedidWritecallback of the boundIpModemwill be invoked with the encoded result. If the writeencodertransitions into the error state, then thedidFailcallback of the boundIpModemwill be invoked with the encode error.- Specified by:
writein interfaceIpModemContext<I,O>
-
idleTimeout
public long idleTimeout()
Description copied from interface:IpSocketReturns the number of idle milliseconds after which thisIpSocketshould be closed due to inactivity. Returns-1if a default idle timeout should be used. Returns0if the underlying network socket should not time out.- Specified by:
idleTimeoutin interfaceIpSocket
-
doRead
public void doRead()
Description copied from interface:IpSocketI/O callback invoked by the socket context asking thisIpSocketto read input data out of the socket context'sinputBuffer. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoReadcalls.
-
doWrite
public void doWrite()
Description copied from interface:IpSocketI/O callback invoked by the socket context asking thisIpSocketto write output data into the socket context'soutputBuffer. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoWriteordidWritecalls.
-
didWrite
public void didWrite()
Description copied from interface:IpSocketI/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 otherdoWriteordidWritecalls.
-
willConnect
public void willConnect()
Description copied from interface:IpSocketLifecycle callback invoked by the socket context before the underlying network socket attempts to open a connection.- Specified by:
willConnectin interfaceIpSocket
-
didConnect
public void didConnect()
Description copied from interface:IpSocketLifecycle callback invoked by the socket context after the underlying network socket has opened a connection.- Specified by:
didConnectin interfaceIpSocket
-
willSecure
public void willSecure()
Description copied from interface:IpSocketLifecycle callback invoked by the socket context before the underlying network socket establishes a secure connection.- Specified by:
willSecurein interfaceIpSocket
-
didSecure
public void didSecure()
Description copied from interface:IpSocketLifecycle callback invoked by the socket context after the underlying network socket has established a secure connection.
-
willBecome
public void willBecome(IpSocket socket)
Description copied from interface:IpSocketLifecycle callback invoked by the socket context before it hasbecomea newsocketimplementation.- Specified by:
willBecomein interfaceIpSocket
-
didBecome
public void didBecome(IpSocket socket)
Description copied from interface:IpSocketLifecycle callback invoked by the socket context after it hasbecomea newsocketimplementation.
-
didTimeout
public void didTimeout()
Description copied from interface:IpSocketLifecycle callback invoked by the socket context after the underlying network connection has timed out. The socket will automatically be closed.- Specified by:
didTimeoutin interfaceIpSocket
-
didDisconnect
public void didDisconnect()
Description copied from interface:IpSocketLifecycle callback invoked by the socket context after the underlying network connection has disconnected.- Specified by:
didDisconnectin interfaceIpSocket
-
didFail
public void didFail(Throwable error)
Description copied from interface:IpSocketLifecycle 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:FlowContextReturns the currentFlowControlstate of the underlying network channel.- Specified by:
flowControlin interfaceFlowContext
-
flowControl
public void flowControl(FlowControl flowControl)
Description copied from interface:FlowContextEnqueues an atomic replacement of the underlying network channel's flow control state with a newflowControl.- Specified by:
flowControlin interfaceFlowContext
-
flowControl
public FlowControl flowControl(FlowModifier flowModifier)
Description copied from interface:FlowContextEnqueues an atomic modification to the underlying network channel's flow control state by applying aflowModifierdelta.- Specified by:
flowControlin interfaceFlowContext
-
become
public void become(IpSocket socket)
Description copied from interface:IpModemContextRebinds the underlyingIpSocketContextto a newsocketimplementation, thereby changing theIpSockethandler that receives network I/O callbacks.- Specified by:
becomein interfaceIpModemContext<I,O>
-
close
public void close()
Description copied from interface:IpModemContextCloses the underlying network socket.- Specified by:
closein interfaceIpModemContext<I,O>
-
-