org.glassfish.grizzly.websockets
Class WebSocketApplication

java.lang.Object
  extended by org.glassfish.grizzly.websockets.WebSocketAdapter
      extended by org.glassfish.grizzly.websockets.WebSocketApplication
All Implemented Interfaces:
WebSocketListener

public abstract class WebSocketApplication
extends WebSocketAdapter

Abstract server-side WebSocket application, which will handle application WebSockets events.

Author:
Alexey Stashok

Constructor Summary
WebSocketApplication()
           
 
Method Summary
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)
          Deprecated. Use createSocket(ProtocolHandler, org.glassfish.grizzly.http.HttpRequestPacket, WebSocketListener...)
 List<String> getSupportedExtensions()
          Return the websocket extensions supported by this WebSocketApplication.
 List<String> getSupportedProtocols(List<String> subProtocol)
           
protected  Set<WebSocket> getWebSockets()
          Returns a set of WebSockets, 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.
abstract  boolean isApplicationRequest(HttpRequestPacket request)
          Checks application specific criteria to determine if this application can process the request as a WebSocket connection.
 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)
          When a new WebSocket connection is made to this application, the WebSocket will be associated with this application.
protected  boolean onError(WebSocket webSocket, Throwable t)
          This method will be invoked if an unexpected exception is caught by the WebSocket runtime.
 boolean remove(WebSocket socket)
          Unassociates the specified WebSocket with this application.
 boolean upgrade(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebSocketApplication

public WebSocketApplication()
Method Detail

createSocket

@Deprecated
public WebSocket createSocket(ProtocolHandler handler,
                                         WebSocketListener... listeners)
Deprecated. Use createSocket(ProtocolHandler, org.glassfish.grizzly.http.HttpRequestPacket, WebSocketListener...)

Factory method to create new WebSocket instances. Developers may wish to override this to return customized WebSocket implementations.

Parameters:
handler - the ProtocolHandler to use with the newly created WebSocket.
listeners - the WebSocketListeners to associate with the new WebSocket.
Returns:
a new WebSocket instance.

createSocket

public WebSocket createSocket(ProtocolHandler handler,
                              HttpRequestPacket requestPacket,
                              WebSocketListener... listeners)
Factory method to create new WebSocket instances. Developers may wish to override this to return customized WebSocket implementations.

Parameters:
handler - the ProtocolHandler to use with the newly created WebSocket.
requestPacket - the HttpRequestPacket that triggered the creation of the WebSocket connection.
listeners - the WebSocketListeners to associate with the new WebSocket.
Returns:

onClose

public void onClose(WebSocket socket,
                    DataFrame frame)
When a WebSocket.onClose(DataFrame) is invoked, the WebSocket will be unassociated with this application and closed.

Specified by:
onClose in interface WebSocketListener
Overrides:
onClose in class WebSocketAdapter
Parameters:
socket - the WebSocket being closed.
frame - the closing frame.

onConnect

public void onConnect(WebSocket socket)
When a new WebSocket connection is made to this application, the WebSocket will be associated with this application.

Specified by:
onConnect in interface WebSocketListener
Overrides:
onConnect in class WebSocketAdapter
Parameters:
socket - the new WebSocket connection.

upgrade

public final boolean upgrade(HttpRequestPacket request)
Checks protocol specific information can and should be upgraded. The default implementation will check for the precence of the 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.

Returns:
true if the request should be upgraded to a WebSocket connection

isApplicationRequest

public abstract boolean isApplicationRequest(HttpRequestPacket request)
Checks application specific criteria to determine if this application can process the request as a WebSocket connection.

Parameters:
request - the incoming HTTP request.
Returns:
true if this application can service this request

getSupportedExtensions

public List<String> getSupportedExtensions()
Return the websocket extensions supported by this WebSocketApplication.

Returns:
the websocket extensions supported by this WebSocketApplication.

getSupportedProtocols

public List<String> getSupportedProtocols(List<String> subProtocol)
Parameters:
subProtocol -
Returns:

getWebSockets

protected Set<WebSocket> getWebSockets()
Returns a set of WebSockets, 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

protected boolean add(WebSocket socket)
Associates the specified WebSocket with this application.

Parameters:
socket - the WebSocket to associate with this application.
Returns:
true if the socket was successfully associated, otherwise returns false.

remove

public boolean remove(WebSocket socket)
Unassociates the specified WebSocket with this application.

Parameters:
socket - the WebSocket to unassociate with this application.
Returns:
true if the socket was successfully unassociated, otherwise returns false.

handshake

protected void handshake(HandShake handshake)
                  throws HandshakeException
This method will be called, when initial WebSocket handshake process has been completed, but allows the application to perform further negotiation/validation.

Throws:
HandshakeException - error occurred during the handshake.

onError

protected boolean onError(WebSocket webSocket,
                          Throwable t)
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:
true if the WebSocket should be closed otherwise false.


Copyright © 2012 Oracle Corporation. All Rights Reserved.