- java.lang.Object
-
- swim.io.AbstractModem<I,O>
-
- All Implemented Interfaces:
ConnectionContext,FlowContext,Modem<I,O>
public abstract class AbstractModem<I,O> extends Object implements Modem<I,O>, ConnectionContext, FlowContext
-
-
Field Summary
Fields Modifier and Type Field Description protected ModemContext<I,O>context
-
Constructor Summary
Constructors Constructor Description AbstractModem()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbecome(Socket socket)StringcipherSuite()Returns the cryptographic cipher suite used by the underlying network connection.voidclose()voiddidBecome(Socket socket)Lifecycle callback invoked by the modem context after it hasbecomea newsocketimplementation.voiddidConnect()Lifecycle callback invoked by the modem 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 modem context when the underlying network socket fails by throwing anerror.voiddidRead(I input)I/O callback invoked by the modem context with the completed value of the current readDecoderafter it has transitioned to the done state.voiddidSecure()Lifecycle callback invoked by the modem context after the underlying network socket has established a secure connection.voiddidTimeout()Lifecycle callback invoked by the modem context after the underlying network connection has timed out.voiddidWrite(O output)I/O callback invoked by the modem context with the completed value of the current writeEncoderafter it has transitioned to the done state.voiddoRead()I/O callback invoked by the modem context asking thisModemto provide an inputDecoderby invoking the modem context'sreadmethod.voiddoWrite()I/O callback invoked by the modem context asking thisModemto provide an outputEncoderby invoking the modem context'swritemethod.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 thisModemshould be closed due to inactivity.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.ModemContext<I,O>modemContext()Returns the socket modem context to which thisModemis bound; returnsnullif thisModemis unbound.<I2 extends I>
voidread(swim.codec.Decoder<I2> decoder)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.voidsetModemContext(ModemContext<I,O> context)Sets the socket modem context to which thisModemis bound.SocketSettingssocketSettings()voidwillBecome(Socket socket)Lifecycle callback invoked by the modem context before it hasbecomea newsocketimplementation.voidwillConnect()Lifecycle callback invoked by the modem context before the underlying network socket attempts to open a connection.voidwillSecure()Lifecycle callback invoked by the modem context before the underlying network socket establishes a secure connection.<O2 extends O>
voidwrite(swim.codec.Encoder<?,O2> encoder)
-
-
-
Field Detail
-
context
protected ModemContext<I,O> context
-
-
Method Detail
-
modemContext
public ModemContext<I,O> modemContext()
Description copied from interface:ModemReturns the socket modem context to which thisModemis bound; returnsnullif thisModemis unbound.- Specified by:
modemContextin interfaceModem<I,O>
-
setModemContext
public void setModemContext(ModemContext<I,O> context)
Description copied from interface:ModemSets the socket modem context to which thisModemis bound.- Specified by:
setModemContextin interfaceModem<I,O>
-
idleTimeout
public long idleTimeout()
Description copied from interface:ModemReturns the number of idle milliseconds after which thisModemshould 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 interfaceModem<I,O>
-
doRead
public void doRead()
Description copied from interface:ModemI/O callback invoked by the modem context asking thisModemto provide an inputDecoderby invoking the modem context'sreadmethod. The modem context will asynchronously feed input data to the provided readDecoderuntil it transitions out of the cont state. The read flow control of the underlying network socket is automatically managed by the modem context using the state of the readDecoder. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoReadordidReadcalls.
-
didRead
public void didRead(I input)
Description copied from interface:ModemI/O callback invoked by the modem context with the completed value of the current readDecoderafter it has transitioned to the done state. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoReadordidReadcalls.
-
doWrite
public void doWrite()
Description copied from interface:ModemI/O callback invoked by the modem context asking thisModemto provide an outputEncoderby invoking the modem context'swritemethod. The modem context will asynchronously pull output data from the provided writeEncoderuntil it transitions out of the cont state. The write flow control of the underlying network socket is automatically managed by the modem context using the state of the writeEncoder. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoWriteordidWritecalls.
-
didWrite
public void didWrite(O output)
Description copied from interface:ModemI/O callback invoked by the modem context with the completed value of the current writeEncoderafter it has transitioned to the done state. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdodWriteordidWritecalls.
-
willConnect
public void willConnect()
Description copied from interface:ModemLifecycle callback invoked by the modem context before the underlying network socket attempts to open a connection.- Specified by:
willConnectin interfaceModem<I,O>
-
didConnect
public void didConnect()
Description copied from interface:ModemLifecycle callback invoked by the modem context after the underlying network socket has opened a connection.- Specified by:
didConnectin interfaceModem<I,O>
-
willSecure
public void willSecure()
Description copied from interface:ModemLifecycle callback invoked by the modem context before the underlying network socket establishes a secure connection.- Specified by:
willSecurein interfaceModem<I,O>
-
didSecure
public void didSecure()
Description copied from interface:ModemLifecycle callback invoked by the modem context after the underlying network socket has established a secure connection.
-
willBecome
public void willBecome(Socket socket)
Description copied from interface:ModemLifecycle callback invoked by the modem context before it hasbecomea newsocketimplementation.- Specified by:
willBecomein interfaceModem<I,O>
-
didBecome
public void didBecome(Socket socket)
Description copied from interface:ModemLifecycle callback invoked by the modem context after it hasbecomea newsocketimplementation.
-
didTimeout
public void didTimeout()
Description copied from interface:ModemLifecycle callback invoked by the modem context after the underlying network connection has timed out. The modem will automatically be closed.- Specified by:
didTimeoutin interfaceModem<I,O>
-
didDisconnect
public void didDisconnect()
Description copied from interface:ModemLifecycle callback invoked by the socket context after the underlying network connection has disconnected.- Specified by:
didDisconnectin interfaceModem<I,O>
-
didFail
public void didFail(Throwable error)
Description copied from interface:ModemLifecycle callback invoked by the modem context when the underlying network socket fails by throwing anerror. The modem will automatically be closed.
-
isConnected
public boolean isConnected()
Description copied from interface:ConnectionContextReturnstrueif the underlying network channel is currently connected.- Specified by:
isConnectedin interfaceConnectionContext
-
isClient
public boolean isClient()
Description copied from interface:ConnectionContextReturnstrueif the underlying network channel initiated an outgoing connection.- Specified by:
isClientin interfaceConnectionContext
-
isServer
public boolean isServer()
Description copied from interface:ConnectionContextReturnstrueif the underlying network channel accepted an incoming connection.- Specified by:
isServerin interfaceConnectionContext
-
isSecure
public boolean isSecure()
Description copied from interface:ConnectionContextReturnstrueif the underlying network transport is encrypted.- Specified by:
isSecurein interfaceConnectionContext
-
securityProtocol
public String securityProtocol()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
cipherSuite
public String cipherSuite()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
localAddress
public InetSocketAddress localAddress()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
localPrincipal
public Principal localPrincipal()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
localCertificates
public Collection<Certificate> localCertificates()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
remoteAddress
public InetSocketAddress remoteAddress()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
remotePrincipal
public Principal remotePrincipal()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
remoteCertificates
public Collection<Certificate> remoteCertificates()
Description copied from interface:ConnectionContextReturns 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 interfaceConnectionContext
-
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
-
socketSettings
public SocketSettings socketSettings()
-
read
public <I2 extends I> void read(swim.codec.Decoder<I2> decoder)
-
write
public <O2 extends O> void write(swim.codec.Encoder<?,O2> encoder)
-
become
public void become(Socket socket)
-
close
public void close()
-
-