org.atmosphere.cpr
Interface AtmosphereHandler<F,G>

All Known Subinterfaces:
AtmosphereServletProcessor
All Known Implementing Classes:
AbstractReflectorAtmosphereHandler, ReflectorServletProcessor, SimpleWebSocketAtmosphereHandler

public interface AtmosphereHandler<F,G>

Implementation of AtmosphereHandler allows creation of event-driven web applications which are hosted in the browser. An AtmosphereHandler allows a web application to suspend and resume an http response. An http response can be suspended AtmosphereResource.suspend() and later resume via AtmosphereResource.resume(). Messages can also be shared between suspended response and their associated AtmosphereHandler using a Broadcaster. Any invocation of Broadcaster.broadcast(java.lang.Object) will allow a suspended response to write the content of the message onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent).

A class implementing AtmosphereHandler must be thread safe

For example, a simple pubsub based AtmosphereHandler will take the form of

 public class AtmosphereHandlerPubSub extends AbstractReflectorAtmosphereHandler {

Author:
Jeanfrancois Arcand

Method Summary
 void destroy()
          Destroy this handler
 void onRequest(AtmosphereResource<F,G> resource)
          When a client send 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 onStateChange(AtmosphereResourceEvent<F,G> event)
          This method is invoked when the Broadcaster execute a broadcast operations.
 

Method Detail

onRequest

void onRequest(AtmosphereResource<F,G> resource)
               throws IOException
When a client send 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 request 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

void onStateChange(AtmosphereResourceEvent<F,G> event)
                   throws IOException
This method is invoked when the Broadcaster execute a broadcast operations. When this method is invoked its associated Broadcaster, any suspended connection will be allowed to write the data back to its associated clients.
This method will also be invoked when a response get resumed, e.g. when AtmosphereResource.resume() gets invoked. In that case, AtmosphereResourceEvent.isResuming() will return true.
This method will also be invoked when the AtmosphereResource.suspend(long) expires. In that case, AtmosphereResourceEvent.isResumedOnTimeout() will return true

Parameters:
event - an AtmosphereResourceEvent
Throws:
IOException

destroy

void destroy()
Destroy this handler



Copyright © 2012. All Rights Reserved.