org.glassfish.grizzly.websockets
Class WebSocketApplication<W extends WebSocket>

java.lang.Object
  extended by org.glassfish.grizzly.websockets.WebSocketApplication<W>
All Implemented Interfaces:
WebSocketHandler<W>

public abstract class WebSocketApplication<W extends WebSocket>
extends Object
implements WebSocketHandler<W>

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

Author:
Alexey Stashok
See Also:
WebSocketHandler, WebSocketClientHandler

Constructor Summary
WebSocketApplication()
           
 
Method Summary
 boolean add(W websocket)
          Add the WebSocket to the WebSocketApplication websockets list.
protected  W createWebSocket(Connection connection, ServerWebSocketMeta meta)
          Method is called before the WebSocketEngine will create a server-side WebSocket object, so application may return any customized subtype of WebSocket.
protected  Set<W> getWebSockets()
          Returns a set of WebSockets, registered with the application.
protected  void handshake(ClientWebSocketMeta websocketMeta)
          Method is called, when inital WebSocket handshake process was completed, but WebSocketApplication may perform additional validation.
 void onAccept(W websocket)
          Method is called, when new WebSocket gets accepted.
 void onClose(W websocket)
          Method is called, when WebSocket gets closed.
 boolean remove(W socket)
          Remove the WebSocket from the WebSocketApplication websockets list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.glassfish.grizzly.websockets.WebSocketHandler
onMessage
 

Constructor Detail

WebSocketApplication

public WebSocketApplication()
Method Detail

onAccept

public void onAccept(W websocket)
              throws IOException
Method is called, when new WebSocket gets accepted. Default implementation just register the passed WebSocket to a set of application associated WebSockets.

Parameters:
websocket - WebSocket
Throws:
IOException

onClose

public void onClose(W websocket)
             throws IOException
Method is called, when WebSocket gets closed.

Specified by:
onClose in interface WebSocketHandler<W extends WebSocket>
Parameters:
websocket - WebSocket
Throws:
IOException

getWebSockets

protected Set<W> 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

public boolean add(W websocket)
Add the WebSocket to the WebSocketApplication websockets list.

Parameters:
websocket - WebSocket to add.
Returns:
true, if the WebSocket was successfully added, or false otherwise.

remove

public boolean remove(W socket)
Remove the WebSocket from the WebSocketApplication websockets list.

Parameters:
socket - WebSocket to remove.
Returns:
true, if the WebSocket was succeessfully removed, or false otherwise.

handshake

protected void handshake(ClientWebSocketMeta websocketMeta)
                  throws HandshakeException
Method is called, when inital WebSocket handshake process was completed, but WebSocketApplication may perform additional validation.

Parameters:
websocketMeta - ClientWebSocketMeta.
Throws:
HandshakeException - error, occurred during the handshake.

createWebSocket

protected W createWebSocket(Connection connection,
                            ServerWebSocketMeta meta)
Method is called before the WebSocketEngine will create a server-side WebSocket object, so application may return any customized subtype of WebSocket.

Parameters:
connection - underlying Grizzly Connection.
meta - server-side ServerWebSocketMeta.
Returns:
customized WebSocket, or null, if application wants to delegate WebSocket creation to WebSocketEngine.


Copyright © 2010 Oracle Corpration. All Rights Reserved.