Class WebSocketConnection

java.lang.Object
org.eclipse.jetty.io.AbstractConnection
org.eclipse.jetty.websocket.core.WebSocketConnection
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable, Connection, Connection.UpgradeTo, Dumpable, Invocable

public class WebSocketConnection extends AbstractConnection implements Connection.UpgradeTo, Dumpable, Runnable
Provides the implementation of Connection that is suitable for WebSocket
  • Constructor Details

    • WebSocketConnection

      public WebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, WebSocketCoreSession coreSession)
      Create a WSConnection.

      It is assumed that the WebSocket Upgrade Handshake has already completed successfully before creating this connection.

    • WebSocketConnection

      public WebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, WebSocketCoreSession coreSession, Random randomMask)
      Create a WSConnection.

      It is assumed that the WebSocket Upgrade Handshake has already completed successfully before creating this connection.

      Parameters:
      endp - The endpoint ever which Websockot is sent/received
      executor - A thread executor to use for WS callbacks.
      scheduler - A scheduler to use for timeouts
      byteBufferPool - A pool of retainable buffers to use.
      coreSession - The WC core session to which frames are delivered.
      randomMask - A Random used to mask frames. If null then SecureRandom will be created if needed.
  • Method Details

    • getExecutor

      public Executor getExecutor()
      Overrides:
      getExecutor in class AbstractConnection
    • getLocalAddress

      @Deprecated public InetSocketAddress getLocalAddress()
      Deprecated.
      Returns:
      the local InetSocketAddress
    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
    • getRemoteAddress

      @Deprecated public InetSocketAddress getRemoteAddress()
      Deprecated.
      Returns:
      the remote InetSocketAddress
    • getRemoteSocketAddress

      public SocketAddress getRemoteSocketAddress()
    • isUseInputDirectByteBuffers

      public boolean isUseInputDirectByteBuffers()
    • setWriteTimeout

      public void setWriteTimeout(long writeTimeout)
    • setUseInputDirectByteBuffers

      public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)
    • isUseOutputDirectByteBuffers

      public boolean isUseOutputDirectByteBuffers()
    • setUseOutputDirectByteBuffers

      public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)
    • onClose

      public void onClose(Throwable cause)
      Description copied from interface: Connection

      Callback method invoked when this connection is closed.

      Creators of the connection implementation are responsible for calling this method.

      Specified by:
      onClose in interface Connection
      Overrides:
      onClose in class AbstractConnection
      Parameters:
      cause - The cause of the close or null for a normal close
    • onIdleExpired

      public boolean onIdleExpired(TimeoutException timeoutException)
      Description copied from interface: Connection

      Callback 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:
      onIdleExpired in interface Connection
      Overrides:
      onIdleExpired in class AbstractConnection
      Returns:
      true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.
    • onReadTimeout

      protected boolean onReadTimeout(TimeoutException timeout)
      Description copied from class: AbstractConnection

      Callback method invoked when the endpoint failed to be ready to be read after a timeout

      Overrides:
      onReadTimeout in class AbstractConnection
      Parameters:
      timeout - the cause of the read timeout
      Returns:
      true to signal that the endpoint must be closed, false to keep the endpoint open
    • onFrame

      protected void onFrame(Frame.Parsed frame)
    • onFillable

      public void onFillable()
      Description copied from class: AbstractConnection

      Callback method invoked when the endpoint is ready to be read.

      Specified by:
      onFillable in class AbstractConnection
      See Also:
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • demand

      public void demand()
    • moreDemand

      public boolean moreDemand()
    • meetDemand

      public boolean meetDemand()
    • cancelDemand

      public void cancelDemand()
    • setInitialBuffer

      protected void setInitialBuffer(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 extra content encountered during upgrade
    • onOpen

      public void onOpen()
      Description copied from interface: Connection

      Callback method invoked when this connection is opened.

      Creators of the connection implementation are responsible for calling this method.

      Specified by:
      onOpen in interface Connection
      Overrides:
      onOpen in class AbstractConnection
    • setInputBufferSize

      public void setInputBufferSize(int inputBufferSize)
      Overrides:
      setInputBufferSize in class AbstractConnection
    • dump

      public String dump()
      Specified by:
      dump in interface Dumpable
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump 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.
      Specified by:
      dump in interface Dumpable
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable
    • toConnectionString

      public String toConnectionString()
      Overrides:
      toConnectionString in class AbstractConnection
    • onUpgradeTo

      public void onUpgradeTo(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:
      onUpgradeTo in interface Connection.UpgradeTo
      Parameters:
      buffer - a non-null buffer of extra bytes
    • getMessagesIn

      public long getMessagesIn()
      Specified by:
      getMessagesIn in interface Connection
      Overrides:
      getMessagesIn in class AbstractConnection
    • getBytesIn

      public long getBytesIn()
      Specified by:
      getBytesIn in interface Connection
      Overrides:
      getBytesIn in class AbstractConnection
    • getMessagesOut

      public long getMessagesOut()
      Specified by:
      getMessagesOut in interface Connection
      Overrides:
      getMessagesOut in class AbstractConnection
    • getBytesOut

      public long getBytesOut()
      Specified by:
      getBytesOut in interface Connection
      Overrides:
      getBytesOut in class AbstractConnection
    • enqueueFrame

      public void enqueueFrame(Frame frame, Callback callback, boolean batch)
      Enqueue a Frame to be sent.
      Parameters:
      frame - The frame to queue
      callback - The callback to call once the frame is sent
      batch - True if batch mode is to be used