Package org.atmosphere.cpr
Class DefaultMetaBroadcaster
java.lang.Object
org.atmosphere.cpr.DefaultMetaBroadcaster
- All Implemented Interfaces:
MetaBroadcaster,AtmosphereConfigAware
Broadcast events to all or a subset of available
Broadcasters based on their Broadcaster.getID() value.
This class allows broadcasting events to a set of broadcasters that maps to some String like:
// Broadcast the event to all Broadcaster ID starting with /hello
broadcast("/hello", event)
// Broadcast the event to all Broadcaster ID
broaccast("/*", event);
The rule used is similar to path/URI mapping used by technology like Servlet, Jersey, etc.
NOTE: Broadcasters' name must start with / in order to get retrieved by this class.
This class is NOT thread safe.
If you want to use MetaBroadcaster with Jersey or any framework, make sure all Broadcaster.getID()
starts with '/'. For example, with Jersey:
- Author:
- Jeanfrancois Arcand
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.atmosphere.cpr.MetaBroadcaster
MetaBroadcaster.MetaBroadcasterCache, MetaBroadcaster.NoCache, MetaBroadcaster.ThirtySecondsCache -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd aBroadcasterListenerto all mappedBroadcasters.protected org.atmosphere.cpr.DefaultMetaBroadcaster.MetaBroadcasterFuturebroadcast(String path, Object message, int time, TimeUnit unit, boolean delay, boolean cacheMessage) broadcastTo(String broadcasterID, Object message) Broadcast the message to all Broadcasters whoseBroadcaster.getID()matches the broadcasterID value.broadcastTo(String broadcasterID, Object message, boolean cacheMessage) Broadcast the message to all Broadcasters whoseBroadcaster.getID()matches the broadcasterID value.Set theMetaBroadcaster.MetaBroadcasterCache.voidconfigure(AtmosphereConfig config) Configure an AtmosphereFramework object.Delay the message delivery to Broadcasters whoseBroadcaster.getID()matches the broadcasterID value.voiddestroy()protected MetaBroadcasterFlush the cached messages.protected org.atmosphere.cpr.DefaultMetaBroadcaster.MetaBroadcasterFutureRemove theBroadcasterListener.scheduleTo(String broadcasterID, Object message, int time, TimeUnit unit) Broadcast the message at a fixed rate to all Broadcasters whoseBroadcaster.getID()matches the broadcasterID value.
-
Field Details
-
MAPPING_REGEX
- See Also:
-
-
Constructor Details
-
DefaultMetaBroadcaster
public DefaultMetaBroadcaster()
-
-
Method Details
-
configure
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Parameters:
config-AtmosphereConfig
-
broadcast
-
map
-
broadcastTo
Description copied from interface:MetaBroadcasterBroadcast the message to all Broadcasters whoseBroadcaster.getID()matches the broadcasterID value.- Specified by:
broadcastToin interfaceMetaBroadcaster- Parameters:
broadcasterID- a String (or path) that can potentially match aBroadcaster.getID()message- a message to be broadcasted- Returns:
- a Future
-
broadcastTo
public Future<List<Broadcaster>> broadcastTo(String broadcasterID, Object message, boolean cacheMessage) Description copied from interface:MetaBroadcasterBroadcast the message to all Broadcasters whoseBroadcaster.getID()matches the broadcasterID value.- Specified by:
broadcastToin interfaceMetaBroadcaster- Parameters:
broadcasterID- a String (or path) that can potentially match aBroadcaster.getID()message- a message to be broadcastedcacheMessage- allow the cache to be cached or not.- Returns:
- a Future
-
flushCache
Flush the cached messages.- Returns:
- this
-
scheduleTo
public Future<List<Broadcaster>> scheduleTo(String broadcasterID, Object message, int time, TimeUnit unit) Description copied from interface:MetaBroadcasterBroadcast the message at a fixed rate to all Broadcasters whoseBroadcaster.getID()matches the broadcasterID value. This operation will invokeBroadcaster.scheduleFixedBroadcast(Object, long, java.util.concurrent.TimeUnit)}- Specified by:
scheduleToin interfaceMetaBroadcaster- Parameters:
broadcasterID- a String (or path) that can potentially match aBroadcaster.getID()message- a message to be broadcastedtime- a time valueunit- aTimeUnit- Returns:
- a Future
-
delayTo
public Future<List<Broadcaster>> delayTo(String broadcasterID, Object message, int time, TimeUnit unit) Description copied from interface:MetaBroadcasterDelay the message delivery to Broadcasters whoseBroadcaster.getID()matches the broadcasterID value. This operation will invokeBroadcaster.delayBroadcast(Object, long, java.util.concurrent.TimeUnit)(Object, long, java.util.concurrent.TimeUnit)}}- Specified by:
delayToin interfaceMetaBroadcaster- Parameters:
broadcasterID- a String (or path) that can potentially match aBroadcaster.getID()message- a message to be broadcastedtime- a time valueunit- aTimeUnit- Returns:
- a Future
-
addBroadcasterListener
Description copied from interface:MetaBroadcasterAdd aBroadcasterListenerto all mappedBroadcasters.- Specified by:
addBroadcasterListenerin interfaceMetaBroadcaster- Parameters:
b-BroadcasterListener- Returns:
- this
-
removeBroadcasterListener
Description copied from interface:MetaBroadcasterRemove theBroadcasterListener.- Specified by:
removeBroadcasterListenerin interfaceMetaBroadcaster- Parameters:
b-BroadcasterListener- Returns:
- this
-
cache
Description copied from interface:MetaBroadcasterSet theMetaBroadcaster.MetaBroadcasterCache. Default isMetaBroadcaster.NoCache.- Specified by:
cachein interfaceMetaBroadcaster- Parameters:
cache-- Returns:
- this
-
destroy
public void destroy()- Specified by:
destroyin interfaceMetaBroadcaster
-