Package org.atmosphere.cpr
Class BroadcasterConfig
java.lang.Object
org.atmosphere.cpr.BroadcasterConfig
- Author:
- Jeanfrancois Arcand
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceManipulate the message before and after they are getting filtered byBroadcastFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentLinkedQueue<BroadcastFilter> protected final ConcurrentLinkedQueue<PerRequestBroadcastFilter> -
Constructor Summary
ConstructorsConstructorDescriptionBroadcasterConfig(ExecutorService executorService, ExecutorService asyncWriteService, ScheduledExecutorService scheduler, AtmosphereConfig config, String broadcasterId) Create a new BroadcasterConfig.BroadcasterConfig(List<String> broadcastFilters, AtmosphereConfig config, boolean handleExecutors, String broadcasterId) Create a new BroadcasterConfig.BroadcasterConfig(List<String> broadcastFilters, AtmosphereConfig config, String broadcasterId) Create a new BroadcasterConfig. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd aBroadcastFilter.protected booleanaddFilter(BroadcastFilter e, boolean init) Add aBroadcastFilter.applyFilters(AtmosphereResource r, List<Object> cacheMessages) Apply all filters to theAtmosphereResourceand the providedListof messages.protected BroadcasterConfigbroadcasterID(String broadcasterId) protected voidprotected voidvoiddestroy()protected voiddestroy(boolean force) protected BroadcastFilter.BroadcastActionInvokeBroadcastFilters in the order they were added.protected BroadcastFilter.BroadcastActionfilter(AtmosphereResource r, Object message, Object originalMessage) InvokeBroadcastFilters in the order they were added, with a uniqueAtmosphereRequest.filters()Return the current list of installedBroadcastFilters.voidForce shutdown of allExecutorServices.Return theExecutorServicethisBroadcasteruse for executing asynchronous write of events.Return theAtmosphereConfigvalue.Get theBroadcasterCacheused for thisBroadcaster.Return theExecutorServicethisBroadcastersupports.Return theScheduledExecutorServicethisBroadcastersupports.booleanbooleanCheck if this object containsBroadcastFilters.booleanCheck if this object containsBroadcastFilters.init()Initialize BroadcastFilters and BroadcasterCache.protected voidvoidRemove allBroadcastFilters.booleanremoveFilter(BroadcastFilter filter) Remove aBroadcastFilter.setAsyncWriteService(ExecutorService asyncWriteService) Set anExecutorServicewhich can be used to writeAtmosphereResourceEvent.getMessage().setAsyncWriteService(ExecutorService asyncWriteService, boolean isAsyncExecutorShared) Set anExecutorServicewhich can be used to writeAtmosphereResourceEvent.getMessage().setBroadcasterCache(BroadcasterCache broadcasterCache) Set aBroadcasterCache.setExecutorService(ExecutorService executorService) Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvent.setExecutorService(ExecutorService executorService, boolean isExecutorShared) Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvent.Set anExecutorServicewhich can be used to dispatchAtmosphereResourceEvents.protected Objectprotected BroadcastFilter.BroadcastActionwrap(BroadcastFilter.BroadcastAction a, boolean wasUnwraped)
-
Field Details
-
filters
-
perRequestFilters
-
-
Constructor Details
-
BroadcasterConfig
public BroadcasterConfig(List<String> broadcastFilters, AtmosphereConfig config, String broadcasterId) Create a new BroadcasterConfig. Remember to call init() after the object has been created. -
BroadcasterConfig
public BroadcasterConfig(List<String> broadcastFilters, AtmosphereConfig config, boolean handleExecutors, String broadcasterId) Create a new BroadcasterConfig. Remember to call init() after the object has been created. -
BroadcasterConfig
public BroadcasterConfig(ExecutorService executorService, ExecutorService asyncWriteService, ScheduledExecutorService scheduler, AtmosphereConfig config, String broadcasterId) Create a new BroadcasterConfig. Remember to call init() after the object has been created.
-
-
Method Details
-
init
Initialize BroadcastFilters and BroadcasterCache. Must always be called after creating a new BroadcasterConfig! -
broadcasterID
-
initClusterExtension
protected void initClusterExtension() -
handleExecutors
public boolean handleExecutors() -
configExecutors
protected void configExecutors() -
setExecutorService
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(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
Return theExecutorServicethisBroadcastersupports. By default it returns the result ofExecutorsFactory.getMessageDispatcher(AtmosphereConfig, String)}.- Returns:
- An ExecutorService.
-
setAsyncWriteService
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(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
Return theExecutorServicethisBroadcasteruse for executing asynchronous write of events. By default it returns the result ofExecutorsFactory.getAsyncOperationExecutor(AtmosphereConfig, String).- Returns:
- An ExecutorService.
-
addFilter
Add aBroadcastFilter.- Parameters:
e-BroadcastFilter- Returns:
- true if successfully added
-
addFilter
Add aBroadcastFilter.- Parameters:
e-BroadcastFilter- Returns:
- true if successfully added
-
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
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
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, Object message, 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
Apply all filters to theAtmosphereResourceand the providedListof messages.- Parameters:
r-AtmosphereResourcecacheMessages- list of messages- Returns:
- the new list of objects.
-
setScheduledExecutorService
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
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
Set aBroadcasterCache.- Parameters:
broadcasterCache- aBroadcasterCache- Returns:
- this
-
getBroadcasterCache
Get theBroadcasterCacheused for thisBroadcaster.- Returns:
- a
BroadcasterCache
-
unwrap
-
wrap
protected BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a, boolean wasUnwraped) -
getAtmosphereConfig
Return theAtmosphereConfigvalue. This value might be null if the associatedBroadcasterhas been created manually.- Returns:
AtmosphereConfig
-