Package org.atmosphere.cpr
Class DefaultBroadcaster
- java.lang.Object
-
- org.atmosphere.cpr.DefaultBroadcaster
-
- All Implemented Interfaces:
Broadcaster
- Direct Known Subclasses:
AbstractBroadcasterProxy,ExcludeSessionBroadcaster,SimpleBroadcaster
public class DefaultBroadcaster extends java.lang.Object implements Broadcaster
The defaultBroadcasterimplementation. Broadcast messages to suspended responses using the caller's Thread. This basicBroadcasteruse anExecutorServiceto broadcast messages, hence the broadcast operation is asynchronous. Make sure you block onbroadcast(Object).get()} if you need synchronous operations.- Author:
- Jeanfrancois Arcand
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDefaultBroadcaster.AsyncWriteTokenstatic classDefaultBroadcaster.WriteQueue-
Nested classes/interfaces inherited from interface org.atmosphere.cpr.Broadcaster
Broadcaster.POLICY, Broadcaster.SCOPE
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.Future<?>[]asyncWriteFutureprotected BroadcasterConfigbcprotected java.util.Collection<BroadcasterListener>broadcasterListenersprotected java.util.concurrent.ConcurrentLinkedQueue<Deliver>broadcastOnResumestatic java.lang.StringCACHEDprotected booleancandidateForPoolableprotected AtmosphereConfigconfigprotected java.util.concurrent.ConcurrentLinkedQueue<Deliver>delayedBroadcastprotected java.util.concurrent.atomic.AtomicBooleandestroyedprotected java.util.concurrent.atomic.AtomicIntegerdispatchThreadprotected java.util.concurrent.atomic.AtomicBooleaninitializedprotected java.util.concurrent.ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener>lifeCycleListenersprotected java.util.concurrent.BlockingQueue<Deliver>messagesprotected java.lang.Stringnameprotected java.util.concurrent.Future<?>[]notifierFuturestatic intPOLLING_DEFAULTprotected java.util.concurrent.ConcurrentLinkedQueue<AtmosphereResource>resourcesprotected Broadcaster.SCOPEscopeprotected booleansharedListenersprotected java.util.concurrent.atomic.AtomicBooleanstartedprotected DefaultBroadcaster.WriteQueueuniqueWriteQueueprotected java.net.URIuriprotected java.lang.StringusingTokenIdForAttributeprotected intwaitTimeprotected java.util.concurrent.ConcurrentHashMap<java.lang.String,DefaultBroadcaster.WriteQueue>writeQueuesprotected intwriteTimeoutInSecond-
Fields inherited from interface org.atmosphere.cpr.Broadcaster
ROOT_MASTER
-
-
Constructor Summary
Constructors Constructor Description DefaultBroadcaster()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BroadcasteraddAtmosphereResource(AtmosphereResource r)Add aAtmosphereResourceto the list of items to be notified when theBroadcaster.broadcast(java.lang.Object)is invoked.voidaddBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)BroadcasteraddBroadcasterListener(BroadcasterListener b)Add aBroadcasterListener.java.util.concurrent.Future<java.lang.Object>awaitAndBroadcast(java.lang.Object t, long time, java.util.concurrent.TimeUnit timeUnit)Await for availableAtmosphereResourcebefore broadcasting.java.util.concurrent.Future<java.lang.Object>broadcast(java.lang.Object msg)Broadcast theObjectto all suspended responses, eg.java.util.concurrent.Future<java.lang.Object>broadcast(java.lang.Object msg, java.util.Set<AtmosphereResource> subset)Broadcast theObjectto all suspended response, eg.java.util.concurrent.Future<java.lang.Object>broadcast(java.lang.Object msg, AtmosphereResource r)Broadcast theObjectto all suspended responses, eg.java.util.Collection<BroadcasterListener>broadcasterListeners()java.util.concurrent.Future<java.lang.Object>broadcastOnResume(java.lang.Object msg)Broadcast theObjectwhen anAtmosphereResourceis resumed by a timeout or when usingAtmosphereResource.resume().protected voidbroadcastOnResume(AtmosphereResource r)protected voidcacheAndSuspend(AtmosphereResource r)Look in the cache to see if there are messages available, and take the appropriate actions.voidcacheLostMessage(AtmosphereResource r, boolean force)Cache the message because an unexpected exception occurred.voidcacheLostMessage(AtmosphereResource r, DefaultBroadcaster.AsyncWriteToken token)Cache the message because an unexpected exception occurred.voidcacheLostMessage(AtmosphereResource r, DefaultBroadcaster.AsyncWriteToken token, boolean force)Cache the message because an unexpected exception occurred.protected booleancacheMessageOnIOException(java.lang.Throwable cause)protected booleancheckCachedAndPush(AtmosphereResource r, AtmosphereResourceEvent e)protected BroadcasterConfigcreateBroadcasterConfig(AtmosphereConfig config)CreateBroadcasterConfig.java.util.concurrent.Future<?>currentLifecycleTask()DefaultBroadcastercurrentLifecycleTask(java.util.concurrent.Future<?> currentLifecycleTask)java.util.concurrent.Future<java.lang.Object>delayBroadcast(java.lang.Object o)Delay the broadcast operation.java.util.concurrent.Future<java.lang.Object>delayBroadcast(java.lang.Object o, long delay, java.util.concurrent.TimeUnit t)Delay the broadcast operation.protected voiddeliverPush(Deliver deliver, boolean rec)voiddestroy()Destroy this instance and shutdown it's associatedExecutorService.protected voiddispatchMessages(Deliver e)protected booleanendBroadcast(Deliver deliver, AtmosphereResource r, CacheMessage cacheMsg, boolean deliverMessage)protected voidentryDone(BroadcasterFuture<?> f)protected voidexecuteAsyncWrite(DefaultBroadcaster.AsyncWriteToken token)protected voidexecuteBlockingWrite(AtmosphereResource r, Deliver deliver, java.util.concurrent.atomic.AtomicInteger count)protected java.lang.Objectfilter(java.lang.Object msg)Invoke theBroadcastFilterprotected BroadcasterFuture<java.lang.Object>futureDone(java.lang.Object msg)protected java.lang.RunnablegetAsyncWriteHandler(DefaultBroadcaster.WriteQueue writeQueue)java.util.Collection<AtmosphereResource>getAtmosphereResources()Return anListofAtmosphereResource.BroadcasterConfiggetBroadcasterConfig()Return the currentBroadcasterConfig.BroadcasterLifeCyclePolicygetBroadcasterLifeCyclePolicy()Get theBroadcasterLifeCyclePolicy.protected java.lang.RunnablegetBroadcastHandler()java.lang.StringgetID()Return the ID of thisBroadcaster.Broadcaster.SCOPEgetScope()Return theBroadcaster.SCOPE.Broadcasterinitialize(java.lang.String name, java.net.URI uri, AtmosphereConfig config)Configure a Broadcaster.Broadcasterinitialize(java.lang.String name, AtmosphereConfig config)protected voidinvokeOnStateChange(AtmosphereResource r, AtmosphereResourceEvent e)booleanisDestroyed()Return true if thisBroadcasterhas been destroyed.protected voidkillReactiveThreads()LifecycleHandlerlifecycleHandler()DefaultBroadcasterlifecycleHandler(LifecycleHandler lifecycleHandler)java.util.concurrent.ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener>lifeCycleListeners()BroadcasterLifeCyclePolicylifeCyclePolicy()java.util.concurrent.BlockingQueue<Deliver>messages()protected voidnotifyAndAdd(AtmosphereResource r)protected voidnotifyBroadcastListener()protected voidnotifyOnAddAtmosphereResourceListener(AtmosphereResource r)protected voidnotifyOnMessage(Deliver deliver)protected voidnotifyOnRemoveAtmosphereResourceListener(AtmosphereResource r)voidonException(java.lang.Throwable t, AtmosphereResource ar)voidonException(java.lang.Throwable t, AtmosphereResource ar, boolean notifyAndCache)booleanoutOfOrderBroadcastSupported()protected booleanperRequestFilter(AtmosphereResource r, Deliver msg)Broadcaster.POLICYpolicy()protected voidprepareInvokeOnStateChange(AtmosphereResource r, AtmosphereResourceEvent e)protected voidpush(Deliver deliver)protected voidqueueWriteIO(AtmosphereResource r, Deliver deliver, java.util.concurrent.atomic.AtomicInteger count)protected intreactiveThreadsCount()Return the default number of reactive threads that will be waiting for work when a broadcast operation is executed.java.util.concurrent.atomic.AtomicBooleanrecentActivity()voidreleaseExternalResources()Release external resources associated with this Broadcaster.BroadcasterremoveAtmosphereResource(AtmosphereResource r)Remove aAtmosphereResourcefrom the list of s to be notified when theBroadcaster.broadcast(java.lang.Object)is invoked.protected BroadcasterremoveAtmosphereResource(AtmosphereResource r, boolean executeDone)voidremoveBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)Remove aBroadcasterLifeCyclePolicyListener.BroadcasterremoveBroadcasterListener(BroadcasterListener b)Remove aBroadcasterListener.Broadcasterrename(java.lang.String id)Rename this Broadcaster without invoking it's associatedBroadcasterFactory.voidresumeAll()Resume all suspended responses (AtmosphereResource) added viaBroadcaster.addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource).protected booleanretrieveTrackedBroadcast(AtmosphereResource r, AtmosphereResourceEvent e)java.util.concurrent.Future<java.lang.Object>scheduleFixedBroadcast(java.lang.Object o, long waitFor, long period, java.util.concurrent.TimeUnit t)Broadcast periodically.java.util.concurrent.Future<java.lang.Object>scheduleFixedBroadcast(java.lang.Object o, long period, java.util.concurrent.TimeUnit t)Broadcast periodically.voidsetBroadcasterConfig(BroadcasterConfig bc)Set theBroadcasterConfiginstance.voidsetBroadcasterLifeCyclePolicy(BroadcasterLifeCyclePolicy lifeCyclePolicy)Set theBroadcasterLifeCyclePolicy.voidsetID(java.lang.String id)Set the ID of thisBroadcaster.voidsetScope(Broadcaster.SCOPE scope)Set the scope.voidsetSuspendPolicy(long maxSuspendResource, Broadcaster.POLICY policy)Set the maximum number of suspendedAtmosphereResources.protected voidspawnReactor()protected voidstart()java.lang.StringtoString()java.util.concurrent.ConcurrentHashMap<java.lang.String,DefaultBroadcaster.WriteQueue>writeQueues()
-
-
-
Field Detail
-
POLLING_DEFAULT
public static final int POLLING_DEFAULT
- See Also:
- Constant Field Values
-
CACHED
public static final java.lang.String CACHED
-
resources
protected final java.util.concurrent.ConcurrentLinkedQueue<AtmosphereResource> resources
-
bc
protected BroadcasterConfig bc
-
messages
protected final java.util.concurrent.BlockingQueue<Deliver> messages
-
broadcasterListeners
protected java.util.Collection<BroadcasterListener> broadcasterListeners
-
started
protected final java.util.concurrent.atomic.AtomicBoolean started
-
initialized
protected final java.util.concurrent.atomic.AtomicBoolean initialized
-
destroyed
protected final java.util.concurrent.atomic.AtomicBoolean destroyed
-
scope
protected Broadcaster.SCOPE scope
-
name
protected java.lang.String name
-
delayedBroadcast
protected final java.util.concurrent.ConcurrentLinkedQueue<Deliver> delayedBroadcast
-
broadcastOnResume
protected final java.util.concurrent.ConcurrentLinkedQueue<Deliver> broadcastOnResume
-
lifeCycleListeners
protected final java.util.concurrent.ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener> lifeCycleListeners
-
writeQueues
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,DefaultBroadcaster.WriteQueue> writeQueues
-
uniqueWriteQueue
protected final DefaultBroadcaster.WriteQueue uniqueWriteQueue
-
dispatchThread
protected final java.util.concurrent.atomic.AtomicInteger dispatchThread
-
notifierFuture
protected java.util.concurrent.Future<?>[] notifierFuture
-
asyncWriteFuture
protected java.util.concurrent.Future<?>[] asyncWriteFuture
-
uri
protected java.net.URI uri
-
config
protected AtmosphereConfig config
-
writeTimeoutInSecond
protected int writeTimeoutInSecond
-
waitTime
protected int waitTime
-
sharedListeners
protected boolean sharedListeners
-
candidateForPoolable
protected boolean candidateForPoolable
-
usingTokenIdForAttribute
protected final java.lang.String usingTokenIdForAttribute
-
-
Method Detail
-
initialize
public Broadcaster initialize(java.lang.String name, java.net.URI uri, AtmosphereConfig config)
Description copied from interface:BroadcasterConfigure a Broadcaster.- Specified by:
initializein interfaceBroadcasterconfig- anAtmosphereConfig- Returns:
- a usable Broadcaster.
-
initialize
public Broadcaster initialize(java.lang.String name, AtmosphereConfig config)
-
createBroadcasterConfig
protected BroadcasterConfig createBroadcasterConfig(AtmosphereConfig config)
CreateBroadcasterConfig.- Parameters:
config- theAtmosphereConfig- Returns:
- an instance of
BroadcasterConfig
-
destroy
public void destroy()
Description copied from interface:BroadcasterDestroy this instance and shutdown it's associatedExecutorService.- Specified by:
destroyin interfaceBroadcaster
-
getAtmosphereResources
public java.util.Collection<AtmosphereResource> getAtmosphereResources()
Description copied from interface:BroadcasterReturn anListofAtmosphereResource.- Specified by:
getAtmosphereResourcesin interfaceBroadcaster- Returns:
ListofAtmosphereResourceassociated with thisBroadcaster.- See Also:
Broadcaster.addAtmosphereResource(AtmosphereResource)
-
setScope
public void setScope(Broadcaster.SCOPE scope)
Description copied from interface:BroadcasterSet the scope.- Specified by:
setScopein interfaceBroadcaster- Parameters:
scope-Broadcaster.SCOPEto set.
-
getScope
public Broadcaster.SCOPE getScope()
Description copied from interface:BroadcasterReturn theBroadcaster.SCOPE.- Specified by:
getScopein interfaceBroadcaster- Returns:
Broadcaster.SCOPEofBroadcaster.
-
setID
public void setID(java.lang.String id)
Description copied from interface:BroadcasterSet the ID of thisBroadcaster.- Specified by:
setIDin interfaceBroadcaster- Parameters:
id- ID of thisBroadcaster
-
rename
public Broadcaster rename(java.lang.String id)
Rename this Broadcaster without invoking it's associatedBroadcasterFactory. This method must be carefully used as it could easily create memory leak as the Broadcaster won't be removed from itsBroadcasterFactory.- Parameters:
id- the new name- Returns:
- this;
-
getID
public java.lang.String getID()
Description copied from interface:BroadcasterReturn the ID of thisBroadcaster.- Specified by:
getIDin interfaceBroadcaster- Returns:
- the ID of this
Broadcaster
-
resumeAll
public void resumeAll()
Description copied from interface:BroadcasterResume all suspended responses (AtmosphereResource) added viaBroadcaster.addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource).- Specified by:
resumeAllin interfaceBroadcaster
-
releaseExternalResources
public void releaseExternalResources()
Description copied from interface:BroadcasterRelease external resources associated with this Broadcaster. This is useful when a Broadcaster no longer have suspendedAtmosphereResourceand some resource (like database connections, JMS queue, etc.) needs to be closed.- Specified by:
releaseExternalResourcesin interfaceBroadcaster
-
setBroadcasterLifeCyclePolicy
public void setBroadcasterLifeCyclePolicy(BroadcasterLifeCyclePolicy lifeCyclePolicy)
Description copied from interface:BroadcasterSet theBroadcasterLifeCyclePolicy. Make sure you are selecting the right policy to avoid unexpected situations.- Specified by:
setBroadcasterLifeCyclePolicyin interfaceBroadcaster- Parameters:
lifeCyclePolicy- aBroadcasterLifeCyclePolicy
-
getBroadcasterLifeCyclePolicy
public BroadcasterLifeCyclePolicy getBroadcasterLifeCyclePolicy()
Description copied from interface:BroadcasterGet theBroadcasterLifeCyclePolicy.- Specified by:
getBroadcasterLifeCyclePolicyin interfaceBroadcaster- Returns:
BroadcasterLifeCyclePolicy
-
addBroadcasterLifeCyclePolicyListener
public void addBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
Description copied from interface:Broadcaster- Specified by:
addBroadcasterLifeCyclePolicyListenerin interfaceBroadcaster- Parameters:
b- aBroadcasterLifeCyclePolicyListener
-
removeBroadcasterLifeCyclePolicyListener
public void removeBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
Description copied from interface:BroadcasterRemove aBroadcasterLifeCyclePolicyListener.- Specified by:
removeBroadcasterLifeCyclePolicyListenerin interfaceBroadcaster- Parameters:
b- aBroadcasterLifeCyclePolicyListener
-
isDestroyed
public boolean isDestroyed()
Description copied from interface:BroadcasterReturn true if thisBroadcasterhas been destroyed.- Specified by:
isDestroyedin interfaceBroadcaster- Returns:
- true if this
Broadcasterhas been destroyed
-
awaitAndBroadcast
public java.util.concurrent.Future<java.lang.Object> awaitAndBroadcast(java.lang.Object t, long time, java.util.concurrent.TimeUnit timeUnit)Description copied from interface:BroadcasterAwait for availableAtmosphereResourcebefore broadcasting. This method will block untilBroadcaster.addAtmosphereResource(AtmosphereResource)gets invoked.- Specified by:
awaitAndBroadcastin interfaceBroadcaster
-
addBroadcasterListener
public Broadcaster addBroadcasterListener(BroadcasterListener b)
Description copied from interface:BroadcasterAdd aBroadcasterListener.- Specified by:
addBroadcasterListenerin interfaceBroadcaster- Parameters:
b- aBroadcasterListener- Returns:
- this
-
removeBroadcasterListener
public Broadcaster removeBroadcasterListener(BroadcasterListener b)
Description copied from interface:BroadcasterRemove aBroadcasterListener.- Specified by:
removeBroadcasterListenerin interfaceBroadcaster- Parameters:
b- aBroadcasterListener- Returns:
- this
-
getBroadcastHandler
protected java.lang.Runnable getBroadcastHandler()
-
getAsyncWriteHandler
protected java.lang.Runnable getAsyncWriteHandler(DefaultBroadcaster.WriteQueue writeQueue)
-
start
protected void start()
-
spawnReactor
protected void spawnReactor()
-
killReactiveThreads
protected void killReactiveThreads()
-
reactiveThreadsCount
protected int reactiveThreadsCount()
Return the default number of reactive threads that will be waiting for work when a broadcast operation is executed.- Returns:
- the default number of reactive threads
-
push
protected void push(Deliver deliver)
-
deliverPush
protected void deliverPush(Deliver deliver, boolean rec)
-
endBroadcast
protected boolean endBroadcast(Deliver deliver, AtmosphereResource r, CacheMessage cacheMsg, boolean deliverMessage)
-
queueWriteIO
protected void queueWriteIO(AtmosphereResource r, Deliver deliver, java.util.concurrent.atomic.AtomicInteger count) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
executeBlockingWrite
protected void executeBlockingWrite(AtmosphereResource r, Deliver deliver, java.util.concurrent.atomic.AtomicInteger count) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
perRequestFilter
protected boolean perRequestFilter(AtmosphereResource r, Deliver msg)
-
executeAsyncWrite
protected void executeAsyncWrite(DefaultBroadcaster.AsyncWriteToken token)
-
cacheMessageOnIOException
protected boolean cacheMessageOnIOException(java.lang.Throwable cause)
-
checkCachedAndPush
protected boolean checkCachedAndPush(AtmosphereResource r, AtmosphereResourceEvent e)
-
retrieveTrackedBroadcast
protected boolean retrieveTrackedBroadcast(AtmosphereResource r, AtmosphereResourceEvent e)
-
invokeOnStateChange
protected void invokeOnStateChange(AtmosphereResource r, AtmosphereResourceEvent e)
-
prepareInvokeOnStateChange
protected void prepareInvokeOnStateChange(AtmosphereResource r, AtmosphereResourceEvent e)
-
onException
public void onException(java.lang.Throwable t, AtmosphereResource ar)
-
onException
public void onException(java.lang.Throwable t, AtmosphereResource ar, boolean notifyAndCache)
-
cacheLostMessage
public void cacheLostMessage(AtmosphereResource r, boolean force)
Cache the message because an unexpected exception occurred.- Parameters:
r-AtmosphereResource
-
cacheLostMessage
public void cacheLostMessage(AtmosphereResource r, DefaultBroadcaster.AsyncWriteToken token)
Cache the message because an unexpected exception occurred.- Parameters:
r-AtmosphereResource
-
cacheLostMessage
public void cacheLostMessage(AtmosphereResource r, DefaultBroadcaster.AsyncWriteToken token, boolean force)
Cache the message because an unexpected exception occurred.- Parameters:
r-AtmosphereResource
-
setSuspendPolicy
public void setSuspendPolicy(long maxSuspendResource, Broadcaster.POLICY policy)Description copied from interface:BroadcasterSet the maximum number of suspendedAtmosphereResources. If the maximum is reached, Atmosphere will either resumeAtmosphereResourceusingBroadcaster.POLICY.FIFO(first in first out) orBroadcaster.POLICY.REJECTtheAtmosphereResource. By default the number is unlimited.- Specified by:
setSuspendPolicyin interfaceBroadcaster- Parameters:
maxSuspendResource- maximum number of suspended AtmosphereResource
-
broadcast
public java.util.concurrent.Future<java.lang.Object> broadcast(java.lang.Object msg)
Description copied from interface:BroadcasterBroadcast theObjectto all suspended responses, eg. invokeAtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent).- Specified by:
broadcastin interfaceBroadcaster- Parameters:
msg- theObjectto be broadcasted- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
futureDone
protected BroadcasterFuture<java.lang.Object> futureDone(java.lang.Object msg)
-
dispatchMessages
protected void dispatchMessages(Deliver e)
-
filter
protected java.lang.Object filter(java.lang.Object msg)
Invoke theBroadcastFilter- Parameters:
msg-- Returns:
-
broadcast
public java.util.concurrent.Future<java.lang.Object> broadcast(java.lang.Object msg, AtmosphereResource r)Description copied from interface:BroadcasterBroadcast theObjectto all suspended responses, eg. invokeAtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent)with an instance ofAtmosphereResource, representing a single suspended response.- Specified by:
broadcastin interfaceBroadcaster- Parameters:
msg- theObjectto be broadcastedr- anAtmosphereResource- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
broadcastOnResume
public java.util.concurrent.Future<java.lang.Object> broadcastOnResume(java.lang.Object msg)
Description copied from interface:BroadcasterBroadcast theObjectwhen anAtmosphereResourceis resumed by a timeout or when usingAtmosphereResource.resume().- Specified by:
broadcastOnResumein interfaceBroadcaster- Parameters:
msg- theObjectto be broadcasted- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
broadcastOnResume
protected void broadcastOnResume(AtmosphereResource r)
-
broadcast
public java.util.concurrent.Future<java.lang.Object> broadcast(java.lang.Object msg, java.util.Set<AtmosphereResource> subset)Description copied from interface:BroadcasterBroadcast theObjectto all suspended response, eg. invokeAtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent)with aSetofAtmosphereResource, representing a set ofAtmosphereHandler.- Specified by:
broadcastin interfaceBroadcaster- Parameters:
msg- theObjectto be broadcastedsubset- a Set ofAtmosphereResource- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
addAtmosphereResource
public Broadcaster addAtmosphereResource(AtmosphereResource r)
Description copied from interface:BroadcasterAdd aAtmosphereResourceto the list of items to be notified when theBroadcaster.broadcast(java.lang.Object)is invoked. It is strongly recommended to suspend theAtmosphereResourcebefore adding it to aBroadcaster.- Specified by:
addAtmosphereResourcein interfaceBroadcaster- Parameters:
r- anAtmosphereResource- Returns:
- this
-
cacheAndSuspend
protected void cacheAndSuspend(AtmosphereResource r)
Look in the cache to see if there are messages available, and take the appropriate actions.- Parameters:
r- AtmosphereResource
-
notifyAndAdd
protected void notifyAndAdd(AtmosphereResource r)
-
entryDone
protected void entryDone(BroadcasterFuture<?> f)
-
notifyBroadcastListener
protected void notifyBroadcastListener()
-
notifyOnAddAtmosphereResourceListener
protected void notifyOnAddAtmosphereResourceListener(AtmosphereResource r)
-
notifyOnRemoveAtmosphereResourceListener
protected void notifyOnRemoveAtmosphereResourceListener(AtmosphereResource r)
-
notifyOnMessage
protected void notifyOnMessage(Deliver deliver)
-
removeAtmosphereResource
public Broadcaster removeAtmosphereResource(AtmosphereResource r)
Description copied from interface:BroadcasterRemove aAtmosphereResourcefrom the list of s to be notified when theBroadcaster.broadcast(java.lang.Object)is invoked.- Specified by:
removeAtmosphereResourcein interfaceBroadcaster- Parameters:
r- anAtmosphereResource- Returns:
- this
-
removeAtmosphereResource
protected Broadcaster removeAtmosphereResource(AtmosphereResource r, boolean executeDone)
-
setBroadcasterConfig
public void setBroadcasterConfig(BroadcasterConfig bc)
Description copied from interface:BroadcasterSet theBroadcasterConfiginstance.- Specified by:
setBroadcasterConfigin interfaceBroadcaster- Parameters:
bc- Configuration to be set.
-
getBroadcasterConfig
public BroadcasterConfig getBroadcasterConfig()
Description copied from interface:BroadcasterReturn the currentBroadcasterConfig.- Specified by:
getBroadcasterConfigin interfaceBroadcaster- Returns:
- the current
BroadcasterConfig
-
delayBroadcast
public java.util.concurrent.Future<java.lang.Object> delayBroadcast(java.lang.Object o)
Description copied from interface:BroadcasterDelay the broadcast operation. TheObjectwill be broadcasted whenBroadcaster.broadcast(java.lang.Object)is invoked the first time.- Specified by:
delayBroadcastin interfaceBroadcaster- Parameters:
o- theObjectto be broadcasted- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
delayBroadcast
public java.util.concurrent.Future<java.lang.Object> delayBroadcast(java.lang.Object o, long delay, java.util.concurrent.TimeUnit t)Description copied from interface:BroadcasterDelay the broadcast operation. TheObjectwill be broadcasted once the specified delay expires or whenBroadcaster.broadcast(java.lang.Object)is invoked the first time.- Specified by:
delayBroadcastin interfaceBroadcaster- Parameters:
o- theObjectto be broadcasteddelay- Amount of time to delayt- theTimeUnitof the delay- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
scheduleFixedBroadcast
public java.util.concurrent.Future<java.lang.Object> scheduleFixedBroadcast(java.lang.Object o, long period, java.util.concurrent.TimeUnit t)Description copied from interface:BroadcasterBroadcast periodically. TheObjectwill be broadcasted after every period specified time frame expires. If theTimeUnitis set to null, theObjectwill be broadcasted when the firstBroadcaster.broadcast(java.lang.Object)is invoked.- Specified by:
scheduleFixedBroadcastin interfaceBroadcaster- Parameters:
o- theObjectto be broadcastedperiod- Every so often broadcast.t- aTimeUnitof period.- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
scheduleFixedBroadcast
public java.util.concurrent.Future<java.lang.Object> scheduleFixedBroadcast(java.lang.Object o, long waitFor, long period, java.util.concurrent.TimeUnit t)Description copied from interface:BroadcasterBroadcast periodically. TheObjectwill be broadcasted after every period specified time frame expires. If theTimeUnitis set null, theObjectwill be broadcasted when the firstBroadcaster.broadcast(java.lang.Object)is invoked.- Specified by:
scheduleFixedBroadcastin interfaceBroadcaster- Parameters:
o- theObjectto be broadcastedwaitFor- Wait for that long before first broadcastperiod- The period inbetween broadcast.t- aTimeUnitof waitFor and period.- Returns:
- a
Futurethat can be used to synchronize using theFuture.get()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
broadcasterListeners
public java.util.Collection<BroadcasterListener> broadcasterListeners()
-
lifeCyclePolicy
public BroadcasterLifeCyclePolicy lifeCyclePolicy()
-
lifeCycleListeners
public java.util.concurrent.ConcurrentLinkedQueue<BroadcasterLifeCyclePolicyListener> lifeCycleListeners()
-
messages
public java.util.concurrent.BlockingQueue<Deliver> messages()
-
writeQueues
public java.util.concurrent.ConcurrentHashMap<java.lang.String,DefaultBroadcaster.WriteQueue> writeQueues()
-
policy
public Broadcaster.POLICY policy()
-
outOfOrderBroadcastSupported
public boolean outOfOrderBroadcastSupported()
-
recentActivity
public java.util.concurrent.atomic.AtomicBoolean recentActivity()
-
lifecycleHandler
public LifecycleHandler lifecycleHandler()
-
lifecycleHandler
public DefaultBroadcaster lifecycleHandler(LifecycleHandler lifecycleHandler)
-
currentLifecycleTask
public java.util.concurrent.Future<?> currentLifecycleTask()
-
currentLifecycleTask
public DefaultBroadcaster currentLifecycleTask(java.util.concurrent.Future<?> currentLifecycleTask)
-
-