org.atmosphere.websocket
Class WebSocketHandler

java.lang.Object
  extended by org.atmosphere.websocket.WebSocketHandler
All Implemented Interfaces:
WebSocketProtocol

public abstract class WebSocketHandler
extends Object
implements WebSocketProtocol

A very simple interface adapter class that implements all methods and expose a WebSocket API close to the JavaScript Counterpart.

Author:
Jeanfrancois Arcand

Constructor Summary
WebSocketHandler()
           
 
Method Summary
 void configure(AtmosphereConfig config)
          Allow an implementation to query the AtmosphereConfig of init-param, etc.
 void onByteMessage(WebSocket webSocket, byte[] data, int offset, int length)
          Invoked when a byte message is received.
 void onClose(WebSocket webSocket)
          Invoked when a WebSocket is closed.
 void onError(WebSocket webSocket, WebSocketProcessor.WebSocketException t)
          Invoked when a WebSocket produces an error.
 List<AtmosphereRequest> onMessage(WebSocket webSocket, byte[] data, int offset, int length)
          Parse the WebSocket message, and delegate the processing to the AtmosphereFramework.asyncSupport or to any existing technology.
 List<AtmosphereRequest> onMessage(WebSocket webSocket, String data)
          Parse the WebSocket message, and delegate the processing to the AtmosphereFramework.asyncSupport or to any existing technology.
 void onOpen(WebSocket webSocket)
          Invoked when a WebSocket is opened.
 void onTextMessage(WebSocket webSocket, String data)
          Invoked when a String message is received
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebSocketHandler

public WebSocketHandler()
Method Detail

onByteMessage

public void onByteMessage(WebSocket webSocket,
                          byte[] data,
                          int offset,
                          int length)
Invoked when a byte message is received.

Parameters:
webSocket - a WebSocket
data -
offset -
length -

onTextMessage

public void onTextMessage(WebSocket webSocket,
                          String data)
Invoked when a String message is received

Parameters:
webSocket - a WebSocket
data -

configure

public final void configure(AtmosphereConfig config)
Description copied from interface: WebSocketProtocol
Allow an implementation to query the AtmosphereConfig of init-param, etc.

Specified by:
configure in interface WebSocketProtocol
Parameters:
config - AtmosphereConfig

onMessage

public final List<AtmosphereRequest> onMessage(WebSocket webSocket,
                                               String data)
Description copied from interface: WebSocketProtocol
Parse the WebSocket message, and delegate the processing to the AtmosphereFramework.asyncSupport or to any existing technology. Invoking AtmosphereFramework.asyncSupport will delegate the request processing to the AtmosphereHandler implementation. Returning null means this implementation will handle itself the processing/dispatching of the WebSocket's request;
As an example, this is how Websocket messages are delegated to the Jersey runtime.

Specified by:
onMessage in interface WebSocketProtocol
Parameters:
webSocket - The WebSocket connection
data - The Websocket message
Returns:
A list of AtmosphereResource, or null if the request won't be dispatched.

onMessage

public final List<AtmosphereRequest> onMessage(WebSocket webSocket,
                                               byte[] data,
                                               int offset,
                                               int length)
Description copied from interface: WebSocketProtocol
Parse the WebSocket message, and delegate the processing to the AtmosphereFramework.asyncSupport or to any existing technology. Invoking AtmosphereFramework.asyncSupport will delegate the request processing to the AtmosphereHandler implementation. Returning null means this implementation will handle itself the processing/dispatching of the WebSocket's request;
As an example, this is how Websocket messages are delegated to the Jersey runtime.

Specified by:
onMessage in interface WebSocketProtocol
Parameters:
webSocket - The WebSocket connection
offset - offset message index
length - length of the message.
Returns:
A list of AtmosphereResource, or null if the request won't be dispatched.

onOpen

public void onOpen(WebSocket webSocket)
Invoked when a WebSocket is opened.

Specified by:
onOpen in interface WebSocketProtocol
Parameters:
webSocket -

onClose

public void onClose(WebSocket webSocket)
Invoked when a WebSocket is closed.

Specified by:
onClose in interface WebSocketProtocol
Parameters:
webSocket -

onError

public void onError(WebSocket webSocket,
                    WebSocketProcessor.WebSocketException t)
Invoked when a WebSocket produces an error.

Specified by:
onError in interface WebSocketProtocol
Parameters:
webSocket -
t - a WebSocketProcessor.WebSocketException


Copyright © 2012. All Rights Reserved.