public abstract class WebSocketApplication extends WebSocketAdapter
Constructor and Description |
---|
WebSocketApplication() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
add(WebSocket socket)
Associates the specified
WebSocket with this application. |
WebSocket |
createSocket(ProtocolHandler handler,
HttpRequestPacket requestPacket,
WebSocketListener... listeners)
Factory method to create new
WebSocket instances. |
WebSocket |
createSocket(ProtocolHandler handler,
WebSocketListener... listeners)
|
List<Extension> |
getSupportedExtensions()
Return the websocket extensions supported by this
WebSocketApplication . |
List<String> |
getSupportedProtocols(List<String> subProtocol) |
protected Set<WebSocket> |
getWebSockets()
Returns a set of
WebSocket s, registered with the application. |
protected void |
handshake(HandShake handshake)
This method will be called, when initial
WebSocket handshake
process has been completed, but allows the application to perform further
negotiation/validation. |
boolean |
isApplicationRequest(HttpRequestPacket request)
Deprecated.
URI mapping shouldn't be intrinsic to the application.
WebSocketApplications should be registered using
WebSocketEngine.register(String, String, WebSocketApplication)
using standard Servlet url-pattern rules. |
void |
onClose(WebSocket socket,
DataFrame frame)
When a
WebSocket.onClose(DataFrame) is invoked, the WebSocket
will be unassociated with this application and closed. |
void |
onConnect(WebSocket socket)
|
protected boolean |
onError(WebSocket webSocket,
Throwable t)
This method will be invoked if an unexpected exception is caught by
the WebSocket runtime.
|
void |
onExtensionNegotiation(List<Extension> extensions)
Invoked during the handshake if the client has advertised extensions
it may use and one or more extensions intersect with those returned
by
getSupportedExtensions() . |
boolean |
remove(WebSocket socket)
Unassociates the specified
WebSocket with this application. |
boolean |
upgrade(HttpRequestPacket request)
Checks protocol specific information can and should be upgraded.
|
onFragment, onFragment, onMessage, onMessage, onPing, onPong
@Deprecated public WebSocket createSocket(ProtocolHandler handler, WebSocketListener... listeners)
createSocket(ProtocolHandler, org.glassfish.grizzly.http.HttpRequestPacket, WebSocketListener...)
WebSocket
instances. Developers may
wish to override this to return customized WebSocket
implementations.handler
- the ProtocolHandler
to use with the newly created
WebSocket
.listeners
- the WebSocketListener
s to associate with the new
WebSocket
.WebSocket
instance.public WebSocket createSocket(ProtocolHandler handler, HttpRequestPacket requestPacket, WebSocketListener... listeners)
WebSocket
instances. Developers may
wish to override this to return customized WebSocket
implementations.handler
- the ProtocolHandler
to use with the newly created
WebSocket
.requestPacket
- the HttpRequestPacket
that triggered the
creation of the WebSocket
connection.listeners
- the WebSocketListener
s to associate with the new
WebSocket
.public void onClose(WebSocket socket, DataFrame frame)
WebSocket.onClose(DataFrame)
is invoked, the WebSocket
will be unassociated with this application and closed.
If this method is overridden, the overriding method must
call remove(WebSocket)
. This is necessary to ensure WebSocket
instances are not leaked nor are message operations against closed sockets
are performed.onClose
in interface WebSocketListener
onClose
in class WebSocketAdapter
socket
- the WebSocket
being closed.frame
- the closing frame.public void onConnect(WebSocket socket)
WebSocket
connection is made to this application, the
WebSocket
will be associated with this application.
If this method is overridden, the overriding method must
call add(WebSocket)
. This is necessary to ensure bulk message
sending via facilities such as Broadcaster
function properly.onConnect
in interface WebSocketListener
onConnect
in class WebSocketAdapter
socket
- the new WebSocket
connection.public void onExtensionNegotiation(List<Extension> extensions)
getSupportedExtensions()
.
The Extension
s passed to this method will include any extension
parameters included by the client. It's up to this method to re-order
and or adjust any parameter values within the list. This method must not
add any extensions that weren't originally in the list, but it is acceptable
to remove one or all extensions if for some reason they can't be supported.
If not overridden, the List will be sent as-is back to the client.extensions
- the intersection of extensions between client and
application.public final boolean upgrade(HttpRequestPacket request)
Upgrade
header with a value of WebSocket
.
If present, isApplicationRequest(org.glassfish.grizzly.http.HttpRequestPacket)
will be invoked to determine if the request is a valid websocket request.true
if the request should be upgraded to a
WebSocket connectionpublic boolean isApplicationRequest(HttpRequestPacket request)
WebSocketEngine.register(String, String, WebSocketApplication)
using standard Servlet url-pattern rules.request
- the incoming HTTP request.true
if this application can service this request
public List<Extension> getSupportedExtensions()
WebSocketApplication
.
The Extension
s added to this List
should not include
any Extension.Parameter
s as they will be ignored. This is used
exclusively for matching the requested extensions.WebSocketApplication
.public List<String> getSupportedProtocols(List<String> subProtocol)
subProtocol
- protected Set<WebSocket> getWebSockets()
WebSocket
s, registered with the application.
The returned set is unmodifiable, the possible modifications may cause exceptions.WebSocket
s, registered with the application.protected boolean add(WebSocket socket)
WebSocket
with this application.socket
- the WebSocket
to associate with this application.true
if the socket was successfully associated,
otherwise returns false
.public boolean remove(WebSocket socket)
WebSocket
with this application.socket
- the WebSocket
to unassociate with this application.true
if the socket was successfully unassociated,
otherwise returns false
.protected void handshake(HandShake handshake) throws HandshakeException
WebSocket
handshake
process has been completed, but allows the application to perform further
negotiation/validation.HandshakeException
- error occurred during the handshake.protected boolean onError(WebSocket webSocket, Throwable t)
webSocket
- the websocket being processed at the time the
exception occurred.t
- the unexpected exception.true
if the WebSocket should be closed otherwise
false
.Copyright © 2014 Oracle Corporation. All rights reserved.