Class AbstractWebSocketConnection
- java.lang.Object
-
- org.eclipse.jetty.io.AbstractConnection
-
- org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Connection,Connection.UpgradeTo,Dumpable,OutgoingFrames,SuspendToken,LogicalConnection
- Direct Known Subclasses:
WebSocketClientConnection,WebSocketServerConnection
public abstract class AbstractWebSocketConnection extends AbstractConnection implements LogicalConnection, Connection.UpgradeTo, Dumpable
Provides the implementation ofLogicalConnectionwithin the framework of the newConnectionframework ofjetty-io.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractWebSocketConnection.StatsDeprecated.-
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeTo
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
-
Constructor Summary
Constructors Constructor Description AbstractWebSocketConnection(EndPoint endp, java.util.concurrent.Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancanReadWebSocketFrames()Test if Connection State allows for reading of frames.booleancanWriteWebSocketFrames()Test if Connection State allows for writing frames.voidclose()Jetty Connection Closevoidclose(java.lang.Throwable cause)Close the connection based on the throwablevoidclose(CloseInfo close, Callback callback)Request a local close.voiddisconnect()Terminate the connection (no close frame sent)voiddump(java.lang.Appendable out, java.lang.String indent)Dump this object (and children) into an Appendable using the provided indent after any new lines.java.lang.StringdumpSelf()The description of this/self found in the dump.voidfillInterested()Utility method to be called to register read interest.ByteBufferPoolgetBufferPool()Get the ByteBufferPool in use by the connectionlonggetBytesIn()longgetBytesOut()java.util.concurrent.ExecutorgetExecutor()Get the Executor used by this connection.java.util.List<ExtensionConfig>getExtensions()Get the list of extensions in use.GeneratorgetGenerator()java.lang.StringgetId()Get Unique ID for the ConnectionlonggetIdleTimeout()Get the read/write idle timeout.java.net.InetSocketAddressgetLocalAddress()Get the localInetSocketAddressin use for this connection.longgetMaxIdleTimeout()Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)longgetMessagesIn()longgetMessagesOut()ParsergetParser()WebSocketPolicygetPolicy()The policy that the connection is running under.java.net.InetSocketAddressgetRemoteAddress()Get the remote Address in use for this connection.SchedulergetScheduler()AbstractWebSocketConnection.StatsgetStats()Deprecated.booleanisOpen()Test if logical connection is still openbooleanisReading()Tests if the connection is actively reading.voidonFillable()Callback method invoked when the endpoint is ready to be read.protected voidonFillInterestedFailed(java.lang.Throwable cause)Callback method invoked when the endpoint failed to be ready to be read.booleanonIdleExpired()Callback method invoked upon an idle timeout event.protected booleanonReadTimeout(java.lang.Throwable timeout)Event for no activity on connection (read or write)voidonUpgradeTo(java.nio.ByteBuffer buffer)Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connectionbooleanopened()Set the state to opened (the application onOpen() method has been called successfully).booleanopening()Set the state to upgrade/opening handshake has completed.voidoutgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)Frame from API, User, or Internal implementation destined for network.voidremoteClose(CloseInfo close)Report that the Remote Endpoint CLOSE Frame has been receivedvoidresume()Resume a previously suspended connection.voidsetExtensions(java.util.List<ExtensionConfig> extensions)Get the list of extensions in use.protected voidsetInitialBuffer(java.nio.ByteBuffer initialBuffer)Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connectionvoidsetInputBufferSize(int inputBufferSize)voidsetMaxIdleTimeout(long ms)Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)voidsetNextIncomingFrames(IncomingFrames incoming)Set where the connection should send the incoming frames to.voidsetSession(WebSocketSession session)Associate the Active Session with the connection.SuspendTokensuspend()Suspend a the incoming read events on the connection.java.lang.StringtoConnectionString()java.lang.StringtoStateString()Get the Connection State as a String-
Methods inherited from class org.eclipse.jetty.io.AbstractConnection
addListener, failedCallback, getCreatedTimeStamp, getEndPoint, getInputBufferSize, isFillInterested, onClose, onOpen, removeListener, toString, tryFillInterested, tryFillInterested
-
-
-
-
Constructor Detail
-
AbstractWebSocketConnection
public AbstractWebSocketConnection(EndPoint endp, java.util.concurrent.Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool)
-
-
Method Detail
-
getExecutor
public java.util.concurrent.Executor getExecutor()
Description copied from interface:LogicalConnectionGet the Executor used by this connection.- Specified by:
getExecutorin interfaceLogicalConnection- Overrides:
getExecutorin classAbstractConnection- Returns:
- the executor
-
close
public void close(CloseInfo close, Callback callback)
Description copied from interface:LogicalConnectionRequest a local close.- Specified by:
closein interfaceLogicalConnection
-
close
public void close(java.lang.Throwable cause)
Close the connection based on the throwable- Specified by:
closein interfaceLogicalConnection- Parameters:
cause- the cause
-
canWriteWebSocketFrames
public boolean canWriteWebSocketFrames()
Description copied from interface:LogicalConnectionTest if Connection State allows for writing frames.- Specified by:
canWriteWebSocketFramesin interfaceLogicalConnection- Returns:
- true if able to write, false otherwise.
-
canReadWebSocketFrames
public boolean canReadWebSocketFrames()
Description copied from interface:LogicalConnectionTest if Connection State allows for reading of frames.- Specified by:
canReadWebSocketFramesin interfaceLogicalConnection- Returns:
- true if able to read, false otherwise.
-
toStateString
public java.lang.String toStateString()
Description copied from interface:LogicalConnectionGet the Connection State as a String- Specified by:
toStateStringin interfaceLogicalConnection- Returns:
- the Connection State string
-
opening
public boolean opening()
Description copied from interface:LogicalConnectionSet the state to upgrade/opening handshake has completed.- Specified by:
openingin interfaceLogicalConnection- Returns:
- true if state is OPENING, false otherwise
-
opened
public boolean opened()
Description copied from interface:LogicalConnectionSet the state to opened (the application onOpen() method has been called successfully).Reads from network begin here.
- Specified by:
openedin interfaceLogicalConnection- Returns:
- true if state is OPENED, false otherwise
-
remoteClose
public void remoteClose(CloseInfo close)
Description copied from interface:LogicalConnectionReport that the Remote Endpoint CLOSE Frame has been received- Specified by:
remoteClosein interfaceLogicalConnection- Parameters:
close- the close frame details
-
setSession
public void setSession(WebSocketSession session)
Description copied from interface:LogicalConnectionAssociate the Active Session with the connection.- Specified by:
setSessionin interfaceLogicalConnection- Parameters:
session- the session for this connection
-
onIdleExpired
public boolean onIdleExpired()
Description copied from interface:ConnectionCallback method invoked upon an idle timeout event.
Implementations of this method may return true to indicate that the idle timeout handling should proceed normally, typically failing the EndPoint and causing it to be closed.
When false is returned, the handling of the idle timeout event is halted immediately and the EndPoint left in the state it was before the idle timeout event.
- Specified by:
onIdleExpiredin interfaceConnection- Overrides:
onIdleExpiredin classAbstractConnection- Returns:
- true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.
-
close
public void close()
Jetty Connection Close- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceConnection- Overrides:
closein classAbstractConnection
-
disconnect
public void disconnect()
Description copied from interface:LogicalConnectionTerminate the connection (no close frame sent)- Specified by:
disconnectin interfaceLogicalConnection
-
fillInterested
public void fillInterested()
Description copied from class:AbstractConnectionUtility method to be called to register read interest.
After a call to this method,
AbstractConnection.onFillable()orAbstractConnection.onFillInterestedFailed(Throwable)will be called back as appropriate.- Overrides:
fillInterestedin classAbstractConnection- See Also:
AbstractConnection.onFillable()
-
getBufferPool
public ByteBufferPool getBufferPool()
Description copied from interface:LogicalConnectionGet the ByteBufferPool in use by the connection- Specified by:
getBufferPoolin interfaceLogicalConnection- Returns:
- the buffer pool
-
getExtensions
public java.util.List<ExtensionConfig> getExtensions()
Get the list of extensions in use.This list is negotiated during the WebSocket Upgrade Request/Response handshake.
- Returns:
- the list of negotiated extensions in use.
-
getGenerator
public Generator getGenerator()
-
getId
public java.lang.String getId()
Description copied from interface:LogicalConnectionGet Unique ID for the Connection- Specified by:
getIdin interfaceLogicalConnection- Returns:
- the unique ID for the connection
-
getIdleTimeout
public long getIdleTimeout()
Description copied from interface:LogicalConnectionGet the read/write idle timeout.- Specified by:
getIdleTimeoutin interfaceLogicalConnection- Returns:
- the idle timeout in milliseconds
-
getMaxIdleTimeout
public long getMaxIdleTimeout()
Description copied from interface:LogicalConnectionSet the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)- Specified by:
getMaxIdleTimeoutin interfaceLogicalConnection- Returns:
- the idle timeout in milliseconds
-
getParser
public Parser getParser()
-
getPolicy
public WebSocketPolicy getPolicy()
Description copied from interface:LogicalConnectionThe policy that the connection is running under.- Specified by:
getPolicyin interfaceLogicalConnection- Returns:
- the policy for the connection
-
getLocalAddress
public java.net.InetSocketAddress getLocalAddress()
Description copied from interface:LogicalConnectionGet the localInetSocketAddressin use for this connection.Note: Non-physical connections, like during the Mux extensions, or during unit testing can result in a InetSocketAddress on port 0 and/or on localhost.
- Specified by:
getLocalAddressin interfaceLogicalConnection- Returns:
- the local address.
-
getRemoteAddress
public java.net.InetSocketAddress getRemoteAddress()
Description copied from interface:LogicalConnectionGet the remote Address in use for this connection.Note: Non-physical connections, like during the Mux extensions, or during unit testing can result in a InetSocketAddress on port 0 and/or on localhost.
- Specified by:
getRemoteAddressin interfaceLogicalConnection- Returns:
- the remote address.
-
getScheduler
public Scheduler getScheduler()
-
getStats
@Deprecated public AbstractWebSocketConnection.Stats getStats()
Deprecated.
-
isOpen
public boolean isOpen()
Description copied from interface:LogicalConnectionTest if logical connection is still open- Specified by:
isOpenin interfaceLogicalConnection- Returns:
- true if connection is open
-
isReading
public boolean isReading()
Description copied from interface:LogicalConnectionTests if the connection is actively reading.- Specified by:
isReadingin interfaceLogicalConnection- Returns:
- true if connection is actively attempting to read.
-
onFillable
public void onFillable()
Description copied from class:AbstractConnectionCallback method invoked when the endpoint is ready to be read.
- Specified by:
onFillablein classAbstractConnection- See Also:
AbstractConnection.fillInterested()
-
resume
public void resume()
Description copied from interface:SuspendTokenResume a previously suspended connection.- Specified by:
resumein interfaceSuspendToken
-
suspend
public SuspendToken suspend()
Description copied from interface:LogicalConnectionSuspend a the incoming read events on the connection.- Specified by:
suspendin interfaceLogicalConnection- Returns:
- the suspend token
-
onFillInterestedFailed
protected void onFillInterestedFailed(java.lang.Throwable cause)
Description copied from class:AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read.
- Overrides:
onFillInterestedFailedin classAbstractConnection- Parameters:
cause- the exception that caused the failure
-
setInitialBuffer
protected void setInitialBuffer(java.nio.ByteBuffer initialBuffer)
Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connection- Parameters:
initialBuffer- the bytes of unconsumed content encountered during upgrade
-
onReadTimeout
protected boolean onReadTimeout(java.lang.Throwable timeout)
Event for no activity on connection (read or write)- Overrides:
onReadTimeoutin classAbstractConnection- Parameters:
timeout- the cause of the read timeout- Returns:
- true to signal that the endpoint must be closed, false to keep the endpoint open
-
outgoingFrame
public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
Frame from API, User, or Internal implementation destined for network.- Specified by:
outgoingFramein interfaceOutgoingFrames- Parameters:
frame- the frame to eventually write to the network layer.callback- the callback to notify when the frame is written.batchMode- the batch mode requested by the sender.
-
setExtensions
public void setExtensions(java.util.List<ExtensionConfig> extensions)
Get the list of extensions in use.This list is negotiated during the WebSocket Upgrade Request/Response handshake.
- Parameters:
extensions- the list of negotiated extensions in use.
-
setInputBufferSize
public void setInputBufferSize(int inputBufferSize)
- Overrides:
setInputBufferSizein classAbstractConnection
-
setMaxIdleTimeout
public void setMaxIdleTimeout(long ms)
Description copied from interface:LogicalConnectionSet the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)This idle timeout cannot be garunteed to take immediate effect for any active read/write actions. New read/write actions will have this new idle timeout.
- Specified by:
setMaxIdleTimeoutin interfaceLogicalConnection- Parameters:
ms- the number of milliseconds of idle timeout
-
dumpSelf
public java.lang.String dumpSelf()
Description copied from interface:DumpableThe description of this/self found in the dump. Allows for alternative representation of Object other then .toString() where the long form output of toString() is represented in a cleaner way within the dump infrastructure.
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOExceptionDescription copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
-
toConnectionString
public java.lang.String toConnectionString()
- Overrides:
toConnectionStringin classAbstractConnection
-
onUpgradeTo
public void onUpgradeTo(java.nio.ByteBuffer buffer)
Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connection- Specified by:
onUpgradeToin interfaceConnection.UpgradeTo- Parameters:
buffer- a non-null buffer of unconsumed bytes received from the upgrade-from connection. The buffer does not belong to any pool and should be discarded after having consumed its bytes.
-
setNextIncomingFrames
public void setNextIncomingFrames(IncomingFrames incoming)
Description copied from interface:LogicalConnectionSet where the connection should send the incoming frames to.Often this is from the Parser to the start of the extension stack, and eventually on to the session.
- Specified by:
setNextIncomingFramesin interfaceLogicalConnection- Parameters:
incoming- the incoming frames handler
-
getMessagesIn
public long getMessagesIn()
- Specified by:
getMessagesInin interfaceConnection- Overrides:
getMessagesInin classAbstractConnection- Returns:
- the number of WebSocket frames received over this connection
-
getMessagesOut
public long getMessagesOut()
- Specified by:
getMessagesOutin interfaceConnection- Overrides:
getMessagesOutin classAbstractConnection- Returns:
- the number of WebSocket frames sent over this connection
-
getBytesIn
public long getBytesIn()
- Specified by:
getBytesInin interfaceConnection- Overrides:
getBytesInin classAbstractConnection- Returns:
- the number of bytes received over this connection
-
getBytesOut
public long getBytesOut()
- Specified by:
getBytesOutin interfaceConnection- Overrides:
getBytesOutin classAbstractConnection- Returns:
- the number of bytes frames sent over this connection
-
-