-
-
Notifications
You must be signed in to change notification settings - Fork 753
Configuring Atmosphere Listener
The AtmosphereFramework supports several events listener that can be used to monitor when a connection gets suspended, resumed, timed out or cancelled. Those listeners can be used to track and clean state associated with a connection.
You can configure AsyncSupportListener by implementing the interface and by annotating it using an AsyncSupportListenerService annotation. The interface is defined as:
public interface AsyncSupportListener {
/**
* Invoked when an AtmosphereResource gets suspended.
* @param request an AtmosphereRequest
* @param response an AtmosphereResponse
*/
void onSuspend(AtmosphereRequest request, AtmosphereResponse response);
/**
* Invoked when an AtmosphereResource gets resumed
* @param request an AtmosphereRequest
* @param response an AtmosphereResponse
*/
void onResume(AtmosphereRequest request, AtmosphereResponse response);
/**
* Invoked when an AtmosphereResource gets timed out
* @param request an AtmosphereRequest
* @param response an AtmosphereResponse
*/
void onTimeout(AtmosphereRequest request, AtmosphereResponse response);
/**
* Invoked when an AtmosphereResource gets closed
* @param request an AtmosphereRequest
* @param response an AtmosphereResponse
*/
void onClose(AtmosphereRequest request, AtmosphereResponse response);
/**
* Invoked when an AtmosphereResource gets destroyed
* @param request an AtmosphereRequest
* @param response an AtmosphereResponse
*/
void onDestroyed(AtmosphereRequest request, AtmosphereResponse response);
}
If you are using Atmosphere's Runtime module and have implemented an AtmosphereHandler, you can add an AtmosphereResourceEventListener
public interface AtmosphereResourceEventListener {
/**
* Invoked when the AtmosphereResource#suspend has been completed and the response
* considered as suspended.
*
* @param event a org.atmosphere.cpr.AtmosphereResourceEvent
*/
void onSuspend(AtmosphereResourceEvent event);
/**
* Invoked when the AtmosphereResource#resume is invoked or when the
* suspend's time out expires.
*
* @param event a org.atmosphere.cpr.AtmosphereResourceEvent
*/
void onResume(AtmosphereResourceEvent event);
/**
* Invoked when the remote connection gets closed.
*
* @param event a org.atmosphere.cpr.AtmosphereResourceEvent
*/
void onDisconnect(AtmosphereResourceEvent event);
/**
* Invoked when a Broadcaster#broadcast occurs.
*
* @param event a org.atmosphere.cpr.AtmosphereResourceEvent
*/
void onBroadcast(AtmosphereResourceEvent event);
/**
* Invoked when an operations failed to execute for an unknown reason like : IOException because the client
* remotely closed the connection, a broken connection, etc.
*
* @param event a org.atmosphere.cpr.AtmosphereResourceEvent
*/
void onThrowable(AtmosphereResourceEvent event);
}
to your AtmosphereResource by simply doing:
atmosphereResource.addEventListener( new AtmosphereResourceEventListenerAdapter() {} );
If your application supports WebSocket, you can add a specialized WebSocketEventListener:
public interface WebSocketEventListener extends AtmosphereResourceEventListener{
/**
* When the hanshake occurs
* @param event WebSocketEvent
*/
void onHandshake(WebSocketEvent event);
/**
* When a message is sent
* @param event WebSocketEvent
*/
void onMessage(WebSocketEvent event);
/**
* When the close occurs
* @param event WebSocketEvent
*/
void onClose(WebSocketEvent event);
/**
* When the control occurs
* @param event WebSocketEvent
*/
void onControl(WebSocketEvent event);
/**
* When the disconnect occurs
* @param event WebSocketEvent
*/
void onDisconnect(WebSocketEvent event);
/**
* When the connect occurs
* @param event WebSocketEvent
*/
void onConnect(WebSocketEvent event);
}
by doing
atmosphereResource.addEventListener( new WebSocketEventListenerAdapter() {...} );
If you are using Atmosphere's Jersey module, you can add listeners by adding them using the @Suspend annotation
@Suspend(listeners="coma separated class that implement AtmosphereResourceEventListener"
Or programmatically using the SuspendResponse API:
return new SuspendResponse.SuspendResponseBuilder<String>()
.addListener(nnew WebSocketEventListenerAdapter() {...} )
.build();
- 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