|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.atmosphere.cpr.DefaultBroadcaster
public class DefaultBroadcaster
Broadcaster implementation.
Broadcaster use an ExecutorService
to broadcast message, hence the broadcast operation is asynchronous. Make sure
you block on broadcast(Object).get()} if you need synchronous operations.
| Nested Class Summary | |
|---|---|
protected static class |
DefaultBroadcaster.AsyncWriteToken
|
static class |
DefaultBroadcaster.Entry
|
| Nested classes/interfaces inherited from interface org.atmosphere.cpr.Broadcaster |
|---|
Broadcaster.POLICY, Broadcaster.SCOPE |
| Field Summary | |
|---|---|
static String |
ASYNC_TOKEN
|
protected Future<?> |
asyncWriteFuture
|
protected BlockingQueue<DefaultBroadcaster.AsyncWriteToken> |
asyncWriteQueue
|
protected BroadcasterConfig |
bc
|
BroadcasterCache |
broadcasterCache
|
protected ConcurrentLinkedQueue<DefaultBroadcaster.Entry> |
broadcastOnResume
|
static String |
CACHED
|
protected BroadcasterCache.STRATEGY |
cacheStrategy
|
protected AtmosphereConfig |
config
|
protected ConcurrentLinkedQueue<DefaultBroadcaster.Entry> |
delayedBroadcast
|
protected AtomicBoolean |
destroyed
|
protected ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener> |
lifeCycleListeners
|
protected BlockingQueue<DefaultBroadcaster.Entry> |
messages
|
protected String |
name
|
protected Future<?> |
notifierFuture
|
protected ConcurrentLinkedQueue<AtmosphereResource> |
resources
|
protected Broadcaster.SCOPE |
scope
|
protected AtomicBoolean |
started
|
protected URI |
uri
|
| Constructor Summary | |
|---|---|
DefaultBroadcaster(String name,
AtmosphereConfig config)
|
|
DefaultBroadcaster(String name,
URI uri,
AtmosphereConfig config)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String CACHED
public static final String ASYNC_TOKEN
protected final ConcurrentLinkedQueue<AtmosphereResource> resources
protected BroadcasterConfig bc
protected final BlockingQueue<DefaultBroadcaster.Entry> messages
protected final BlockingQueue<DefaultBroadcaster.AsyncWriteToken> asyncWriteQueue
protected final AtomicBoolean started
protected final AtomicBoolean destroyed
protected Broadcaster.SCOPE scope
protected String name
protected final ConcurrentLinkedQueue<DefaultBroadcaster.Entry> delayedBroadcast
protected final ConcurrentLinkedQueue<DefaultBroadcaster.Entry> broadcastOnResume
protected final ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener> lifeCycleListeners
protected Future<?> notifierFuture
protected Future<?> asyncWriteFuture
public BroadcasterCache broadcasterCache
protected URI uri
protected AtmosphereConfig config
protected BroadcasterCache.STRATEGY cacheStrategy
| Constructor Detail |
|---|
public DefaultBroadcaster(String name,
URI uri,
AtmosphereConfig config)
public DefaultBroadcaster(String name,
AtmosphereConfig config)
| Method Detail |
|---|
protected BroadcasterConfig createBroadcasterConfig(AtmosphereConfig config)
BroadcasterConfig
config - the AtmosphereConfig
BroadcasterConfigpublic void destroy()
ExecutorService
destroy in interface Broadcasterpublic Collection<AtmosphereResource> getAtmosphereResources()
List of AtmosphereResource.
getAtmosphereResources in interface BroadcasterList of AtmosphereResource associated with this Broadcaster.Broadcaster.addAtmosphereResource(AtmosphereResource)public void setScope(Broadcaster.SCOPE scope)
setScope in interface Broadcasterscope - Broadcaster.SCOPE to set.public Broadcaster.SCOPE getScope()
Broadcaster.SCOPE
getScope in interface BroadcasterBroadcaster.SCOPE of Broadcaster.public void setID(String id)
Broadcaster
setID in interface Broadcasterid - ID of this Broadcasterpublic String getID()
Broadcaster
getID in interface BroadcasterBroadcasterpublic void resumeAll()
AtmosphereResource) added via
Broadcaster.addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource).
resumeAll in interface Broadcasterpublic void releaseExternalResources()
AtmosphereResource and some resource (like database connections, JMS queue, etc.) needs to be
closed.
releaseExternalResources in interface Broadcasterpublic void setBroadcasterLifeCyclePolicy(BroadcasterLifeCyclePolicy lifeCyclePolicy)
BroadcasterLifeCyclePolicy. Make sure you are selecting the right policy
to avoid unexpected situation.
setBroadcasterLifeCyclePolicy in interface BroadcasterlifeCyclePolicy - a BroadcasterLifeCyclePolicypublic void addBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
BroadcasterLifeCyclePolicyListener
addBroadcasterLifeCyclePolicyListener in interface Broadcasterb - a BroadcasterLifeCyclePolicyListenerpublic void removeBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
BroadcasterLifeCyclePolicyListener
removeBroadcasterLifeCyclePolicyListener in interface Broadcasterb - a BroadcasterLifeCyclePolicyListenerpublic boolean isDestroyed()
Broadcaster has been destroyed
isDestroyed in interface BroadcasterBroadcaster has been destroyed
public <T> Future<T> awaitAndBroadcast(T t,
long time,
TimeUnit timeUnit)
AtmosphereResource before broadcasting. This method will block until
Broadcaster.addAtmosphereResource(AtmosphereResource) gets invoked.
awaitAndBroadcast in interface Broadcasterprotected Runnable getBroadcastHandler()
protected void start()
protected void push(DefaultBroadcaster.Entry entry)
protected void push(DefaultBroadcaster.Entry entry,
boolean rec)
protected void queueWriteIO(AtmosphereResource r,
Object finalMsg,
DefaultBroadcaster.Entry entry)
throws InterruptedException
InterruptedException
protected Object perRequestFilter(AtmosphereResource r,
DefaultBroadcaster.Entry msg)
protected void executeAsyncWrite(DefaultBroadcaster.AsyncWriteToken token)
protected Runnable getAsyncWriteHandler()
protected void checkCachedAndPush(AtmosphereResource r,
AtmosphereResourceEvent e)
protected boolean retrieveTrackedBroadcast(AtmosphereResource r,
AtmosphereResourceEvent e)
protected void trackBroadcastMessage(AtmosphereResource r,
Object msg)
protected void broadcast(AtmosphereResource r,
AtmosphereResourceEvent e)
public void onException(Throwable t,
AtmosphereResource ar)
public void cacheLostMessage(AtmosphereResource r)
r -
public void cacheLostMessage(AtmosphereResource r,
DefaultBroadcaster.AsyncWriteToken token)
r -
public void setSuspendPolicy(long maxSuspendResource,
Broadcaster.POLICY policy)
BroadcasterAtmosphereResource. If the max is reached, Atmosphere will either
resume AtmosphereResource using Broadcaster.POLICY.FIFO (first in first out)
or Broadcaster.POLICY.REJECT the AtmosphereResource.
By default the number is uunlimited.
setSuspendPolicy in interface BroadcastermaxSuspendResource - max suspendedpublic <T> Future<T> broadcast(T msg)
Object to all suspended response, e.g. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent).
broadcast in interface Broadcastermsg - and Object to be broadcasted.
Future that can be used to synchronize using the Future.get()protected Object filter(Object msg)
BroadcastFilter
msg -
public <T> Future<T> broadcast(T msg,
AtmosphereResource r)
Object to all suspended response, e.g. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with an instance of AtmosphereResource, representing
a single suspended response..
broadcast in interface Broadcastermsg - and Object to be broadcasted.r - an AtmosphereResource
Future that can be used to synchronize using the Future.get()public <T> Future<T> broadcastOnResume(T msg)
Object when an AtmosphereResource is resumed by a timeout or when using
AtmosphereResource.resume()
broadcastOnResume in interface Broadcastermsg - and Object to be broadcasted.
Future that can be used to synchronize using the Future.get()protected void broadcastOnResume(AtmosphereResource r)
public <T> Future<T> broadcast(T msg,
Set<AtmosphereResource> subset)
Object to all suspended response, e.g. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with a Set of AtmosphereResource,
representing a set of AtmosphereHandler.
broadcast in interface Broadcastermsg - and Object to be broadcasted.subset - a Set of AtmosphereResource
Future that can be used to synchronize using the Future.get()public Broadcaster addAtmosphereResource(AtmosphereResource r)
AtmosphereResource to the list of item to be notified when
the Broadcaster.broadcast(T) is invoked.
addAtmosphereResource in interface Broadcasterr - an AtmosphereResource
AtmosphereResource if added, or null if it was already there.public Broadcaster removeAtmosphereResource(AtmosphereResource r)
AtmosphereResource from the list of item to be notified when
the Broadcaster.broadcast(T) is invoked.
removeAtmosphereResource in interface Broadcasterr - an AtmosphereResource
AtmosphereResource if removed, or null if it was not.public void setBroadcasterConfig(BroadcasterConfig bc)
BroadcasterConfig instance.
setBroadcasterConfig in interface Broadcasterbc - public BroadcasterConfig getBroadcasterConfig()
BroadcasterConfig
getBroadcasterConfig in interface BroadcasterBroadcasterConfigpublic <T> Future<T> delayBroadcast(T o)
Object will be broadcasted
when the first Broadcaster.broadcast(java.lang.Object)
is invoked.
delayBroadcast in interface Broadcastero - and Object to be broadcasted.
Future that can be used to synchronize using the Future.get()
public <T> Future<T> delayBroadcast(T o,
long delay,
TimeUnit t)
Object will be broadcasted once the
specified delay expires or when the first Broadcaster.broadcast(java.lang.Object)
delayBroadcast in interface Broadcastero - and Object to be broadcasted.delay - Amount of time to delay.t - a TimeUnit of delay.
Future that can be used to synchronize using the Future.get()
public Future<?> scheduleFixedBroadcast(Object o,
long period,
TimeUnit t)
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.
scheduleFixedBroadcast in interface Broadcastero - and Object to be broadcasted.period - Every so often broadcast.t - a TimeUnit of period.
Future that can be used to synchronize using the Future.get()
public Future<?> scheduleFixedBroadcast(Object o,
long waitFor,
long period,
TimeUnit t)
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.
scheduleFixedBroadcast in interface Broadcastero - and Object to be broadcasted.waitFor - Wait for that long before first broadcast.period - The period inbetween broadcast.t - a TimeUnit of waitFor and period.
Future that can be used to synchronize using the Future.get()public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||