-
-
Notifications
You must be signed in to change notification settings - Fork 751
Understanding AtmosphereHandler
An AtmosphereHandler is the central concept of an Atmosphere Framework application. AtmosphereHandler are the lowest component an application can implement. For example, the atmosphere-jersey and atmosphere-gwt build on top of AtmosphereHandler. The interface is defined as:
public interface AtmosphereHandler {
/**
* 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.
*/
void onRequest(AtmosphereResource resource) 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
*
*/
void onStateChange(AtmosphereResourceEvent event) throws IOException;
/**
* Destroy this handler
*/
void destroy();
}
The AtmosphereHandler.onRequest is invoked every time a new connection is made to an application. An application must take action and decide what to do with the AtmosphereResource, e.g. suspend, resume or broadcast events. You can also write String or bytes back to the client from that method.
This method gets invoked when:
- The remote connection gets closed, either by a browser or a proxy
- The remote connection reach its maximum idle time (AtmosphereResource.suspend)
- Everytime a broadcast operation is executed (broadcaster.broadcast)
When the Atmosphere Framework is stopped.
The framework ships with some AtmosphereHandler implementation that can be extended easily:
- AbstractReflectorAtmosphereHandler : contains an implementation of the onStateChanged method.
- ReflectorServletProcessor : used by the framework to support Servlet Based Technology like Jersey, Wicket, Grails, etc.
- SimpleWebSocketAtmosphereHandler: A very simple handler for implementing WebSocket. It is recommended to use the WebSocketHandler API instead of AtmosphereHandler if you are planning to write pure WebSockets applications.
To get started, read this document
- Understanding Atmosphere
- Understanding @ManagedService
- Using javax.inject.Inject and javax.inject.PostConstruct annotation
- Understanding Atmosphere's Annotation
- Understanding AtmosphereResource
- Understanding AtmosphereHandler
- Understanding WebSocketHandler
- Understanding Broadcaster
- Understanding BroadcasterCache
- Understanding Meteor
- Understanding BroadcastFilter
- Understanding Atmosphere's Events Listeners
- Understanding AtmosphereInterceptor
- Configuring Atmosphere for Performance
- Understanding JavaScript functions
- Understanding AtmosphereResourceSession
- Improving Performance by using the PoolableBroadcasterFactory
- Using Atmosphere Jersey API
- Using Meteor API
- Using AtmosphereHandler API
- Using Socket.IO
- Using GWT
- Writing HTML5 Server-Sent Events
- Using STOMP protocol
- Streaming WebSocket messages
- Configuring Atmosphere's Classes Creation and Injection
- Using AtmosphereInterceptor to customize Atmosphere Framework
- Writing WebSocket sub protocol
- Configuring Atmosphere for the Cloud
- Injecting Atmosphere's Components in Jersey
- Sharing connection between Browser's windows and tabs
- Understanding AtmosphereResourceSession
- Manage installed services
- Server Side: javadoc API
- Server Side: atmosphere.xml and web.xml configuration
- Client Side: atmosphere.js API