@ManagedObject public class WebSocketSession extends ContainerLifeCycle implements Session, WebSocketConnection, IncomingFrames
AbstractLifeCycle.AbstractLifeCycleListener
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Constructor and Description |
---|
WebSocketSession(URI requestURI,
EventDriver websocket,
LogicalConnection connection) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the current conversation with a normal status code and no reason phrase.
|
void |
close(CloseStatus closeStatus)
Close the current conversation, giving a reason for the closure.
|
void |
close(int statusCode,
String reason)
Send a websocket Close frame, with status code.
|
void |
dump(Appendable out,
String indent) |
LogicalConnection |
getConnection() |
ExtensionFactory |
getExtensionFactory() |
IncomingFrames |
getIncomingHandler() |
InetSocketAddress |
getLocalAddress()
Get the address of the local side.
|
long |
getMaximumMessageSize()
The maximum total length of messages, text or binary, that this Session can handle.
|
List<String> |
getNegotiatedExtensions()
Return the list of extensions currently in use for this conversation.
|
String |
getNegotiatedSubprotocol()
Return the sub protocol agreed during the websocket handshake for this conversation.
|
OutgoingFrames |
getOutgoingHandler() |
WebSocketPolicy |
getPolicy()
Access the (now read-only)
WebSocketPolicy in use for this connection. |
String |
getProtocolVersion()
Returns the version of the websocket protocol currently being used.
|
String |
getQueryString()
Return the query string associated with the request this session was opened under.
|
RemoteEndpoint |
getRemote()
Return a reference to the RemoteEndpoint object representing the other end of this conversation.
|
InetSocketAddress |
getRemoteAddress()
Get the address of the remote side.
|
URI |
getRequestURI()
Return the URI that this session was opened under.
|
String |
getSubProtocol()
Get the SubProtocol in use for this connection.
|
long |
getTimeout()
The timeout in seconds
|
void |
incomingError(WebSocketException e)
Incoming Errors from Parser
|
void |
incomingFrame(Frame frame)
Incoming Raw Frames from Parser
|
boolean |
isActive()
Return true if and only if the underlying socket is open.
|
boolean |
isOpen()
Is the connection open.
|
boolean |
isSecure()
Return true if and only if the underlying socket is using a secure transport.
|
void |
open()
Open/Activate the session
|
void |
ping(ByteBuffer buf)
Send a single ping messages.
|
void |
setActive(boolean active) |
void |
setExtensionFactory(ExtensionFactory extensionFactory) |
void |
setMaximumMessageSize(long length)
Sets the maximum total length of messages, text or binary, that this Session can handle.
|
void |
setNegotiatedExtensions(List<String> negotiatedExtensions) |
void |
setNegotiatedSubprotocol(String negotiatedSubprotocol) |
void |
setOutgoingHandler(OutgoingFrames outgoing) |
void |
setPolicy(WebSocketPolicy policy) |
void |
setTimeout(long seconds)
Set the timeout in seconds
|
SuspendToken |
suspend()
Suspend a the incoming read events on the connection.
|
String |
toString() |
Future<Void> |
write(byte[] buf,
int offset,
int len)
Send an async binary message.
|
Future<Void> |
write(ByteBuffer buffer)
Send an async binary message.
|
Future<Void> |
write(String message)
Send an async text messages.
|
addBean, addBean, addBean, contains, destroy, doStart, doStop, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, setBeans, setStopTimeout, start, unmanage, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public WebSocketSession(URI requestURI, EventDriver websocket, LogicalConnection connection)
public void close() throws IOException
Session
close
in interface Session
close
in interface WebSocketConnection
IOException
StatusCode
,
WebSocketConnection.close(int, String)
public void close(CloseStatus closeStatus) throws IOException
Session
close
in interface Session
closeStatus
- the reason for the closureIOException
public void close(int statusCode, String reason)
WebSocketConnection
Advanced usage: results in an non-blocking async write, then connection close.
close
in interface WebSocketConnection
statusCode
- the status codereason
- the (optional) reason. (can be null for no reason)StatusCode
public void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
dump
in class ContainerLifeCycle
IOException
public LogicalConnection getConnection()
public ExtensionFactory getExtensionFactory()
@ManagedAttribute(readonly=true) public IncomingFrames getIncomingHandler()
public InetSocketAddress getLocalAddress()
WebSocketConnection
getLocalAddress
in interface WebSocketConnection
public long getMaximumMessageSize()
Session
getMaximumMessageSize
in interface Session
public List<String> getNegotiatedExtensions()
Session
getNegotiatedExtensions
in interface Session
public String getNegotiatedSubprotocol()
Session
getNegotiatedSubprotocol
in interface Session
@ManagedAttribute(readonly=true) public OutgoingFrames getOutgoingHandler()
public WebSocketPolicy getPolicy()
WebSocketConnection
WebSocketPolicy
in use for this connection.getPolicy
in interface WebSocketConnection
public String getProtocolVersion()
Session
getProtocolVersion
in interface Session
public String getQueryString()
Session
getQueryString
in interface Session
public RemoteEndpoint getRemote()
Session
public InetSocketAddress getRemoteAddress()
WebSocketConnection
getRemoteAddress
in interface WebSocketConnection
public URI getRequestURI()
Session
Note, this is different than the servlet-api getRequestURI, as this will return the query portion as well.
getRequestURI
in interface Session
getRequestURI
in interface WebSocketConnection
public String getSubProtocol()
WebSocketConnection
getSubProtocol
in interface WebSocketConnection
public long getTimeout()
getTimeout
in interface Session
public void incomingError(WebSocketException e)
incomingError
in interface IncomingFrames
public void incomingFrame(Frame frame)
incomingFrame
in interface IncomingFrames
public boolean isActive()
Session
public boolean isOpen()
WebSocketConnection
isOpen
in interface WebSocketConnection
public boolean isSecure()
Session
public void open()
IOException
public void ping(ByteBuffer buf) throws IOException
WebSocketConnection
NIO style with callbacks, allows for knowledge of successful ping send.
Use @OnWebSocketFrame and monitor Pong frames
ping
in interface WebSocketConnection
IOException
public void setActive(boolean active)
public void setExtensionFactory(ExtensionFactory extensionFactory)
public void setMaximumMessageSize(long length)
Session
setMaximumMessageSize
in interface Session
public void setNegotiatedSubprotocol(String negotiatedSubprotocol)
public void setOutgoingHandler(OutgoingFrames outgoing)
public void setPolicy(WebSocketPolicy policy)
public void setTimeout(long seconds)
setTimeout
in interface Session
seconds
- the number of milliseconds.public SuspendToken suspend()
WebSocketConnection
suspend
in interface WebSocketConnection
public Future<Void> write(byte[] buf, int offset, int len)
WebSocketConnection
write
in interface WebSocketConnection
public Future<Void> write(ByteBuffer buffer)
WebSocketConnection
write
in interface WebSocketConnection
public Future<Void> write(String message)
WebSocketConnection
write
in interface WebSocketConnection
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.