Package org.glassfish.grizzly.websockets
Class WebSocketApplication
java.lang.Object
org.glassfish.grizzly.websockets.WebSocketAdapter
org.glassfish.grizzly.websockets.WebSocketApplication
- All Implemented Interfaces:
WebSocketListener
- Author:
- Alexey Stashok
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanAssociates the specifiedWebSocketwith this application.createSocket(ProtocolHandler handler, org.glassfish.grizzly.http.HttpRequestPacket requestPacket, WebSocketListener... listeners) Factory method to create newWebSocketinstances.createSocket(ProtocolHandler handler, WebSocketListener... listeners) Deprecated.Return the websocket extensions supported by thisWebSocketApplication.getSupportedProtocols(List<String> subProtocol) Returns a set ofWebSockets, registered with the application.protected voidThis method will be called, when initialWebSockethandshake process has been completed, but allows the application to perform further negotiation/validation.booleanisApplicationRequest(org.glassfish.grizzly.http.HttpRequestPacket request) Deprecated.URI mapping shouldn't be intrinsic to the application.voidWhen aWebSocket.onClose(DataFrame)is invoked, theWebSocketwill be unassociated with this application and closed.voidprotected booleanThis method will be invoked if an unexpected exception is caught by the WebSocket runtime.voidonExtensionNegotiation(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 bygetSupportedExtensions().booleanUnassociates the specifiedWebSocketwith this application.final booleanupgrade(org.glassfish.grizzly.http.HttpRequestPacket request) Checks protocol specific information can and should be upgraded.Methods inherited from class org.glassfish.grizzly.websockets.WebSocketAdapter
onFragment, onFragment, onMessage, onMessage, onPing, onPong
-
Field Details
-
sockets
-
-
Constructor Details
-
WebSocketApplication
public WebSocketApplication()
-
-
Method Details
-
createSocket
Deprecated.Factory method to create newWebSocketinstances. Developers may wish to override this to return customizedWebSocketimplementations.- Parameters:
handler- theProtocolHandlerto use with the newly createdWebSocket.listeners- theWebSocketListeners to associate with the newWebSocket.- Returns:
- a new
WebSocketinstance.
-
createSocket
public WebSocket createSocket(ProtocolHandler handler, org.glassfish.grizzly.http.HttpRequestPacket requestPacket, WebSocketListener... listeners) Factory method to create newWebSocketinstances. Developers may wish to override this to return customizedWebSocketimplementations.- Parameters:
handler- theProtocolHandlerto use with the newly createdWebSocket.requestPacket- theHttpRequestPacketthat triggered the creation of theWebSocketconnection.listeners- theWebSocketListeners to associate with the newWebSocket.- Returns:
-
onClose
When aWebSocket.onClose(DataFrame)is invoked, theWebSocketwill be unassociated with this application and closed. If this method is overridden, the overriding method must callremove(WebSocket). This is necessary to ensure WebSocket instances are not leaked nor are message operations against closed sockets are performed.- Specified by:
onClosein interfaceWebSocketListener- Overrides:
onClosein classWebSocketAdapter- Parameters:
socket- theWebSocketbeing closed.frame- the closing frame.
-
onConnect
When a newWebSocketconnection is made to this application, theWebSocketwill be associated with this application. If this method is overridden, the overriding method must calladd(WebSocket). This is necessary to ensure bulk message sending via facilities such asBroadcasterfunction properly.- Specified by:
onConnectin interfaceWebSocketListener- Overrides:
onConnectin classWebSocketAdapter- Parameters:
socket- the newWebSocketconnection.
-
onExtensionNegotiation
Invoked during the handshake if the client has advertised extensions it may use and one or more extensions intersect with those returned bygetSupportedExtensions(). TheExtensions 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.- Parameters:
extensions- the intersection of extensions between client and application.- Since:
- 2.3
-
upgrade
public final boolean upgrade(org.glassfish.grizzly.http.HttpRequestPacket request) Checks protocol specific information can and should be upgraded. The default implementation will check for the presence of theUpgradeheader with a value ofWebSocket. If present,isApplicationRequest(org.glassfish.grizzly.http.HttpRequestPacket)will be invoked to determine if the request is a valid websocket request.- Returns:
trueif the request should be upgraded to a WebSocket connection
-
isApplicationRequest
public boolean isApplicationRequest(org.glassfish.grizzly.http.HttpRequestPacket request) Deprecated.URI mapping shouldn't be intrinsic to the application. WebSocketApplications should be registered usingWebSocketEngine.register(String, String, WebSocketApplication)using standard Servlet url-pattern rules.Checks application specific criteria to determine if this application can process the request as a WebSocket connection.- Parameters:
request- the incoming HTTP request.- Returns:
trueif this application can service this request
-
getSupportedExtensions
Return the websocket extensions supported by thisWebSocketApplication. TheExtensions added to thisListshould not include anyExtension.Parameters as they will be ignored. This is used exclusively for matching the requested extensions.- Returns:
- the websocket extensions supported by this
WebSocketApplication.
-
getSupportedProtocols
- Parameters:
subProtocol-- Returns:
-
getWebSockets
Returns a set ofWebSockets, registered with the application. The returned set is unmodifiable, the possible modifications may cause exceptions.- Returns:
- a set of
WebSockets, registered with the application.
-
add
Associates the specifiedWebSocketwith this application.- Parameters:
socket- theWebSocketto associate with this application.- Returns:
trueif the socket was successfully associated, otherwise returnsfalse.
-
remove
Unassociates the specifiedWebSocketwith this application.- Parameters:
socket- theWebSocketto unassociate with this application.- Returns:
trueif the socket was successfully unassociated, otherwise returnsfalse.
-
handshake
This method will be called, when initialWebSockethandshake process has been completed, but allows the application to perform further negotiation/validation.- Throws:
HandshakeException- error occurred during the handshake.
-
onError
This method will be invoked if an unexpected exception is caught by the WebSocket runtime.- Parameters:
webSocket- the websocket being processed at the time the exception occurred.t- the unexpected exception.- Returns:
trueif the WebSocket should be closed otherwisefalse.
-
createSocket(ProtocolHandler, org.glassfish.grizzly.http.HttpRequestPacket, WebSocketListener...)