Package org.atmosphere.cpr
Class Meteor
- java.lang.Object
-
- org.atmosphere.cpr.Meteor
-
public class Meteor extends java.lang.ObjectAMeteoris a simple class that can be used from aServletto suspend, broadcast and resume responses. AMeteorcan 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MeteoraddListener(AtmosphereResourceEventListener e)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.voidattach(java.lang.Object o)Attach anObjectwith thisMeteor.java.lang.Objectattachement()Return anObjectwith thisMeteor.Meteorbroadcast(java.lang.Object o)Broadcast anObjectto all suspended responses.static Meteorbuild(javax.servlet.http.HttpServletRequest r)Create aMeteorusing theHttpServletRequest.static Meteorbuild(javax.servlet.http.HttpServletRequest req, java.util.List<BroadcastFilter> l, Serializer s)Create aMeteorusing theHttpServletRequestand use a list ofBroadcastFilterandSerializerfor writing the result of a broadcast operation theHttpServletResponse.static Meteorbuild(javax.servlet.http.HttpServletRequest req, Broadcaster.SCOPE scope, java.util.List<BroadcastFilter> l, Serializer s)Create aMeteorusing theHttpServletRequestand use a list ofBroadcastFilterandSerializerfor writing the result of a broadcast operation theHttpServletResponse.static Meteorbuild(javax.servlet.http.HttpServletRequest r, Serializer s)Create aMeteorusing theHttpServletRequestand use theSerializerfor writing the result of a broadcast operation using theHttpServletResponse.MeteordelayBroadadcast(java.lang.Object o, long period)Schedule a delayed broadcast, in seconds.voiddestroy()Mark this instance as destroyed.AtmosphereConfiggetAtmosphereConfig()Return theAtmosphereConfigAtmosphereResourcegetAtmosphereResource()Return the underlyingAtmosphereResource.BroadcastergetBroadcaster()Return the underlyingBroadcaster.static Meteorlookup(javax.servlet.http.HttpServletRequest r)Retrieve an instance ofMeteorbased on theHttpServletRequest.MeteorremoveListener(AtmosphereResourceEventListener e)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.Meteorresume()Resume the underlyingHttpServletResponse.MeteorresumeOnBroadcast(boolean resumeOnBroadcast)Resume the Meteor after the first broadcast operation.Meteorschedule(java.lang.Object o, long period)Schedule a periodic broadcast, in seconds.voidsetBroadcaster(Broadcaster b)Set aBroadcasterinstance.Meteorsuspend(long l)Suspend the underlyingHttpServletResponse.Meteorsuspend(long timeout, java.util.concurrent.TimeUnit timeunit)Suspend the underlyingHttpServletResponse.AtmosphereResource.TRANSPORTtransport()Return the currentAtmosphereResource.TRANSPORT.
-
-
-
Method Detail
-
lookup
public static Meteor lookup(javax.servlet.http.HttpServletRequest r)
Retrieve an instance ofMeteorbased on theHttpServletRequest.- Parameters:
r-HttpServletRequest- Returns:
- a
Meteoror null if not found
-
build
public static final Meteor build(javax.servlet.http.HttpServletRequest r)
Create aMeteorusing theHttpServletRequest.- Parameters:
r- anHttpServletRequest- Returns:
- a
Meteorthan can be used to resume, suspend and broadcastObject
-
build
public static final Meteor build(javax.servlet.http.HttpServletRequest r, Serializer s)
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 final Meteor build(javax.servlet.http.HttpServletRequest req, java.util.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 final Meteor build(javax.servlet.http.HttpServletRequest req, Broadcaster.SCOPE scope, java.util.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
public Meteor suspend(long l)
Suspend the underlyingHttpServletResponse. Passing a value of -1 suspends the response forever.- Parameters:
l- the maximum time a response stay suspended- Returns:
Meteor
-
resumeOnBroadcast
public Meteor resumeOnBroadcast(boolean resumeOnBroadcast)
Resume the Meteor after the first broadcast operation. This is useful when long-polling is used.- Parameters:
resumeOnBroadcast-- Returns:
- this
-
transport
public AtmosphereResource.TRANSPORT 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
public Meteor suspend(long timeout, java.util.concurrent.TimeUnit timeunit)
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
-
broadcast
public Meteor broadcast(java.lang.Object o)
Broadcast anObjectto all suspended responses.- Parameters:
o- anObject- Returns:
Meteor
-
schedule
public Meteor schedule(java.lang.Object o, long period)
Schedule a periodic broadcast, in seconds.- Parameters:
o- anObjectperiod- period in seconds- Returns:
Meteor
-
delayBroadadcast
public Meteor delayBroadadcast(java.lang.Object o, long period)
Schedule a delayed broadcast, in seconds.- Parameters:
o- anObjectperiod- period in seconds- Returns:
Meteor
-
getBroadcaster
public Broadcaster getBroadcaster()
Return the underlyingBroadcaster.- Returns:
-
setBroadcaster
public void setBroadcaster(Broadcaster b)
Set aBroadcasterinstance.- Parameters:
b-
-
attachement
public java.lang.Object attachement()
Return anObjectwith thisMeteor.- Returns:
- the
Object
-
attach
public void attach(java.lang.Object o)
Attach anObjectwith thisMeteor.
-
addListener
public Meteor addListener(AtmosphereResourceEventListener e)
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
public Meteor removeListener(AtmosphereResourceEventListener e)
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
public AtmosphereResource getAtmosphereResource()
Return the underlyingAtmosphereResource.- Returns:
- the underlying
AtmosphereResource
-
getAtmosphereConfig
public AtmosphereConfig getAtmosphereConfig()
Return theAtmosphereConfig- Returns:
- the
AtmosphereConfig
-
-