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 class BroadcasterConfig.DefaultBroadcasterCache
           
 
Field Summary
protected  ConcurrentLinkedQueue<BroadcastFilter> filters
           
protected  ConcurrentLinkedQueue<PerRequestBroadcastFilter> perRequestFilters
           
 
Constructor Summary
BroadcasterConfig(ExecutorService executorService, ExecutorService asyncWriteService, ScheduledExecutorService scheduler, AtmosphereConfig config, String name)
           
BroadcasterConfig(List<String> list, AtmosphereConfig config, boolean handleExecutors, String name)
           
BroadcasterConfig(List<String> list, AtmosphereConfig config, String name)
           
 
Method Summary
 boolean addFilter(BroadcastFilter e)
          Add a BroadcastFilter
protected  boolean addFilter(BroadcastFilter e, boolean init)
          Add a BroadcastFilter
protected  BroadcasterConfig broadcasterID(String name)
           
protected  void configExecutors()
           
 void destroy()
           
protected  void destroy(boolean force)
           
protected  BroadcastFilter.BroadcastAction filter(AtmosphereResource r, Object message, Object originalMessage)
          Invoke BroadcastFilter in the other they were added, with a unique AtmosphereRequest
protected  BroadcastFilter.BroadcastAction filter(Object object)
          Invoke BroadcastFilter in the other they were added.
 void forceDestroy()
          Force shutdown of all ExecutorService
 ExecutorService getAsyncWriteService()
          Return the ExecutorService this Broadcaster use for executing asynchronous write of events.
 AtmosphereConfig getAtmosphereConfig()
          Return the AtmosphereConfig value.
 BroadcasterCache getBroadcasterCache()
          Get a BroadcasterConfig.DefaultBroadcasterCache
 ExecutorService getDefaultExecutorService()
          Return the default ExecutorService.
 ExecutorService getExecutorService()
          Return the ExecutorService this Broadcaster support.
 ScheduledExecutorService getScheduledExecutorService()
          Return the ScheduledExecutorService this Broadcaster support.
 boolean hasFilters()
          Return true if this object contains BroadcastFilter
 boolean hasPerRequestFilters()
          Return true if this object contains BroadcastFilter
protected  void initClusterExtension()
           
 void removeAllFilters()
          Remove all BroadcastFilter
 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 BroadcasterConfig.DefaultBroadcasterCache
 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 AtmosphereResourceEvent.
 
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> list,
                         AtmosphereConfig config,
                         String name)

BroadcasterConfig

public BroadcasterConfig(List<String> list,
                         AtmosphereConfig config,
                         boolean handleExecutors,
                         String name)

BroadcasterConfig

public BroadcasterConfig(ExecutorService executorService,
                         ExecutorService asyncWriteService,
                         ScheduledExecutorService scheduler,
                         AtmosphereConfig config,
                         String name)
Method Detail

broadcasterID

protected BroadcasterConfig broadcasterID(String name)

initClusterExtension

protected void initClusterExtension()

configExecutors

protected void configExecutors()

setExecutorService

public BroadcasterConfig setExecutorService(ExecutorService executorService)
Set an ExecutorService which can be used to dispatch AtmosphereResourceEvent. By default, an Executors.newFixedThreadPool(int) of size 1 is used if that 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, an Executors.newFixedThreadPool(int) of size 1 is used if that method is not invoked.

Parameters:
executorService - to be used when broadcasting.
isExecutorShared - true is the life cycle of the ExecutorService will be executed by the application. That means Atmosphere will NOT invoke the shutdown method when this destroy()

getExecutorService

public ExecutorService getExecutorService()
Return the ExecutorService this Broadcaster support. By default it returns Executors.newFixedThreadPool(int) of size 1.

Returns:
An ExecutorService.

setAsyncWriteService

public BroadcasterConfig setAsyncWriteService(ExecutorService asyncWriteService)
Set an ExecutorService which can be used to write AtmosphereResourceEvent.getMessage(). By default, an Executors.newFixedThreadPool(int) is used if that 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, an Executors.newFixedThreadPool(int) is used if that method is not invoked.

Parameters:
asyncWriteService - to be used when writing events .
isAsyncExecutorShared - true is the life cycle of the ExecutorService will be executed by the application. That means Atmosphere will NOT invoke the shutdown method when this destroy()

getAsyncWriteService

public ExecutorService getAsyncWriteService()
Return the ExecutorService this Broadcaster use for executing asynchronous write of events. By default it returns Executors.newCachedThreadPool() of size 1.

Returns:
An ExecutorService.

addFilter

public boolean addFilter(BroadcastFilter e)
Add a BroadcastFilter

Parameters:
e - BroadcastFilter
Returns:
true if added.

addFilter

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

Parameters:
e - BroadcastFilter
Returns:
true if added.

destroy

public void destroy()

destroy

protected void destroy(boolean force)

forceDestroy

public void forceDestroy()
Force shutdown of all ExecutorService


removeFilter

public boolean removeFilter(BroadcastFilter filter)
Remove a BroadcastFilter

Parameters:
filter - BroadcastFilter
Returns:
true if removed

removeAllFilters

public void removeAllFilters()
Remove all BroadcastFilter


hasFilters

public boolean hasFilters()
Return true if this object contains BroadcastFilter

Returns:
true if this object contains BroadcastFilter

hasPerRequestFilters

public boolean hasPerRequestFilters()
Return true if this object contains BroadcastFilter

Returns:
true if this object contains BroadcastFilter

filter

protected BroadcastFilter.BroadcastAction filter(Object object)
Invoke BroadcastFilter in the other 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 BroadcastFilter in the other 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.

getDefaultExecutorService

public ExecutorService getDefaultExecutorService()
Return the default ExecutorService.

Returns:
the defaultExecutorService

setScheduledExecutorService

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

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

getScheduledExecutorService

public ScheduledExecutorService getScheduledExecutorService()
Return the ScheduledExecutorService this Broadcaster support. By default it returns 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 BroadcasterConfig.DefaultBroadcasterCache

Parameters:
broadcasterCache - a BroadcasterConfig.DefaultBroadcasterCache
Returns:
this

getBroadcasterCache

public BroadcasterCache getBroadcasterCache()
Get a BroadcasterConfig.DefaultBroadcasterCache

Returns:
this

getAtmosphereConfig

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

Returns:
AtmosphereConfig


Copyright © 2012. All Rights Reserved.