|
||||||||||
| 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
The default Broadcaster implementation.
Broadcaster use an ExecutorService
to broadcast messages, 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.WriteQueue
|
| Nested classes/interfaces inherited from interface org.atmosphere.cpr.Broadcaster |
|---|
Broadcaster.POLICY, Broadcaster.SCOPE |
| Fields inherited from interface org.atmosphere.cpr.Broadcaster |
|---|
ROOT_MASTER |
| Constructor Summary | |
|---|---|
DefaultBroadcaster()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int POLLING_DEFAULT
public static final String CACHED
public static final String ASYNC_TOKEN
protected final ConcurrentLinkedQueue<AtmosphereResource> resources
protected BroadcasterConfig bc
protected final BlockingQueue<Deliver> messages
protected final ConcurrentLinkedQueue<BroadcasterListener> broadcasterListeners
protected final AtomicBoolean started
protected final AtomicBoolean initialized
protected final AtomicBoolean destroyed
protected Broadcaster.SCOPE scope
protected String name
protected final ConcurrentLinkedQueue<Deliver> delayedBroadcast
protected final ConcurrentLinkedQueue<Deliver> broadcastOnResume
protected final ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener> lifeCycleListeners
protected final ConcurrentHashMap<String,DefaultBroadcaster.WriteQueue> writeQueues
protected final DefaultBroadcaster.WriteQueue uniqueWriteQueue
protected final AtomicInteger dispatchThread
protected Future<?>[] notifierFuture
protected Future<?>[] asyncWriteFuture
protected URI uri
protected AtmosphereConfig config
protected int writeTimeoutInSecond
protected int waitTime
| Constructor Detail |
|---|
public DefaultBroadcaster()
| Method Detail |
|---|
public Broadcaster initialize(String name,
URI uri,
AtmosphereConfig config)
Broadcaster
initialize in interface Broadcasterconfig - an AtmosphereConfig
public Broadcaster initialize(String name,
AtmosphereConfig config)
protected BroadcasterConfig createBroadcasterConfig(AtmosphereConfig config)
BroadcasterConfig.
config - the AtmosphereConfig
BroadcasterConfigpublic void destroy()
BroadcasterExecutorService.
destroy in interface Broadcasterpublic Collection<AtmosphereResource> getAtmosphereResources()
BroadcasterList of AtmosphereResource.
getAtmosphereResources in interface BroadcasterList of AtmosphereResource associated with this Broadcaster.Broadcaster.addAtmosphereResource(AtmosphereResource)public void setScope(Broadcaster.SCOPE scope)
Broadcaster
setScope in interface Broadcasterscope - Broadcaster.SCOPE to set.public Broadcaster.SCOPE getScope()
BroadcasterBroadcaster.SCOPE.
getScope in interface BroadcasterBroadcaster.SCOPE of Broadcaster.public void setID(String id)
BroadcasterBroadcaster.
setID in interface Broadcasterid - ID of this Broadcasterpublic String getID()
BroadcasterBroadcaster.
getID in interface BroadcasterBroadcasterpublic void resumeAll()
BroadcasterAtmosphereResource) added via
Broadcaster.addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource).
resumeAll in interface Broadcasterpublic void releaseExternalResources()
BroadcasterAtmosphereResource and some resource (like database connections, JMS queue, etc.) needs to be
closed.
releaseExternalResources in interface Broadcasterpublic void setBroadcasterLifeCyclePolicy(BroadcasterLifeCyclePolicy lifeCyclePolicy)
BroadcasterBroadcasterLifeCyclePolicy. Make sure you are selecting the right policy
to avoid unexpected situations.
setBroadcasterLifeCyclePolicy in interface BroadcasterlifeCyclePolicy - a BroadcasterLifeCyclePolicypublic void addBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
BroadcasterBroadcasterLifeCyclePolicyListener.
addBroadcasterLifeCyclePolicyListener in interface Broadcasterb - a BroadcasterLifeCyclePolicyListenerpublic void removeBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
BroadcasterBroadcasterLifeCyclePolicyListener.
removeBroadcasterLifeCyclePolicyListener in interface Broadcasterb - a BroadcasterLifeCyclePolicyListenerpublic boolean isDestroyed()
BroadcasterBroadcaster has been destroyed.
isDestroyed in interface BroadcasterBroadcaster has been destroyed
public Future<Object> awaitAndBroadcast(Object t,
long time,
TimeUnit timeUnit)
BroadcasterAtmosphereResource before broadcasting. This method will block until
Broadcaster.addAtmosphereResource(AtmosphereResource) gets invoked.
awaitAndBroadcast in interface Broadcasterpublic Broadcaster addBroadcasterListener(BroadcasterListener b)
BroadcasterBroadcasterListener.
addBroadcasterListener in interface Broadcasterb - a BroadcasterListener
public Broadcaster removeBroadcasterListener(BroadcasterListener b)
BroadcasterBroadcasterListener.
removeBroadcasterListener in interface Broadcasterb - a BroadcasterListener
protected Runnable getBroadcastHandler()
protected Runnable getAsyncWriteHandler(DefaultBroadcaster.WriteQueue writeQueue)
protected void start()
protected void spawnReactor()
protected void killReactiveThreads()
protected int reactiveThreadsCount()
protected void push(Deliver deliver)
protected void deliverPush(Deliver deliver,
boolean rec)
protected boolean endBroadcast(Deliver deliver,
boolean deliverMessage)
protected void queueWriteIO(AtmosphereResource r,
Deliver deliver,
AtomicInteger count)
throws InterruptedException
InterruptedException
protected void executeBlockingWrite(AtmosphereResource r,
Deliver deliver,
AtomicInteger count)
throws InterruptedException
InterruptedException
protected boolean perRequestFilter(AtmosphereResource r,
Deliver msg)
protected void executeAsyncWrite(DefaultBroadcaster.AsyncWriteToken token)
protected boolean checkCachedAndPush(AtmosphereResource r,
AtmosphereResourceEvent e)
protected boolean retrieveTrackedBroadcast(AtmosphereResource r,
AtmosphereResourceEvent e)
protected void invokeOnStateChange(AtmosphereResource r,
AtmosphereResourceEvent e)
protected void prepareInvokeOnStateChange(AtmosphereResource r,
AtmosphereResourceEvent e)
public void onException(Throwable t,
AtmosphereResource ar)
public void onException(Throwable t,
AtmosphereResource ar,
boolean notifyAndCache)
public void cacheLostMessage(AtmosphereResource r)
r - AtmosphereResource
public void cacheLostMessage(AtmosphereResource r,
boolean force)
r - AtmosphereResource
public void cacheLostMessage(AtmosphereResource r,
DefaultBroadcaster.AsyncWriteToken token)
r - AtmosphereResource
public void cacheLostMessage(AtmosphereResource r,
DefaultBroadcaster.AsyncWriteToken token,
boolean force)
r - AtmosphereResource
public void setSuspendPolicy(long maxSuspendResource,
Broadcaster.POLICY policy)
BroadcasterAtmosphereResources. If the maximum 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 unlimited.
setSuspendPolicy in interface BroadcastermaxSuspendResource - maximum number of suspended AtmosphereResourcepublic Future<Object> broadcast(Object msg)
BroadcasterObject to all suspended responses, eg. invoke AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent).
broadcast in interface Broadcastermsg - the Object to be broadcasted
Future that can be used to synchronize using the Future.get()protected BroadcasterFuture<Object> futureDone(Object msg)
protected void dispatchMessages(Deliver e)
protected Object filter(Object msg)
BroadcastFilter
msg -
public Future<Object> broadcast(Object msg,
AtmosphereResource r)
BroadcasterObject to all suspended responses, eg. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with an instance of AtmosphereResource, representing
a single suspended response.
broadcast in interface Broadcastermsg - the Object to be broadcastedr - an AtmosphereResource
Future that can be used to synchronize using the Future.get()public Future<Object> broadcastOnResume(Object msg)
BroadcasterObject when an AtmosphereResource is resumed by a timeout or when using
AtmosphereResource.resume().
broadcastOnResume in interface Broadcastermsg - the Object to be broadcasted
Future that can be used to synchronize using the Future.get()protected void broadcastOnResume(AtmosphereResource r)
public Future<Object> broadcast(Object msg,
Set<AtmosphereResource> subset)
BroadcasterObject to all suspended response, eg. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with a Set of AtmosphereResource,
representing a set of AtmosphereHandler.
broadcast in interface Broadcastermsg - the Object to be broadcastedsubset - a Set of AtmosphereResource
Future that can be used to synchronize using the Future.get()public Broadcaster addAtmosphereResource(AtmosphereResource r)
BroadcasterAtmosphereResource to the list of items to be notified when
the Broadcaster.broadcast(java.lang.Object) is invoked.
It is strongly recommended to suspend the AtmosphereResource before
adding it to a Broadcaster.
addAtmosphereResource in interface Broadcasterr - an AtmosphereResource
protected void cacheAndSuspend(AtmosphereResource r)
r - AtmosphereResourceprotected void notifyAndAdd(AtmosphereResource r)
protected void entryDone(BroadcasterFuture<?> f)
protected void notifyBroadcastListener()
protected void notifyOnAddAtmosphereResourceListener(AtmosphereResource r)
protected void notifyOnRemoveAtmosphereResourceListener(AtmosphereResource r)
protected void notifyOnMessage(Deliver deliver)
public Broadcaster removeAtmosphereResource(AtmosphereResource r)
BroadcasterAtmosphereResource from the list of s to be notified when
the Broadcaster.broadcast(java.lang.Object) is invoked.
removeAtmosphereResource in interface Broadcasterr - an AtmosphereResource
protected Broadcaster removeAtmosphereResource(AtmosphereResource r,
boolean executeDone)
protected void notifyIdleListener()
protected void notifyDestroyListener()
protected void notifyEmptyListener()
public void setBroadcasterConfig(BroadcasterConfig bc)
BroadcasterBroadcasterConfig instance.
setBroadcasterConfig in interface Broadcasterbc - Configuration to be set.public BroadcasterConfig getBroadcasterConfig()
BroadcasterBroadcasterConfig.
getBroadcasterConfig in interface BroadcasterBroadcasterConfigpublic Future<Object> delayBroadcast(Object o)
BroadcasterObject will be broadcasted when Broadcaster.broadcast(java.lang.Object)
is invoked the first time.
delayBroadcast in interface Broadcastero - the Object to be broadcasted
Future that can be used to synchronize using the Future.get()
public Future<Object> delayBroadcast(Object o,
long delay,
TimeUnit t)
BroadcasterObject will be broadcasted once the
specified delay expires or when Broadcaster.broadcast(java.lang.Object) is invoked the first time.
delayBroadcast in interface Broadcastero - the Object to be broadcasteddelay - Amount of time to delayt - the TimeUnit of the delay
Future that can be used to synchronize using the Future.get()
public Future<Object> scheduleFixedBroadcast(Object o,
long period,
TimeUnit t)
BroadcasterObject will be broadcasted after every period
specified time frame expires. If the TimeUnit is set to null, the
Object will be broadcasted when the first Broadcaster.broadcast(java.lang.Object)
is invoked.
scheduleFixedBroadcast in interface Broadcastero - the Object to be broadcastedperiod - Every so often broadcast.t - a TimeUnit of period.
Future that can be used to synchronize using the Future.get()
public Future<Object> scheduleFixedBroadcast(Object o,
long waitFor,
long period,
TimeUnit t)
BroadcasterObject 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 - the Object to be broadcastedwaitFor - Wait for that long before first broadcastperiod - 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 Objectpublic ConcurrentLinkedQueue<BroadcasterListener> broadcasterListeners()
public BroadcasterLifeCyclePolicy lifeCyclePolicy()
public ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener> lifeCycleListeners()
public BlockingQueue<Deliver> messages()
public ConcurrentHashMap<String,DefaultBroadcaster.WriteQueue> writeQueues()
public Broadcaster.POLICY policy()
public boolean outOfOrderBroadcastSupported()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||