org.atmosphere.cpr
Class DefaultBroadcaster

java.lang.Object
  extended by org.atmosphere.cpr.DefaultBroadcaster
All Implemented Interfaces:
Broadcaster

public class DefaultBroadcaster
extends Object
implements Broadcaster

Broadcaster implementation. Broadcast messages to suspended reponse using the caller's Thread. This basic Broadcaster isn't using any ExecutorService to broadcast messages, so it is single threaded.

Author:
Jeanfrancois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.atmosphere.cpr.Broadcaster
Broadcaster.SCOPE
 
Constructor Summary
DefaultBroadcaster()
           
 
Method Summary
 AtmosphereResource addAtmosphereResource(AtmosphereResource r)
          Add a AtmosphereResource to the list of item to be notified when the Broadcaster.broadcast(java.lang.Object) is invoked.
protected  ConcurrentLinkedQueue<AtmosphereResource> atmosphereResources()
          Return the list of AtmosphereResource registered with this Broadcaster
 BroadcasterFuture<Object> broadcast(Object msg)
          Broadcast the Object to all suspended response, e.g.
 BroadcasterFuture<Object> broadcast(Object msg, AtmosphereResource r)
          Broadcast the Object to all suspended response, e.g.
 BroadcasterFuture<Object> broadcast(Object msg, Set<AtmosphereResource> subset)
          Broadcast the Object to all suspended response, e.g.
 Future<Object> delayBroadcast(Object o)
          Delay the broadcast operation.
 Future<Object> delayBroadcast(Object o, long delay, TimeUnit t)
          Delay the broadcast operation.
 void destroy()
          Destroy this instance and shutdown it's associated ExecutorServices
 Iterator<AtmosphereResource> getAtmosphereResources()
          Return an Iterator of AtmosphereResource
 BroadcasterConfig getBroadcasterConfig()
          Return the current BroadcasterConfig
 String getName()
          Return the name of this Broadcaster
 Broadcaster.SCOPE getScope()
          Retunr the Broadcaster#SCOPE
 AtmosphereResource removeAtmosphereResource(AtmosphereResource r)
          Remove a AtmosphereResource from the list of item to be notified when the Broadcaster.broadcast(java.lang.Object) is invoked.
 Future<?> scheduleFixedBroadcast(Object o, long period, TimeUnit t)
          Broadcast periodically.
 void setBroadcasterConfig(BroadcasterConfig bc)
          Set the BroadcasterConfig instance.
 void setName(String name)
          Set the name of this Broadcaster
 void setScope(Broadcaster.SCOPE scope)
          Set the scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBroadcaster

public DefaultBroadcaster()
Method Detail

destroy

public void destroy()
Destroy this instance and shutdown it's associated ExecutorServices

Specified by:
destroy in interface Broadcaster

getAtmosphereResources

public Iterator<AtmosphereResource> getAtmosphereResources()
Return an Iterator of AtmosphereResource

Specified by:
getAtmosphereResources in interface Broadcaster

setScope

public void setScope(Broadcaster.SCOPE scope)
Set the scope.

Specified by:
setScope in interface Broadcaster

getScope

public Broadcaster.SCOPE getScope()
Retunr the Broadcaster#SCOPE

Specified by:
getScope in interface Broadcaster
Returns:
Broadcaster#SCOPE

setName

public void setName(String name)
Set the name of this Broadcaster

Specified by:
setName in interface Broadcaster
Parameters:
name - of this Broadcaster

getName

public String getName()
Return the name of this Broadcaster

Specified by:
getName in interface Broadcaster
Returns:
the name of this Broadcaster

broadcast

public BroadcasterFuture<Object> broadcast(Object msg)
Broadcast the Object to all suspended response, e.g. invoke AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent).

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - and Object to be broadcasted.
Returns:
a Future that can be used to synchronize using the Future.get()

broadcast

public BroadcasterFuture<Object> broadcast(Object msg,
                                           AtmosphereResource r)
Broadcast the Object to all suspended response, e.g. invoke AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with an instance of AtmosphereResource, representing a single suspended response..

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - and Object to be broadcasted.
r - an AtmosphereResource
Returns:
a Future that can be used to synchronize using the Future.get()

broadcast

public BroadcasterFuture<Object> broadcast(Object msg,
                                           Set<AtmosphereResource> subset)
Broadcast the Object to all suspended response, e.g. invoke AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with a Set of AtmosphereResource, representing a set of AtmosphereHandler.

Specified by:
broadcast in interface Broadcaster
Parameters:
msg - and Object to be broadcasted.
Returns:
a Future that can be used to synchronize using the Future.get()

addAtmosphereResource

public AtmosphereResource addAtmosphereResource(AtmosphereResource r)
Add a AtmosphereResource to the list of item to be notified when the Broadcaster.broadcast(java.lang.Object) is invoked.

Specified by:
addAtmosphereResource in interface Broadcaster
Parameters:
r - an AtmosphereResource
Returns:
AtmosphereResource if added, or null if it was already there.

removeAtmosphereResource

public AtmosphereResource removeAtmosphereResource(AtmosphereResource r)
Remove a AtmosphereResource from the list of item to be notified when the Broadcaster.broadcast(java.lang.Object) is invoked.

Specified by:
removeAtmosphereResource in interface Broadcaster
Parameters:
r - an AtmosphereResource
Returns:
AtmosphereResource if removed, or null if it was not.

atmosphereResources

protected ConcurrentLinkedQueue<AtmosphereResource> atmosphereResources()
Return the list of AtmosphereResource registered with this Broadcaster

Returns:

setBroadcasterConfig

public void setBroadcasterConfig(BroadcasterConfig bc)
Set the BroadcasterConfig instance.

Specified by:
setBroadcasterConfig in interface Broadcaster
Parameters:
bf -

getBroadcasterConfig

public BroadcasterConfig getBroadcasterConfig()
Return the current BroadcasterConfig

Specified by:
getBroadcasterConfig in interface Broadcaster
Returns:
the current BroadcasterConfig

delayBroadcast

public Future<Object> delayBroadcast(Object o)
Delay the broadcast operation. The Object will be broadcasted when the first Broadcaster.broadcast(java.lang.Object) is invoked.

Specified by:
delayBroadcast in interface Broadcaster
Parameters:
o - and Object to be broadcasted.
Returns:
a Future that can be used to synchronize using the Future.get()

delayBroadcast

public Future<Object> delayBroadcast(Object o,
                                     long delay,
                                     TimeUnit t)
Delay the broadcast operation. The Object will be broadcasted once the specified delay expires. If the TimeUnit is set null, the Object will be broadcasted when the first Broadcaster.broadcast(java.lang.Object) is invoked.

Specified by:
delayBroadcast in interface Broadcaster
Parameters:
o - and Object to be broadcasted.
t - a TimeUnit
Returns:
a Future that can be used to synchronize using the Future.get()

scheduleFixedBroadcast

public Future<?> scheduleFixedBroadcast(Object o,
                                        long period,
                                        TimeUnit t)
Broadcast periodically. The Object will be broadcasted after every period specified time frame expires. If the TimeUnit is set null, the Object will be broadcasted when the first Broadcaster.broadcast(java.lang.Object) is invoked.

Specified by:
scheduleFixedBroadcast in interface Broadcaster
Parameters:
o - and Object to be broadcasted.
t - a TimeUnit
Returns:
a Future that can be used to synchronize using the Future.get()


Copyright © 2009 SUN Microsystems. All Rights Reserved.