org.atmosphere.cpr
Class BroadcasterConfig

java.lang.Object
  extended by org.atmosphere.cpr.BroadcasterConfig

public class BroadcasterConfig
extends Object

Handle Broadcaster configuration like ExecutorService and BroadcastFilter.

Author:
Jeanfrancois Arcand

Nested Class Summary
static interface BroadcasterConfig.FilterManipulator
          Manipulate the message before and after they are getting filtered by BroadcastFilter
 
Field Summary
protected  ConcurrentLinkedQueue<BroadcastFilter> filters
           
protected  ConcurrentLinkedQueue<PerRequestBroadcastFilter> perRequestFilters
           
 
Constructor Summary
BroadcasterConfig(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
 boolean addFilter(BroadcastFilter e)
          Add a BroadcastFilter.
protected  boolean addFilter(BroadcastFilter e, boolean init)
          Add a BroadcastFilter.
 List<Object> applyFilters(AtmosphereResource r, List<Object> cacheMessages)
          Apply all filters to the AtmosphereResource and the provided List of messages.
protected  BroadcasterConfig broadcasterID(String broadcasterId)
           
protected  void configExecutors()
           
protected  void configureSharedCacheExecutor()
           
 void destroy()
           
protected  void destroy(boolean force)
           
protected  BroadcastFilter.BroadcastAction filter(AtmosphereResource r, Object message, Object originalMessage)
          Invoke BroadcastFilters in the order they were added, with a unique AtmosphereRequest.
protected  BroadcastFilter.BroadcastAction filter(Object object)
          Invoke BroadcastFilters in the order they were added.
 Collection<BroadcastFilter> filters()
          Return the current list of installed BroadcastFilters.
 void forceDestroy()
          Force shutdown of all ExecutorServices.
 ExecutorService getAsyncWriteService()
          Return the ExecutorService this Broadcaster use for executing asynchronous write of events.
 AtmosphereConfig getAtmosphereConfig()
          Return the AtmosphereConfig value.
 BroadcasterCache getBroadcasterCache()
          Get the BroadcasterCache used for this Broadcaster.
 ExecutorService getExecutorService()
          Return the ExecutorService this Broadcaster supports.
 ScheduledExecutorService getScheduledExecutorService()
          Return the ScheduledExecutorService this Broadcaster supports.
 boolean handleExecutors()
           
 boolean hasFilters()
          Check if this object contains BroadcastFilters.
 boolean hasPerRequestFilters()
          Check if this object contains BroadcastFilters.
 BroadcasterConfig init()
          Initialize BroadcastFilters and BroadcasterCache.
protected  void initClusterExtension()
           
 void removeAllFilters()
          Remove all BroadcastFilters.
 boolean removeFilter(BroadcastFilter filter)
          Remove a BroadcastFilter.
 BroadcasterConfig setAsyncWriteService(ExecutorService asyncWriteService)
          Set an ExecutorService which can be used to write AtmosphereResourceEvent.getMessage().
 BroadcasterConfig setAsyncWriteService(ExecutorService asyncWriteService, boolean isAsyncExecutorShared)
          Set an ExecutorService which can be used to write AtmosphereResourceEvent.getMessage().
 BroadcasterConfig setBroadcasterCache(BroadcasterCache broadcasterCache)
          Set a BroadcasterCache.
 BroadcasterConfig setExecutorService(ExecutorService executorService)
          Set an ExecutorService which can be used to dispatch AtmosphereResourceEvent.
 BroadcasterConfig setExecutorService(ExecutorService executorService, boolean isExecutorShared)
          Set an ExecutorService which can be used to dispatch AtmosphereResourceEvent.
 BroadcasterConfig setScheduledExecutorService(ScheduledExecutorService scheduler)
          Set an ExecutorService which can be used to dispatch AtmosphereResourceEvents.
protected  Object unwrap(Object o)
           
protected  BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a, boolean wasUnwraped)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filters

protected final ConcurrentLinkedQueue<BroadcastFilter> filters

perRequestFilters

protected final ConcurrentLinkedQueue<PerRequestBroadcastFilter> perRequestFilters
Constructor Detail

BroadcasterConfig

public BroadcasterConfig(List<String> broadcastFilters,
                         AtmosphereConfig config,
                         String broadcasterId)
Create a new BroadcasterConfig. Remember to call init() after the object has been created.

Parameters:
broadcastFilters -
config -
broadcasterId -

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.

Parameters:
broadcastFilters -
config -
handleExecutors -
broadcasterId -

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.

Parameters:
executorService -
asyncWriteService -
scheduler -
config -
name -
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(String broadcasterId)

initClusterExtension

protected void initClusterExtension()

handleExecutors

public boolean handleExecutors()

configExecutors

protected void configExecutors()

setExecutorService

public BroadcasterConfig setExecutorService(ExecutorService executorService)
Set an ExecutorService which can be used to dispatch AtmosphereResourceEvent. By default, the result of ExecutorsFactory.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 an ExecutorService which can be used to dispatch AtmosphereResourceEvent. By default, the result of ExecutorsFactory.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 the ExecutorService will be executed by the application. It means Atmosphere will NOT invoke the shutdown method when destroy() is invoked.

getExecutorService

public ExecutorService getExecutorService()
Return the ExecutorService this Broadcaster supports. By default it returns the result of ExecutorsFactory.getMessageDispatcher(AtmosphereConfig, String)}.

Returns:
An ExecutorService.

setAsyncWriteService

public BroadcasterConfig setAsyncWriteService(ExecutorService asyncWriteService)
Set an ExecutorService which can be used to write AtmosphereResourceEvent.getMessage(). By default, the result of ExecutorsFactory.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 an ExecutorService which can be used to write AtmosphereResourceEvent.getMessage(). By default, the result of ExecutorsFactory.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 the ExecutorService will be executed by the application. It means Atmosphere will NOT invoke the shutdown method when this destroy() is invoked.

getAsyncWriteService

public ExecutorService getAsyncWriteService()
Return the ExecutorService this Broadcaster use for executing asynchronous write of events. By default it returns the result of ExecutorsFactory.getAsyncOperationExecutor(AtmosphereConfig, String).

Returns:
An ExecutorService.

addFilter

public boolean addFilter(BroadcastFilter e)
Add a BroadcastFilter.

Parameters:
e - BroadcastFilter
Returns:
true if successfully added

addFilter

protected boolean addFilter(BroadcastFilter e,
                            boolean init)
Add a BroadcastFilter.

Parameters:
e - BroadcastFilter
Returns:
true if successfully added

filters

public Collection<BroadcastFilter> filters()
Return the current list of installed BroadcastFilters.

Returns:
the current list of installed BroadcastFilters

destroy

public void destroy()

destroy

protected void destroy(boolean force)

forceDestroy

public void forceDestroy()
Force shutdown of all ExecutorServices.


removeFilter

public boolean removeFilter(BroadcastFilter filter)
Remove a BroadcastFilter.

Parameters:
filter - BroadcastFilter
Returns:
true if successfully removed

removeAllFilters

public void removeAllFilters()
Remove all BroadcastFilters.


hasFilters

public boolean hasFilters()
Check if this object contains BroadcastFilters.

Returns:
true if this object contains BroadcastFilters

hasPerRequestFilters

public boolean hasPerRequestFilters()
Check if this object contains BroadcastFilters.

Returns:
true if this object contains BroadcastFilters

filter

protected BroadcastFilter.BroadcastAction filter(Object object)
Invoke BroadcastFilters 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)
Invoke BroadcastFilters in the order they were added, with a unique AtmosphereRequest.

Parameters:
r - AtmosphereResource
message - the broadcasted object.
message - the broadcasted object.
Returns:
BroadcastAction that tell Atmosphere to invoke the next filter or not.

applyFilters

public List<Object> applyFilters(AtmosphereResource r,
                                 List<Object> cacheMessages)
Apply all filters to the AtmosphereResource and the provided List of messages.

Parameters:
r - AtmosphereResource
cacheMessages - list of messages
Returns:
the new list of objects.

setScheduledExecutorService

public BroadcasterConfig setScheduledExecutorService(ScheduledExecutorService scheduler)
Set an ExecutorService which can be used to dispatch AtmosphereResourceEvents. By default a ScheduledExecutorService is used if this method is not invoked.

Parameters:
scheduler - to be used when broadcasting.
Returns:
this.

getScheduledExecutorService

public ScheduledExecutorService getScheduledExecutorService()
Return the ScheduledExecutorService this Broadcaster supports. By default it returns an Executors.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 a BroadcasterCache.

Parameters:
broadcasterCache - a BroadcasterCache
Returns:
this

getBroadcasterCache

public BroadcasterCache getBroadcasterCache()
Get the BroadcasterCache used for this Broadcaster.

Returns:
a BroadcasterCache

unwrap

protected Object unwrap(Object o)

wrap

protected BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a,
                                               boolean wasUnwraped)

getAtmosphereConfig

public AtmosphereConfig getAtmosphereConfig()
Return the AtmosphereConfig value. This value might be null if the associated Broadcaster has been created manually.

Returns:
AtmosphereConfig


Copyright © 2014. All Rights Reserved.