Package org.atmosphere.cpr
Class Meteor
java.lang.Object
org.atmosphere.cpr.Meteor
A
Meteor is a simple class that can be used from a Servlet
to suspend, broadcast and resume responses. A Meteor can be created by invoking
the build() method.
Meteor.build(HttpServletRequest).suspend(-1);
A Meteor is usually created when an application needs to suspend a response. A Meteor instance can then be cached and re-used later for either broadcasting a message, or when an application needs to resume the suspended response.
- Author:
- Jeanfrancois Arcand
-
Method Summary
Modifier and TypeMethodDescriptionAdd aAtmosphereResourceEventListenerwhich gets invoked when responses are resuming, when the remote client closes the connection or when the aBroadcaster.broadcast(java.lang.Object)operations occurs.voidBroadcast anObjectto all suspended responses.static Meteorbuild(jakarta.servlet.http.HttpServletRequest r) Create aMeteorusing theHttpServletRequest.static Meteorbuild(jakarta.servlet.http.HttpServletRequest req, List<BroadcastFilter> l, Serializer s) Create aMeteorusing theHttpServletRequestand use a list ofBroadcastFilterandSerializerfor writing the result of a broadcast operation theHttpServletResponse.static Meteorbuild(jakarta.servlet.http.HttpServletRequest req, Broadcaster.SCOPE scope, List<BroadcastFilter> l, Serializer s) Create aMeteorusing theHttpServletRequestand use a list ofBroadcastFilterandSerializerfor writing the result of a broadcast operation theHttpServletResponse.static Meteorbuild(jakarta.servlet.http.HttpServletRequest r, Serializer s) Create aMeteorusing theHttpServletRequestand use theSerializerfor writing the result of a broadcast operation using theHttpServletResponse.delayBroadadcast(Object o, long period) Schedule a delayed broadcast, in seconds.voiddestroy()Mark this instance as destroyed.Return theAtmosphereConfigReturn the underlyingAtmosphereResource.Return the underlyingBroadcaster.static Meteorlookup(jakarta.servlet.http.HttpServletRequest r) Retrieve an instance ofMeteorbased on theHttpServletRequest.Remove aAtmosphereResourceEventListenerwhich gets invoked when a response is resuming, when the remote client closes the connection or when the aBroadcaster.broadcast(java.lang.Object)operations occurs.resume()Resume the underlyingHttpServletResponse.resumeOnBroadcast(boolean resumeOnBroadcast) Resume the Meteor after the first broadcast operation.Schedule a periodic broadcast, in seconds.voidSet aBroadcasterinstance.suspend(long l) Suspend the underlyingHttpServletResponse.Suspend the underlyingHttpServletResponse.Return the currentAtmosphereResource.TRANSPORT.
-
Method Details
-
lookup
Retrieve an instance ofMeteorbased on theHttpServletRequest.- Parameters:
r-HttpServletRequest- Returns:
- a
Meteoror null if not found
-
build
Create aMeteorusing theHttpServletRequest. -
build
Create aMeteorusing theHttpServletRequestand use theSerializerfor writing the result of a broadcast operation using theHttpServletResponse.- Parameters:
r- anHttpServletRequests- aSerializerused when writing broadcast events- Returns:
- a
Meteorthan can be used to resume, suspend and broadcastObject
-
build
public static Meteor build(jakarta.servlet.http.HttpServletRequest req, List<BroadcastFilter> l, Serializer s) Create aMeteorusing theHttpServletRequestand use a list ofBroadcastFilterandSerializerfor writing the result of a broadcast operation theHttpServletResponse.- Parameters:
req- anHttpServletRequestl- a list ofBroadcastFilters- aSerializerused when writing broadcast events- Returns:
- a
Meteorthan can be used to resume, suspend and broadcastObject
-
build
public static Meteor build(jakarta.servlet.http.HttpServletRequest req, Broadcaster.SCOPE scope, List<BroadcastFilter> l, Serializer s) Create aMeteorusing theHttpServletRequestand use a list ofBroadcastFilterandSerializerfor writing the result of a broadcast operation theHttpServletResponse.- Parameters:
req- anHttpServletRequestscope- theBroadcaster.SCOPE}l- a list ofBroadcastFilters- aSerializerused when writing broadcast events- Returns:
- a
Meteorthan can be used to resume, suspend and broadcastObject
-
suspend
Suspend the underlyingHttpServletResponse. Passing a value of -1 suspends the response forever.- Parameters:
l- the maximum time a response stay suspended- Returns:
Meteor
-
resumeOnBroadcast
Resume the Meteor after the first broadcast operation. This is useful when long-polling is used.- Parameters:
resumeOnBroadcast-- Returns:
- this
-
transport
Return the currentAtmosphereResource.TRANSPORT. The transport needs to be explicitly set by the client by adding the appropriateHeaderConfig.X_ATMOSPHERE_TRANSPORTvalue, which can be long-polling, streaming, websocket or JSONP.- Returns:
-
suspend
Suspend the underlyingHttpServletResponse. Passing a value of -1 suspends the response forever.- Parameters:
timeout- the maximum time a response stay suspendedtimeunit- The time unit of the timeout value- Returns:
Meteor
-
resume
Resume the underlyingHttpServletResponse.- Returns:
Meteor
-
broadcast
Broadcast anObjectto all suspended responses. -
schedule
Schedule a periodic broadcast, in seconds. -
delayBroadadcast
Schedule a delayed broadcast, in seconds. -
getBroadcaster
Return the underlyingBroadcaster.- Returns:
-
setBroadcaster
Set aBroadcasterinstance.- Parameters:
b-
-
attachement
- Returns:
- the
Object
-
attach
-
addListener
Add aAtmosphereResourceEventListenerwhich gets invoked when responses are resuming, when the remote client closes the connection or when the aBroadcaster.broadcast(java.lang.Object)operations occurs.- Parameters:
e- an instance ofAtmosphereResourceEventListener
-
removeListener
Remove aAtmosphereResourceEventListenerwhich gets invoked when a response is resuming, when the remote client closes the connection or when the aBroadcaster.broadcast(java.lang.Object)operations occurs.- Parameters:
e- an instance ofAtmosphereResourceEventListener
-
destroy
public void destroy()Mark this instance as destroyed. No more operations will be allowed. -
getAtmosphereResource
Return the underlyingAtmosphereResource.- Returns:
- the underlying
AtmosphereResource
-
getAtmosphereConfig
Return theAtmosphereConfig- Returns:
- the
AtmosphereConfig
-