Package org.atmosphere.cpr
Class BroadcasterConfig
- java.lang.Object
-
- org.atmosphere.cpr.BroadcasterConfig
-
public class BroadcasterConfig extends java.lang.Object- Author:
- Jeanfrancois Arcand
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBroadcasterConfig.FilterManipulatorManipulate the message before and after they are getting filtered byBroadcastFilter
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentLinkedQueue<BroadcastFilter>filtersprotected java.util.concurrent.ConcurrentLinkedQueue<PerRequestBroadcastFilter>perRequestFilters
-
Constructor Summary
Constructors Constructor Description BroadcasterConfig(java.util.concurrent.ExecutorService executorService, java.util.concurrent.ExecutorService asyncWriteService, java.util.concurrent.ScheduledExecutorService scheduler, AtmosphereConfig config, java.lang.String broadcasterId)Create a new BroadcasterConfig.BroadcasterConfig(java.util.List<java.lang.String> broadcastFilters, AtmosphereConfig config, boolean handleExecutors, java.lang.String broadcasterId)Create a new BroadcasterConfig.BroadcasterConfig(java.util.List<java.lang.String> broadcastFilters, AtmosphereConfig config, java.lang.String broadcasterId)Create a new BroadcasterConfig.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddFilter(BroadcastFilter e)Add aBroadcastFilter.protected booleanaddFilter(BroadcastFilter e, boolean init)Add aBroadcastFilter.java.util.List<java.lang.Object>applyFilters(AtmosphereResource r, java.util.List<java.lang.Object> cacheMessages)Apply all filters to theAtmosphereResourceand the providedListof messages.protected BroadcasterConfigbroadcasterID(java.lang.String broadcasterId)protected voidconfigExecutors()protected voidconfigureSharedCacheExecutor()voiddestroy()protected voiddestroy(boolean force)protected BroadcastFilter.BroadcastActionfilter(java.lang.Object object)InvokeBroadcastFilters in the order they were added.protected BroadcastFilter.BroadcastActionfilter(AtmosphereResource r, java.lang.Object message, java.lang.Object originalMessage)InvokeBroadcastFilters in the order they were added, with a uniqueAtmosphereRequest.java.util.Collection<BroadcastFilter>filters()Return the current list of installedBroadcastFilters.voidforceDestroy()Force shutdown of allExecutorServices.java.util.concurrent.ExecutorServicegetAsyncWriteService()Return theExecutorServicethisBroadcasteruse for executing asynchronous write of events.AtmosphereConfiggetAtmosphereConfig()Return theAtmosphereConfigvalue.BroadcasterCachegetBroadcasterCache()Get theBroadcasterCacheused for thisBroadcaster.java.util.concurrent.ExecutorServicegetExecutorService()Return theExecutorServicethisBroadcastersupports.java.util.concurrent.ScheduledExecutorServicegetScheduledExecutorService()Return theScheduledExecutorServicethisBroadcastersupports.booleanhandleExecutors()booleanhasFilters()Check if this object containsBroadcastFilters.booleanhasPerRequestFilters()Check if this object containsBroadcastFilters.BroadcasterConfiginit()Initialize BroadcastFilters and BroadcasterCache.protected voidinitClusterExtension()voidremoveAllFilters()Remove allBroadcastFilters.booleanremoveFilter(BroadcastFilter filter)Remove aBroadcastFilter.BroadcasterConfigsetAsyncWriteService(java.util.concurrent.ExecutorService asyncWriteService)Set anExecutorServicewhich can be used to writeAtmosphereResourceEvent.getMessage().BroadcasterConfigsetAsyncWriteService(java.util.concurrent.ExecutorService asyncWriteService, boolean isAsyncExecutorShared)Set anExecutorServicewhich can be used to writeAtmosphereResourceEvent.getMessage().BroadcasterConfigsetBroadcasterCache(BroadcasterCache broadcasterCache)Set aBroadcasterCache.BroadcasterConfigsetExecutorService(java.util.concurrent.ExecutorService executorService)Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvent.BroadcasterConfigsetExecutorService(java.util.concurrent.ExecutorService executorService, boolean isExecutorShared)Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvent.BroadcasterConfigsetScheduledExecutorService(java.util.concurrent.ScheduledExecutorService scheduler)Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvents.protected java.lang.Objectunwrap(java.lang.Object o)protected BroadcastFilter.BroadcastActionwrap(BroadcastFilter.BroadcastAction a, boolean wasUnwraped)
-
-
-
Field Detail
-
filters
protected final java.util.concurrent.ConcurrentLinkedQueue<BroadcastFilter> filters
-
perRequestFilters
protected final java.util.concurrent.ConcurrentLinkedQueue<PerRequestBroadcastFilter> perRequestFilters
-
-
Constructor Detail
-
BroadcasterConfig
public BroadcasterConfig(java.util.List<java.lang.String> broadcastFilters, AtmosphereConfig config, java.lang.String broadcasterId)Create a new BroadcasterConfig. Remember to call init() after the object has been created.- Parameters:
broadcastFilters-config-broadcasterId-
-
BroadcasterConfig
public BroadcasterConfig(java.util.List<java.lang.String> broadcastFilters, AtmosphereConfig config, boolean handleExecutors, java.lang.String broadcasterId)Create a new BroadcasterConfig. Remember to call init() after the object has been created.- Parameters:
broadcastFilters-config-handleExecutors-broadcasterId-
-
BroadcasterConfig
public BroadcasterConfig(java.util.concurrent.ExecutorService executorService, java.util.concurrent.ExecutorService asyncWriteService, java.util.concurrent.ScheduledExecutorService scheduler, AtmosphereConfig config, java.lang.String broadcasterId)Create a new BroadcasterConfig. Remember to call init() after the object has been created.- Parameters:
executorService-asyncWriteService-scheduler-config-broadcasterId-
-
-
Method Detail
-
init
public BroadcasterConfig init()
Initialize BroadcastFilters and BroadcasterCache. Must always be called after creating a new BroadcasterConfig!
-
configureSharedCacheExecutor
protected void configureSharedCacheExecutor()
-
broadcasterID
protected BroadcasterConfig broadcasterID(java.lang.String broadcasterId)
-
initClusterExtension
protected void initClusterExtension()
-
handleExecutors
public boolean handleExecutors()
-
configExecutors
protected void configExecutors()
-
setExecutorService
public BroadcasterConfig setExecutorService(java.util.concurrent.ExecutorService executorService)
Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvent. By default, the result ofExecutorsFactory.getMessageDispatcher(AtmosphereConfig, String)is used if this method is not invoked.- Parameters:
executorService- to be used when broadcasting.
-
setExecutorService
public BroadcasterConfig setExecutorService(java.util.concurrent.ExecutorService executorService, boolean isExecutorShared)
Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvent. By default, the result ofExecutorsFactory.getMessageDispatcher(AtmosphereConfig, String)is used if this method is not invoked.- Parameters:
executorService- to be used when broadcasting.isExecutorShared- true if the life cycle of theExecutorServicewill be executed by the application. It means Atmosphere will NOT invoke the shutdown method whendestroy()is invoked.
-
getExecutorService
public java.util.concurrent.ExecutorService getExecutorService()
Return theExecutorServicethisBroadcastersupports. By default it returns the result ofExecutorsFactory.getMessageDispatcher(AtmosphereConfig, String)}.- Returns:
- An ExecutorService.
-
setAsyncWriteService
public BroadcasterConfig setAsyncWriteService(java.util.concurrent.ExecutorService asyncWriteService)
Set anExecutorServicewhich can be used to writeAtmosphereResourceEvent.getMessage(). By default, the result ofExecutorsFactory.getAsyncOperationExecutor(AtmosphereConfig, String)is used if this method is not invoked.- Parameters:
asyncWriteService- to be used when writing events.
-
setAsyncWriteService
public BroadcasterConfig setAsyncWriteService(java.util.concurrent.ExecutorService asyncWriteService, boolean isAsyncExecutorShared)
Set anExecutorServicewhich can be used to writeAtmosphereResourceEvent.getMessage(). By default, the result ofExecutorsFactory.getAsyncOperationExecutor(AtmosphereConfig, String)is used if this method is not invoked.- Parameters:
asyncWriteService- to be used when writing events.isAsyncExecutorShared- true if the life cycle of theExecutorServicewill be executed by the application. It means Atmosphere will NOT invoke the shutdown method when thisdestroy()is invoked.
-
getAsyncWriteService
public java.util.concurrent.ExecutorService getAsyncWriteService()
Return theExecutorServicethisBroadcasteruse for executing asynchronous write of events. By default it returns the result ofExecutorsFactory.getAsyncOperationExecutor(AtmosphereConfig, String).- Returns:
- An ExecutorService.
-
addFilter
public boolean addFilter(BroadcastFilter e)
Add aBroadcastFilter.- Parameters:
e-BroadcastFilter- Returns:
- true if successfully added
-
addFilter
protected boolean addFilter(BroadcastFilter e, boolean init)
Add aBroadcastFilter.- Parameters:
e-BroadcastFilter- Returns:
- true if successfully added
-
filters
public java.util.Collection<BroadcastFilter> filters()
Return the current list of installedBroadcastFilters.- Returns:
- the current list of installed
BroadcastFilters
-
destroy
public void destroy()
-
destroy
protected void destroy(boolean force)
-
forceDestroy
public void forceDestroy()
Force shutdown of allExecutorServices.
-
removeFilter
public boolean removeFilter(BroadcastFilter filter)
Remove aBroadcastFilter.- Parameters:
filter-BroadcastFilter- Returns:
- true if successfully removed
-
removeAllFilters
public void removeAllFilters()
Remove allBroadcastFilters.
-
hasFilters
public boolean hasFilters()
Check if this object containsBroadcastFilters.- Returns:
- true if this object contains
BroadcastFilters
-
hasPerRequestFilters
public boolean hasPerRequestFilters()
Check if this object containsBroadcastFilters.- Returns:
- true if this object contains
BroadcastFilters
-
filter
protected BroadcastFilter.BroadcastAction filter(java.lang.Object object)
InvokeBroadcastFilters in the order they were added.- Parameters:
object- the broadcasted object.- Returns:
- BroadcastAction that tell Atmosphere to invoke the next filter or not.
-
filter
protected BroadcastFilter.BroadcastAction filter(AtmosphereResource r, java.lang.Object message, java.lang.Object originalMessage)
InvokeBroadcastFilters in the order they were added, with a uniqueAtmosphereRequest.- Parameters:
r-AtmosphereResourcemessage- the broadcasted object.message- the broadcasted object.- Returns:
- BroadcastAction that tell Atmosphere to invoke the next filter or not.
-
applyFilters
public java.util.List<java.lang.Object> applyFilters(AtmosphereResource r, java.util.List<java.lang.Object> cacheMessages)
Apply all filters to theAtmosphereResourceand the providedListof messages.- Parameters:
r-AtmosphereResourcecacheMessages- list of messages- Returns:
- the new list of objects.
-
setScheduledExecutorService
public BroadcasterConfig setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService scheduler)
Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvents. By default aScheduledExecutorServiceis used if this method is not invoked.- Parameters:
scheduler- to be used when broadcasting.- Returns:
- this.
-
getScheduledExecutorService
public java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
Return theScheduledExecutorServicethisBroadcastersupports. By default it returns anExecutors.newScheduledThreadPool(int)and will use the underlying number of core/protocol as an indication of the thread number.- Returns:
- An ExecutorService.
-
setBroadcasterCache
public BroadcasterConfig setBroadcasterCache(BroadcasterCache broadcasterCache)
Set aBroadcasterCache.- Parameters:
broadcasterCache- aBroadcasterCache- Returns:
- this
-
getBroadcasterCache
public BroadcasterCache getBroadcasterCache()
Get theBroadcasterCacheused for thisBroadcaster.- Returns:
- a
BroadcasterCache
-
unwrap
protected java.lang.Object unwrap(java.lang.Object o)
-
wrap
protected BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a, boolean wasUnwraped)
-
getAtmosphereConfig
public AtmosphereConfig getAtmosphereConfig()
Return theAtmosphereConfigvalue. This value might be null if the associatedBroadcasterhas been created manually.- Returns:
AtmosphereConfig
-
-