org.glassfish.grizzly.samples.websockets
Class ChatApplication

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

public class ChatApplication
extends WebSocketApplication

Chat websockets based application. This WebSocketApplication customizes default WebSocket with ChatWebSocket, which includes some chat specific properties and logic.

Author:
Alexey Stashok, Justin Lee

Constructor Summary
ChatApplication()
           
 
Method Summary
 WebSocket createSocket(ProtocolHandler handler, HttpRequestPacket request, WebSocketListener... listeners)
          Creates a customized WebSocket implementation.
 boolean isApplicationRequest(HttpRequestPacket request)
          Checks application specific criteria to determine if this application can process the request as a WebSocket connection.
 void onClose(WebSocket websocket, DataFrame frame)
          When a WebSocket.onClose(DataFrame) is invoked, the WebSocket will be unassociated with this application and closed.
 void onMessage(WebSocket websocket, String data)
          Method is called, when ChatWebSocket receives a Frame.
 
Methods inherited from class org.glassfish.grizzly.websockets.WebSocketApplication
add, createSocket, getSupportedExtensions, getSupportedProtocols, getWebSockets, handshake, onConnect, onError, remove, upgrade
 
Methods inherited from class org.glassfish.grizzly.websockets.WebSocketAdapter
onFragment, onFragment, onMessage, onPing, onPong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatApplication

public ChatApplication()
Method Detail

createSocket

public WebSocket createSocket(ProtocolHandler handler,
                              HttpRequestPacket request,
                              WebSocketListener... listeners)
Creates a customized WebSocket implementation.

Overrides:
createSocket in class WebSocketApplication
Parameters:
handler - the ProtocolHandler to use with the newly created WebSocket.
request - the HttpRequestPacket that triggered the creation of the WebSocket connection.
listeners - the WebSocketListeners to associate with the new WebSocket.
Returns:
customized WebSocket implementation - ChatWebSocket

isApplicationRequest

public boolean isApplicationRequest(HttpRequestPacket request)
Description copied from class: WebSocketApplication
Checks application specific criteria to determine if this application can process the request as a WebSocket connection.

Specified by:
isApplicationRequest in class WebSocketApplication
Parameters:
request - the incoming HTTP request.
Returns:
true if this application can service this request

onMessage

public void onMessage(WebSocket websocket,
                      String data)
Method is called, when ChatWebSocket receives a Frame.

Specified by:
onMessage in interface WebSocketListener
Overrides:
onMessage in class WebSocketAdapter
Parameters:
websocket - ChatWebSocket
data - Frame
Throws:
IOException

onClose

public void onClose(WebSocket websocket,
                    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 WebSocketApplication
Parameters:
websocket - the WebSocket being closed.
frame - the closing frame.


Copyright © 2013 Oracle Corporation. All Rights Reserved.