Package org.atmosphere.handler
Class OnMessage<T>
- java.lang.Object
-
- org.atmosphere.handler.AbstractReflectorAtmosphereHandler
-
- org.atmosphere.handler.OnMessage<T>
-
- All Implemented Interfaces:
AtmosphereHandler,AtmosphereServletProcessor
public abstract class OnMessage<T> extends AbstractReflectorAtmosphereHandler
SimpleAtmosphereHandlerthat must be used with theAtmosphereResourceLifecycleInterceptorandBroadcastOnPostAtmosphereInterceptorto reduce the handling of the suspend/resume/disconnect and broadcast operation. You can also safely used this class withBroadcasterCache. method- Author:
- Jeanfrancois Arcand
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.atmosphere.handler.AbstractReflectorAtmosphereHandler
AbstractReflectorAtmosphereHandler.Default
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMESSAGE_DELIMITER
-
Constructor Summary
Constructors Constructor Description OnMessage()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddestroy()Destroy this handlervoidonDisconnect(AtmosphereResponse response)This method will be invoked when the underlying WebServer detects a connection has been closed.abstract voidonMessage(AtmosphereResponse response, T message)Implement this method to get invoked every time a newBroadcaster.broadcast(Object)occurs.voidonOpen(AtmosphereResource resource)This method will be invoked when an connection has been received and not haven't yet be suspended.voidonRequest(AtmosphereResource resource)When a client sends a request to its associatedAtmosphereHandler, it can decide if the underlying connection can be suspended (creating a Continuation) or handle the connection synchronously.voidonResume(AtmosphereResponse response)This method will be invoked during the process of resuming a connection.voidonStateChange(AtmosphereResourceEvent event)Write theAtmosphereResourceEvent.getMessage()back to the client using theAtmosphereResponseImpl.getOutputStream()orAtmosphereResponseImpl.getWriter().voidonTimeout(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
init, postStateChange, useTwoStepWrite, write
-
-
-
-
Field Detail
-
MESSAGE_DELIMITER
public static final java.lang.String MESSAGE_DELIMITER
- See Also:
- Constant Field Values
-
-
Method Detail
-
onRequest
public final void onRequest(AtmosphereResource resource) throws java.io.IOException
Description copied from interface:AtmosphereHandlerWhen a client sends a request to its associatedAtmosphereHandler, 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- anAtmosphereResource- Throws:
java.io.IOException
-
onStateChange
public final void onStateChange(AtmosphereResourceEvent event) throws java.io.IOException
Description copied from class:AbstractReflectorAtmosphereHandlerWrite theAtmosphereResourceEvent.getMessage()back to the client using theAtmosphereResponseImpl.getOutputStream()orAtmosphereResponseImpl.getWriter(). If aSerializeris defined, it will be invoked and the write operation will be delegated to it. By default, this method will try to useAtmosphereResponseImpl.getWriter().- Specified by:
onStateChangein interfaceAtmosphereHandler- Overrides:
onStateChangein classAbstractReflectorAtmosphereHandler- Parameters:
event- theAtmosphereResourceEvent.getMessage()- Throws:
java.io.IOException
-
destroy
public final void destroy()
Description copied from interface:AtmosphereHandlerDestroy this handler- Specified by:
destroyin interfaceAtmosphereHandler- Overrides:
destroyin classAbstractReflectorAtmosphereHandler
-
onOpen
public void onOpen(AtmosphereResource resource) throws java.io.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 withAtmosphereResourceLifecycleInterceptor- Parameters:
resource- anAtmosphereResource- Throws:
java.io.IOException
-
onMessage
public abstract void onMessage(AtmosphereResponse response, T message) throws java.io.IOException
Implement this method to get invoked every time a newBroadcaster.broadcast(Object)occurs.- Parameters:
response- anAtmosphereResponsemessage- a message of type T- Throws:
java.io.IOException
-
onResume
public void onResume(AtmosphereResponse response) throws java.io.IOException
This method will be invoked during the process of resuming a connection. By default this method does nothing.- Parameters:
response- anAtmosphereResponse.- Throws:
java.io.IOException
-
onTimeout
public void onTimeout(AtmosphereResponse response) throws java.io.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- anAtmosphereResponse.- Throws:
java.io.IOException
-
onDisconnect
public void onDisconnect(AtmosphereResponse response) throws java.io.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- anAtmosphereResponse.- Throws:
java.io.IOException
-
-