org.atmosphere.handler
Class OnMessage<T>

java.lang.Object
  extended by org.atmosphere.handler.AbstractReflectorAtmosphereHandler
      extended by org.atmosphere.handler.OnMessage<T>
All Implemented Interfaces:
AtmosphereHandler

public abstract class OnMessage<T>
extends AbstractReflectorAtmosphereHandler

Simple AtmosphereHandler that must be used with the AtmosphereResourceLifecycleInterceptor and BroadcastOnPostAtmosphereInterceptor to reduce the handling of the suspend/resume/disconnect and broadcast operation.

You can also safely used this class with BroadcasterCache. method

Author:
Jeanfrancois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from class org.atmosphere.handler.AbstractReflectorAtmosphereHandler
AbstractReflectorAtmosphereHandler.Default
 
Field Summary
static String MESSAGE_DELIMITER
           
 
Constructor Summary
OnMessage()
           
 
Method Summary
 void destroy()
          Destroy this handler
 void onDisconnect(AtmosphereResponse response)
          This method will be invoked when the underlying WebServer detects a connection has been closed.
abstract  void onMessage(AtmosphereResponse response, T message)
          Implement this method to get invoked every time a new Broadcaster.broadcast(Object) occurs.
 void onOpen(AtmosphereResource resource)
          This method will be invoked when an connection has been received and not haven't yet be suspended.
 void onRequest(AtmosphereResource resource)
          When a client sends a request to its associated AtmosphereHandler, it can decide if the underlying connection can be suspended (creating a Continuation) or handle the connection synchronously.
 void onResume(AtmosphereResponse response)
          This method will be invoked during the process of resuming a connection.
 void onStateChange(AtmosphereResourceEvent event)
          Write the AtmosphereResourceEvent.getMessage() back to the client using the AtmosphereResponse.getOutputStream() or AtmosphereResponse.getWriter().
 void onTimeout(AtmosphereResponse response)
          This method will be invoked when a suspended connection times out, e.g no activity has occurred for the specified time used when suspending.
 
Methods inherited from class org.atmosphere.handler.AbstractReflectorAtmosphereHandler
postStateChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_DELIMITER

public static final String MESSAGE_DELIMITER
See Also:
Constant Field Values
Constructor Detail

OnMessage

public OnMessage()
Method Detail

onRequest

public final void onRequest(AtmosphereResource resource)
                     throws IOException
Description copied from interface: AtmosphereHandler
When a client sends a request to its associated AtmosphereHandler, it can decide if the underlying connection can be suspended (creating a Continuation) or handle the connection synchronously.

It is recommended to only suspend requests for which HTTP method is a GET and use the POST method to send data to the server, without marking the connection as asynchronous.

Parameters:
resource - an AtmosphereResource
Throws:
IOException

onStateChange

public final void onStateChange(AtmosphereResourceEvent event)
                         throws IOException
Description copied from class: AbstractReflectorAtmosphereHandler
Write the AtmosphereResourceEvent.getMessage() back to the client using the AtmosphereResponse.getOutputStream() or AtmosphereResponse.getWriter(). If a Serializer is defined, it will be invoked and the write operation will be delegated to it.

By default, this method will try to use AtmosphereResponse.getWriter().

Specified by:
onStateChange in interface AtmosphereHandler
Overrides:
onStateChange in class AbstractReflectorAtmosphereHandler
Parameters:
event - the AtmosphereResourceEvent.getMessage()
Throws:
IOException

destroy

public final void destroy()
Description copied from interface: AtmosphereHandler
Destroy this handler

Specified by:
destroy in interface AtmosphereHandler
Overrides:
destroy in class AbstractReflectorAtmosphereHandler

onOpen

public void onOpen(AtmosphereResource resource)
            throws IOException
This method will be invoked when an connection has been received and not haven't yet be suspended. Note that the connection will be suspended AFTER the method has been invoked when used with AtmosphereResourceLifecycleInterceptor

Parameters:
resource - an AtmosphereResource
Throws:
IOException

onMessage

public abstract void onMessage(AtmosphereResponse response,
                               T message)
                        throws IOException
Implement this method to get invoked every time a new Broadcaster.broadcast(Object) occurs.

Parameters:
response - an AtmosphereResponse
message - a message of type T
Throws:
IOException

onResume

public void onResume(AtmosphereResponse response)
              throws IOException
This method will be invoked during the process of resuming a connection. By default this method does nothing.

Parameters:
response - an AtmosphereResponse.
Throws:
IOException

onTimeout

public void onTimeout(AtmosphereResponse response)
               throws IOException
This method will be invoked when a suspended connection times out, e.g no activity has occurred for the specified time used when suspending. By default this method does nothing.

Parameters:
response - an AtmosphereResponse.
Throws:
IOException

onDisconnect

public void onDisconnect(AtmosphereResponse response)
                  throws IOException
This method will be invoked when the underlying WebServer detects a connection has been closed. Please note that not all WebServer supports that features (see Atmosphere's WIKI for help). By default this method does nothing.

Parameters:
response - an AtmosphereResponse.
Throws:
IOException


Copyright © 2014. All Rights Reserved.