org.atmosphere.websocket.protocol
Class EchoProtocol

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

public class EchoProtocol
extends Object
implements WebSocketProtocol

Simple WebSocketProcessor that invoke the Broadcaster.broadcast(T) API when a WebSocket message is received.

NOTE: If WebSocket frame are used the bytes will be decoded into a String, which reduce performance.

Author:
Jeanfrancois Arcand

Constructor Summary
EchoProtocol()
           
 
Method Summary
 void configure(AtmosphereConfig config)
          Allow an implementation to query the AtmosphereConfig of init-param, etc.
 void onClose(WebSocket webSocket)
          Invoked when a WebSocket is closed
 void onError(WebSocket webSocket, WebSocketProcessor.WebSocketException t)
          Invoked when an error occurs.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EchoProtocol

public EchoProtocol()
Method Detail

onMessage

public List<AtmosphereRequest> onMessage(WebSocket webSocket,
                                         String data)
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 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. 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.

configure

public void configure(AtmosphereConfig config)
Allow an implementation to query the AtmosphereConfig of init-param, etc.

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

onOpen

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

Specified by:
onOpen in interface WebSocketProtocol
Parameters:
webSocket - WebSocket

onClose

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

Specified by:
onClose in interface WebSocketProtocol
Parameters:
webSocket - WebSocket

onError

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

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


Copyright © 2013. All Rights Reserved.