org.atmosphere.cpr
Class Meteor

java.lang.Object
  extended by org.atmosphere.cpr.Meteor

public class Meteor
extends Object

A Meteor is a simple class that can be used from a Servlet to suspend, broadcast and resume a response. A Meteor can be created by invoking the build() method.

Meteor.build(HttpServletRequest).suspend(-1);

A Meteor is usually created when an application need 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

Field Summary
protected static ConcurrentHashMap<AtmosphereResource,Meteor> cache
           
 
Method Summary
 Meteor addListener(AtmosphereResourceEventListener e)
          Add a AtmosphereResourceEventListener which gets invoked when response are resuming, when the remote client close the connection or when the a Broadcaster.broadcast(T) operations occurs.
 void attach(Object o)
          Attach an Object with this Meteor
 Object attachement()
          Return an Object with this Meteor
 Meteor broadcast(Object o)
          Broadcast an Object to all suspended response.
static Meteor build(javax.servlet.http.HttpServletRequest r)
          Create a Meteor using the HttpServletRequest
static Meteor build(javax.servlet.http.HttpServletRequest req, Broadcaster.SCOPE scope, List<BroadcastFilter> l, Serializer s)
          Create a Meteor using the HttpServletRequest and use a list of BroadcastFilter and Serializer for writting the result of a broadcast operation the HttpServletResponse.
static Meteor build(javax.servlet.http.HttpServletRequest req, List<BroadcastFilter> l, Serializer s)
          Create a Meteor using the HttpServletRequest and use a list of BroadcastFilter and Serializer for writting the result of a broadcast operation the HttpServletResponse.
static Meteor build(javax.servlet.http.HttpServletRequest r, Serializer s)
          Create a Meteor using the HttpServletRequest and use the Serializer for writting the result of a broadcast operation using the HttpServletResponse
 Meteor delayBroadadcast(Object o, long period)
          Schedule a delayed broadcast, in seconds.
 void destroy()
          Mark this instance as Destroyed.
 AtmosphereResource getAtmosphereResource()
          Return the underlying AtmosphereResource
 Broadcaster getBroadcaster()
          Return the underlying Broadcaster
static Meteor lookup(javax.servlet.http.HttpServletRequest r)
          Retrieve an instance of Meteor based on the HttpServletRequest
 Meteor removeListener(AtmosphereResourceEventListener e)
          Remove a AtmosphereResourceEventListener which gets invoked when response are resuming, when the remote client close the connection or when the a Broadcaster.broadcast(T) operations occurs.
 Meteor resume()
          Resume the underlying HttpServletResponse
 Meteor resumeOnBroadcast(boolean resumeOnBroadcast)
          Resume the Meteor after the first broadcast operation.
 Meteor schedule(Object o, long period)
          Schedule a periodic broadcast, in seconds.
 void setBroadcaster(Broadcaster b)
          Set a Broadcaster instance.
 Meteor suspend(long l)
          Suspend the underlying HttpServletResponse.
 Meteor suspend(long l, boolean outputComments)
          Suspend the underlying HttpServletResponse.
 Meteor suspend(long timeout, TimeUnit timeunit)
          Suspend the underlying HttpServletResponse.
 Meteor suspend(long timeout, TimeUnit timeunit, boolean outputComments)
          Suspend the underlying HttpServletResponse.
 AtmosphereResource.TRANSPORT transport()
          Return the current AtmosphereResource.TRANSPORT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected static final ConcurrentHashMap<AtmosphereResource,Meteor> cache
Method Detail

lookup

public static Meteor lookup(javax.servlet.http.HttpServletRequest r)
Retrieve an instance of Meteor based on the HttpServletRequest

Parameters:
r - HttpServletRequest
Returns:
a Meteor or null if not found

build

public static final Meteor build(javax.servlet.http.HttpServletRequest r)
Create a Meteor using the HttpServletRequest

Parameters:
r - an HttpServletRequest
Returns:
a Meteor than can be used to resume, suspend and broadcast Object

build

public static final Meteor build(javax.servlet.http.HttpServletRequest r,
                                 Serializer s)
Create a Meteor using the HttpServletRequest and use the Serializer for writting the result of a broadcast operation using the HttpServletResponse

Parameters:
r - an HttpServletRequest
s - a Serializer used when writing broadcast events.
Returns:
a Meteor than can be used to resume, suspend and broadcast Object

build

public static final Meteor build(javax.servlet.http.HttpServletRequest req,
                                 List<BroadcastFilter> l,
                                 Serializer s)
Create a Meteor using the HttpServletRequest and use a list of BroadcastFilter and Serializer for writting the result of a broadcast operation the HttpServletResponse.

Parameters:
req - an HttpServletRequest
l - a list of BroadcastFilter
s - a Serializer used when writing broadcast events.
Returns:
a Meteor than can be used to resume, suspend and broadcast Object

build

public static final Meteor build(javax.servlet.http.HttpServletRequest req,
                                 Broadcaster.SCOPE scope,
                                 List<BroadcastFilter> l,
                                 Serializer s)
Create a Meteor using the HttpServletRequest and use a list of BroadcastFilter and Serializer for writting the result of a broadcast operation the HttpServletResponse.

Parameters:
req - an HttpServletRequest
scope - the Broadcaster.SCOPE}
l - a list of BroadcastFilter
s - a Serializer used when writing broadcast events.
Returns:
a Meteor than can be used to resume, suspend and broadcast Object

suspend

public Meteor suspend(long l)
Suspend the underlying HttpServletResponse. Passing value of -1 suspend 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 current AtmosphereResource.TRANSPORT. The transport needs to be explicitly set by the client by adding the appropriate HeaderConfig.X_ATMOSPHERE_TRANSPORT value, which can be long-polling, streaming, websocket or jsonp.

Returns:

suspend

public Meteor suspend(long timeout,
                      TimeUnit timeunit)
Suspend the underlying HttpServletResponse. Passing value of -1 suspend the response forever.

Parameters:
timeout - the maximum time a response stay suspended.
timeunit - The time unit of the timeout value
Returns:
Meteor

suspend

public Meteor suspend(long l,
                      boolean outputComments)
Suspend the underlying HttpServletResponse. Passing value of -1 suspend the response forever.

Parameters:
l - the maximum time a response stay suspended.
outputComments - the maximum time a response stay suspended.
Returns:
Meteor

suspend

public Meteor suspend(long timeout,
                      TimeUnit timeunit,
                      boolean outputComments)
Suspend the underlying HttpServletResponse. Passing value of -1 suspend the response forever.

Parameters:
timeout - the maximum time a response stay suspended.
timeunit - The time unit of the timeout value
outputComments - the maximum time a response stay suspended.
Returns:
Meteor

resume

public Meteor resume()
Resume the underlying HttpServletResponse

Returns:
Meteor

broadcast

public Meteor broadcast(Object o)
Broadcast an Object to all suspended response.

Parameters:
o - an Object
Returns:
Meteor

schedule

public Meteor schedule(Object o,
                       long period)
Schedule a periodic broadcast, in seconds.

Parameters:
o - an Object
period - period in seconds
Returns:
Meteor

delayBroadadcast

public Meteor delayBroadadcast(Object o,
                               long period)
Schedule a delayed broadcast, in seconds.

Parameters:
o - an Object
period - period in seconds
Returns:
Meteor

getBroadcaster

public Broadcaster getBroadcaster()
Return the underlying Broadcaster

Returns:

setBroadcaster

public void setBroadcaster(Broadcaster b)
Set a Broadcaster instance.

Parameters:
b -

attachement

public Object attachement()
Return an Object with this Meteor

Returns:
the Object

attach

public void attach(Object o)
Attach an Object with this Meteor


addListener

public Meteor addListener(AtmosphereResourceEventListener e)
Add a AtmosphereResourceEventListener which gets invoked when response are resuming, when the remote client close the connection or when the a Broadcaster.broadcast(T) operations occurs.

Parameters:
e - an inatance of AtmosphereResourceEventListener

removeListener

public Meteor removeListener(AtmosphereResourceEventListener e)
Remove a AtmosphereResourceEventListener which gets invoked when response are resuming, when the remote client close the connection or when the a Broadcaster.broadcast(T) operations occurs.

Parameters:
e - an inatance of AtmosphereResourceEventListener

destroy

public void destroy()
Mark this instance as Destroyed. No more operation will be allowed.


getAtmosphereResource

public AtmosphereResource getAtmosphereResource()
Return the underlying AtmosphereResource

Returns:
the underlying AtmosphereResource


Copyright © 2012. All Rights Reserved.