- java.lang.Object
-
- swim.io.ws.WebSocketModem<I,O>
-
- All Implemented Interfaces:
FlowContext
,IpContext
,IpModem<Object,Object>
,WebSocketContext<I,O>
public class WebSocketModem<I,O> extends Object implements IpModem<Object,Object>, WebSocketContext<I,O>
-
-
Field Summary
Fields Modifier and Type Field Description protected IpModemContext<Object,Object>
context
protected WsDecoder
decoder
protected WsEncoder
encoder
protected WebSocket<I,O>
socket
protected WsSettings
wsSettings
-
Constructor Summary
Constructors Constructor Description WebSocketModem(WebSocket<I,O> socket, WsSettings wsSettings, WsDecoder decoder, WsEncoder encoder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
become(IpSocket socket)
String
cipherSuite()
Returns the cryptographic cipher suite used by the underlying network connection.void
close()
void
didBecome(IpSocket socket)
Lifecycle callback invoked by the modem context after it hasbecome
a newsocket
implementation.void
didConnect()
Lifecycle callback invoked by the modem 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 modem context when the underlying network socket fails by throwing anerror
.void
didRead(Object input)
I/O callback invoked by the modem context with the completed value of the current readDecoder
after it has transitioned to the done state.void
didSecure()
Lifecycle callback invoked by the modem context after the underlying network socket has established a secure connection.void
didTimeout()
Lifecycle callback invoked by the modem context after the underlying network connection has timed out.void
didWrite(Object output)
I/O callback invoked by the modem context with the completed value of the current writeEncoder
after it has transitioned to the done state.void
doRead()
void
doWrite()
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 thisIpModem
should be closed due to inactivity.IpModemContext<Object,Object>
ipModemContext()
Returns the socket modem context to which thisIpModem
is bound; returnsnull
if thisIpModem
is unbound.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> payloadDecoder)
<I2 extends I>
voidread(WsOpcode frameType, Decoder<I2> payloadDecoder)
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
setIpModemContext(IpModemContext<Object,Object> context)
Sets the socket modem context to which thisIpModem
is bound.void
willBecome(IpSocket socket)
Lifecycle callback invoked by the modem context before it hasbecome
a newsocket
implementation.void
willConnect()
Lifecycle callback invoked by the modem context before the underlying network socket attempts to open a connection.void
willSecure()
Lifecycle callback invoked by the modem context before the underlying network socket establishes a secure connection.<O2 extends O>
voidwrite(WsControlFrame<?,O2> frame)
<O2 extends O>
voidwrite(WsDataFrame<O2> frame)
WsSettings
wsSettings()
-
-
-
Field Detail
-
wsSettings
protected final WsSettings wsSettings
-
decoder
protected final WsDecoder decoder
-
encoder
protected final WsEncoder encoder
-
context
protected IpModemContext<Object,Object> context
-
-
Method Detail
-
ipModemContext
public IpModemContext<Object,Object> ipModemContext()
Description copied from interface:IpModem
Returns the socket modem context to which thisIpModem
is bound; returnsnull
if thisIpModem
is unbound.- Specified by:
ipModemContext
in interfaceIpModem<I,O>
-
setIpModemContext
public void setIpModemContext(IpModemContext<Object,Object> context)
Description copied from interface:IpModem
Sets the socket modem context to which thisIpModem
is bound.- Specified by:
setIpModemContext
in interfaceIpModem<I,O>
-
idleTimeout
public long idleTimeout()
Description copied from interface:IpModem
Returns the number of idle milliseconds after which thisIpModem
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 interfaceIpModem<I,O>
-
doRead
public void doRead()
Description copied from interface:IpModem
I/O callback invoked by the modem context asking thisIpModem
to provide an inputDecoder
by invoking the modem context'sread
method. The modem context will asynchronously feed input data to the provided readDecoder
until 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 otherdoRead
ordidRead
calls.
-
didRead
public void didRead(Object input)
Description copied from interface:IpModem
I/O callback invoked by the modem context with the completed value of the current readDecoder
after it has transitioned to the done state. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdoRead
ordidRead
calls.
-
doWrite
public void doWrite()
Description copied from interface:IpModem
I/O callback invoked by the modem context asking thisIpModem
to provide an outputEncoder
by invoking the modem context'swrite
method. The modem context will asynchronously pull output data from the provided writeEncoder
until 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 otherdoWrite
ordidWrite
calls.
-
didWrite
public void didWrite(Object output)
Description copied from interface:IpModem
I/O callback invoked by the modem context with the completed value of the current writeEncoder
after it has transitioned to the done state. May be invoked concurrently to other I/O callbacks, but never concurrently with otherdodWrite
ordidWrite
calls.
-
willConnect
public void willConnect()
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context before the underlying network socket attempts to open a connection.- Specified by:
willConnect
in interfaceIpModem<I,O>
-
didConnect
public void didConnect()
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context after the underlying network socket has opened a connection.- Specified by:
didConnect
in interfaceIpModem<I,O>
-
willSecure
public void willSecure()
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context before the underlying network socket establishes a secure connection.- Specified by:
willSecure
in interfaceIpModem<I,O>
-
didSecure
public void didSecure()
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context after the underlying network socket has established a secure connection.
-
willBecome
public void willBecome(IpSocket socket)
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context before it hasbecome
a newsocket
implementation.- Specified by:
willBecome
in interfaceIpModem<I,O>
-
didBecome
public void didBecome(IpSocket socket)
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context after it hasbecome
a newsocket
implementation.
-
didTimeout
public void didTimeout()
Description copied from interface:IpModem
Lifecycle callback invoked by the modem context after the underlying network connection has timed out. The modem will automatically be closed.- Specified by:
didTimeout
in interfaceIpModem<I,O>
-
didDisconnect
public void didDisconnect()
Description copied from interface:IpModem
Lifecycle callback invoked by the socket context after the underlying network connection has disconnected.- Specified by:
didDisconnect
in interfaceIpModem<I,O>
-
didFail
public void didFail(Throwable error)
Description copied from interface:IpModem
Lifecycle 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:IpContext
Returnstrue
if the underlying network channel is currently connected.- Specified by:
isConnected
in interfaceIpContext
-
isClient
public boolean isClient()
Description copied from interface:IpContext
Returnstrue
if the underlying network channel initiated an outgoing connection.
-
isServer
public boolean isServer()
Description copied from interface:IpContext
Returnstrue
if the underlying network channel accepted an incoming connection.
-
isSecure
public boolean isSecure()
Description copied from interface:IpContext
Returnstrue
if the underlying network transport is encrypted.
-
securityProtocol
public String securityProtocol()
Description copied from interface:IpContext
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 interfaceIpContext
-
cipherSuite
public String cipherSuite()
Description copied from interface:IpContext
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 interfaceIpContext
-
localAddress
public InetSocketAddress localAddress()
Description copied from interface:IpContext
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 interfaceIpContext
-
localPrincipal
public Principal localPrincipal()
Description copied from interface:IpContext
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 interfaceIpContext
-
localCertificates
public Collection<Certificate> localCertificates()
Description copied from interface:IpContext
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 interfaceIpContext
-
remoteAddress
public InetSocketAddress remoteAddress()
Description copied from interface:IpContext
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 interfaceIpContext
-
remotePrincipal
public Principal remotePrincipal()
Description copied from interface:IpContext
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 interfaceIpContext
-
remoteCertificates
public Collection<Certificate> remoteCertificates()
Description copied from interface:IpContext
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 interfaceIpContext
-
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
-
wsSettings
public WsSettings wsSettings()
- Specified by:
wsSettings
in interfaceWebSocketContext<I,O>
-
read
public <I2 extends I> void read(Decoder<I2> payloadDecoder)
- Specified by:
read
in interfaceWebSocketContext<I,O>
-
read
public <I2 extends I> void read(WsOpcode frameType, Decoder<I2> payloadDecoder)
- Specified by:
read
in interfaceWebSocketContext<I,O>
-
write
public <O2 extends O> void write(WsDataFrame<O2> frame)
- Specified by:
write
in interfaceWebSocketContext<I,O>
-
write
public <O2 extends O> void write(WsControlFrame<?,O2> frame)
- Specified by:
write
in interfaceWebSocketContext<I,O>
-
become
public void become(IpSocket socket)
- Specified by:
become
in interfaceWebSocketContext<I,O>
-
close
public void close()
- Specified by:
close
in interfaceWebSocketContext<I,O>
-
-