org.atmosphere.websocket
Class DefaultWebSocketProcessor

java.lang.Object
  extended by org.atmosphere.websocket.DefaultWebSocketProcessor
All Implemented Interfaces:
Serializable, WebSocketProcessor

public class DefaultWebSocketProcessor
extends Object
implements WebSocketProcessor, Serializable

Like the AsynchronousProcessor class, this class is responsible for dispatching WebSocket request to the proper WebSocket implementation. This class can be extended in order to support any protocol running on top websocket.

Author:
Jeanfrancois Arcand
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.atmosphere.websocket.WebSocketProcessor
WebSocketProcessor.WebSocketException, WebSocketProcessor.WebSocketHandlerProxy
 
Constructor Summary
DefaultWebSocketProcessor(AtmosphereFramework framework)
           
 
Method Summary
 void close(WebSocket webSocket, int closeCode)
          Invked when the WebServer is closing the native WebSocket
static Map<String,String> configureHeader(AtmosphereRequest request)
           
 void destroy()
          Destroy all resources associated with this class.
 void dispatch(WebSocket webSocket, AtmosphereRequest request, AtmosphereResponse r)
          Dispatch to request/response to the AsyncSupport implementation as it was a normal HTTP request.
protected  void dispatchReader(WebSocket webSocket, Reader r)
           
protected  void dispatchStream(WebSocket webSocket, InputStream is)
           
 void executeClose(AsynchronousProcessor.AsynchronousProcessorHook h, WebSocket webSocket, int closeCode)
           
 int getByteBufferMaxSize()
          Obtain the current maximum size (in bytes) of the buffer used for binary messages.
 int getCharBufferMaxSize()
          Obtain the current maximum size (in characters) of the buffer used for binary messages.
 boolean handshake(javax.servlet.http.HttpServletRequest request)
          Determine if the WebSocket's handshake data can be processed, or if the request be cancelled.
 void invokeWebSocketProtocol(WebSocket webSocket, byte[] data, int offset, int length)
          Invoked when a WebSocket message gets received from the underlying container
 void invokeWebSocketProtocol(WebSocket webSocket, InputStream stream)
          Invoked when a WebSocket message gets received from the underlying container
 void invokeWebSocketProtocol(WebSocket webSocket, Reader reader)
          Invoked when a WebSocket message gets received from the underlying container
 void invokeWebSocketProtocol(WebSocket webSocket, String webSocketMessage)
          Invoked when a WebSocket message gets received from the underlying container
 void notifyListener(WebSocket webSocket, WebSocketEventListener.WebSocketEvent event)
          Notify all WebSocketEventListener
 void open(WebSocket webSocket, AtmosphereRequest request, AtmosphereResponse response)
          Invoked when a WebSocket gets opened by the underlying container
protected  void optimizeMapping()
           
protected  WebSocketHandler postProcessMapping(WebSocket webSocket, AtmosphereRequest request, WebSocketProcessor.WebSocketHandlerProxy w)
           
 WebSocketProcessor registerWebSocketHandler(String path, WebSocketProcessor.WebSocketHandlerProxy webSockethandler)
          Register a WebSocketHandler
 void setByteBufferMaxSize(int byteBufferMaxSize)
          Set the maximum size (in bytes) of the buffer used for binary messages.
 void setCharBufferMaxSize(int charBufferMaxSize)
          Set the maximum size (in characters) of the buffer used for textual messages.
 boolean wildcardMapping()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultWebSocketProcessor

public DefaultWebSocketProcessor(AtmosphereFramework framework)
Method Detail

handshake

public boolean handshake(javax.servlet.http.HttpServletRequest request)
Description copied from interface: WebSocketProcessor
Determine if the WebSocket's handshake data can be processed, or if the request be cancelled. Since it's container related native API, the HttpServletRequest might be null, so implementation must check for null.

Specified by:
handshake in interface WebSocketProcessor
Parameters:
request - HttpServletRequest
Returns:
true if the processing can continue, false if not.

registerWebSocketHandler

public WebSocketProcessor registerWebSocketHandler(String path,
                                                   WebSocketProcessor.WebSocketHandlerProxy webSockethandler)
Description copied from interface: WebSocketProcessor
Register a WebSocketHandler

Specified by:
registerWebSocketHandler in interface WebSocketProcessor
Parameters:
path - the URI mapping the WebSocketHandler
webSockethandler - an instance of WebSocketProcessor.WebSocketHandlerProxy
Returns:
this

open

public final void open(WebSocket webSocket,
                       AtmosphereRequest request,
                       AtmosphereResponse response)
                throws IOException
Description copied from interface: WebSocketProcessor
Invoked when a WebSocket gets opened by the underlying container

Specified by:
open in interface WebSocketProcessor
Throws:
IOException

postProcessMapping

protected WebSocketHandler postProcessMapping(WebSocket webSocket,
                                              AtmosphereRequest request,
                                              WebSocketProcessor.WebSocketHandlerProxy w)

invokeWebSocketProtocol

public void invokeWebSocketProtocol(WebSocket webSocket,
                                    String webSocketMessage)
Description copied from interface: WebSocketProcessor
Invoked when a WebSocket message gets received from the underlying container

Specified by:
invokeWebSocketProtocol in interface WebSocketProcessor

invokeWebSocketProtocol

public void invokeWebSocketProtocol(WebSocket webSocket,
                                    byte[] data,
                                    int offset,
                                    int length)
Description copied from interface: WebSocketProcessor
Invoked when a WebSocket message gets received from the underlying container

Specified by:
invokeWebSocketProtocol in interface WebSocketProcessor

invokeWebSocketProtocol

public void invokeWebSocketProtocol(WebSocket webSocket,
                                    InputStream stream)
Description copied from interface: WebSocketProcessor
Invoked when a WebSocket message gets received from the underlying container

Specified by:
invokeWebSocketProtocol in interface WebSocketProcessor

invokeWebSocketProtocol

public void invokeWebSocketProtocol(WebSocket webSocket,
                                    Reader reader)
Description copied from interface: WebSocketProcessor
Invoked when a WebSocket message gets received from the underlying container

Specified by:
invokeWebSocketProtocol in interface WebSocketProcessor

dispatch

public final void dispatch(WebSocket webSocket,
                           AtmosphereRequest request,
                           AtmosphereResponse r)
Dispatch to request/response to the AsyncSupport implementation as it was a normal HTTP request.

Parameters:
request - a AtmosphereRequest
r - a AtmosphereResponse

close

public void close(WebSocket webSocket,
                  int closeCode)
Description copied from interface: WebSocketProcessor
Invked when the WebServer is closing the native WebSocket

Specified by:
close in interface WebSocketProcessor

executeClose

public void executeClose(AsynchronousProcessor.AsynchronousProcessorHook h,
                         WebSocket webSocket,
                         int closeCode)

destroy

public void destroy()
Description copied from interface: WebSocketProcessor
Destroy all resources associated with this class.

Specified by:
destroy in interface WebSocketProcessor

notifyListener

public void notifyListener(WebSocket webSocket,
                           WebSocketEventListener.WebSocketEvent event)
Description copied from interface: WebSocketProcessor
Notify all WebSocketEventListener

Specified by:
notifyListener in interface WebSocketProcessor

configureHeader

public static final Map<String,String> configureHeader(AtmosphereRequest request)

dispatchStream

protected void dispatchStream(WebSocket webSocket,
                              InputStream is)
                       throws IOException
Throws:
IOException

dispatchReader

protected void dispatchReader(WebSocket webSocket,
                              Reader r)
                       throws IOException
Throws:
IOException

getByteBufferMaxSize

public final int getByteBufferMaxSize()
Obtain the current maximum size (in bytes) of the buffer used for binary messages.


setByteBufferMaxSize

public final void setByteBufferMaxSize(int byteBufferMaxSize)
Set the maximum size (in bytes) of the buffer used for binary messages.


getCharBufferMaxSize

public final int getCharBufferMaxSize()
Obtain the current maximum size (in characters) of the buffer used for binary messages.


setCharBufferMaxSize

public final void setCharBufferMaxSize(int charBufferMaxSize)
Set the maximum size (in characters) of the buffer used for textual messages.


optimizeMapping

protected void optimizeMapping()

wildcardMapping

public boolean wildcardMapping()


Copyright © 2014. All Rights Reserved.