public interface Broadcaster
AtmosphereResource, which are representing a suspended response.
AtmosphereResource can be added using addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource),
so when broadcast(java.lang.Object) execute,
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) will
be invoked and the suspended connection will have a chance to write the
message available using AtmosphereResourceEvent.getMessage()
Broadcaster, by default, will use an ExecutorService, and the
number of Thread will be computed based on the core/cpu of the OS under
which the application run. Thus invoking broadcast(Object) will be executed
asynchronously so this is important to wait for the Future.get() to awake/unblock to be garantee
the operation has completed.
AtmosphereResource on which the response has been suspended, e.g. {AtmosphereResource#suspend()}
has been invoked. This behavior is configurable and you can configure it by invoking the
setScope(org.atmosphere.cpr.Broadcaster.SCOPE) ):| Modifier and Type | Interface and Description |
|---|---|
static class |
Broadcaster.POLICY |
static class |
Broadcaster.SCOPE |
| Modifier and Type | Method and Description |
|---|---|
Broadcaster |
addAtmosphereResource(AtmosphereResource resource)
Add a
AtmosphereResource to the list of item to be notified when
the broadcast(T) is invoked. |
void |
addBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
|
Broadcaster |
addBroadcasterListener(BroadcasterListener b)
Add a
BroadcasterListener |
<T> java.util.concurrent.Future<T> |
awaitAndBroadcast(T t,
long time,
java.util.concurrent.TimeUnit timeUnit)
Await for available
AtmosphereResource before broadcasting. |
<T> java.util.concurrent.Future<T> |
broadcast(T o)
Broadcast the
Object to all suspended response, e.g. |
<T> java.util.concurrent.Future<T> |
broadcast(T o,
AtmosphereResource resource)
Broadcast the
Object to all suspended response, e.g. |
<T> java.util.concurrent.Future<T> |
broadcast(T o,
java.util.Set<AtmosphereResource> subset)
Broadcast the
Object to all suspended response, e.g. |
<T> java.util.concurrent.Future<T> |
broadcastOnResume(T o)
Broadcast the
Object when an AtmosphereResource is resumed by a timeout or when using
AtmosphereResource.resume() |
<T> java.util.concurrent.Future<T> |
delayBroadcast(T o)
Delay the broadcast operation.
|
<T> java.util.concurrent.Future<T> |
delayBroadcast(T o,
long delay,
java.util.concurrent.TimeUnit t)
Delay the broadcast operation.
|
void |
destroy()
Destroy this instance and shutdown it's associated
ExecutorService |
java.util.Collection<AtmosphereResource> |
getAtmosphereResources()
Return an
List of AtmosphereResource. |
BroadcasterConfig |
getBroadcasterConfig()
Return the current
BroadcasterConfig |
java.lang.String |
getID()
Return the id of this
Broadcaster |
Broadcaster.SCOPE |
getScope()
Return the
Broadcaster.SCOPE |
boolean |
isDestroyed()
Return true if that
Broadcaster has been destroyed |
void |
releaseExternalResources()
Release external resources associated with this Broadcaster.
|
Broadcaster |
removeAtmosphereResource(AtmosphereResource resource)
Remove a
AtmosphereResource from the list of item to be notified when
the broadcast(T) is invoked. |
void |
removeBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
Remove a
BroadcasterLifeCyclePolicyListener |
Broadcaster |
removeBroadcasterListener(BroadcasterListener b)
Remove a
BroadcasterListener |
void |
resumeAll()
Resume all suspended responses (
AtmosphereResource) added via
addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource). |
<T> java.util.concurrent.Future<T> |
scheduleFixedBroadcast(T o,
long waitFor,
long period,
java.util.concurrent.TimeUnit t)
Broadcast periodically.
|
<T> java.util.concurrent.Future<T> |
scheduleFixedBroadcast(T o,
long period,
java.util.concurrent.TimeUnit t)
Broadcast periodically.
|
void |
setBroadcasterConfig(BroadcasterConfig bc)
Set the
BroadcasterConfig instance. |
void |
setBroadcasterLifeCyclePolicy(BroadcasterLifeCyclePolicy policy)
Set the
BroadcasterLifeCyclePolicy. |
void |
setID(java.lang.String name)
Set the id of this
Broadcaster |
void |
setScope(Broadcaster.SCOPE scope)
Set the scope.
|
void |
setSuspendPolicy(long maxSuspended,
Broadcaster.POLICY policy)
Set the maximum number of suspended
AtmosphereResource. |
void setSuspendPolicy(long maxSuspended,
Broadcaster.POLICY policy)
AtmosphereResource. If the max is reached, Atmosphere will either
resume AtmosphereResource using Broadcaster.POLICY.FIFO (first in first out)
or Broadcaster.POLICY.REJECT the AtmosphereResource.
By default the number is uunlimited.maxSuspended - max suspended<T> java.util.concurrent.Future<T> broadcast(T o)
Object to all suspended response, e.g. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent).o - and Object to be broadcasted.Future that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> delayBroadcast(T o)
Object will be broadcasted
when the first broadcast(java.lang.Object)
is invoked.o - and Object to be broadcasted.Future that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> delayBroadcast(T o,
long delay,
java.util.concurrent.TimeUnit t)
Object will be broadcasted once the
specified delay expires or when the first broadcast(java.lang.Object)o - and Object to be broadcasted.delay - Amount of time to delay.t - a TimeUnit of delay.Future that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> scheduleFixedBroadcast(T o,
long period,
java.util.concurrent.TimeUnit t)
Object will be broadcasted after every period
specified time frame expires. If the TimeUnit is set null, the
Object will be broadcasted when the first broadcast(java.lang.Object)
is invoked.o - and Object to be broadcasted.period - Every so often broadcast.t - a TimeUnit of period.Future that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> scheduleFixedBroadcast(T o,
long waitFor,
long period,
java.util.concurrent.TimeUnit t)
Object will be broadcasted after every period
specified time frame expires. If the TimeUnit is set null, the
Object will be broadcasted when the first broadcast(java.lang.Object) * is invoked.o - and Object to be broadcasted.waitFor - Wait for that long before first broadcast.period - The period inbetween broadcast.t - a TimeUnit of waitFor and period.Future that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> broadcast(T o,
AtmosphereResource resource)
Object to all suspended response, e.g. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with an instance of AtmosphereResource, representing
a single suspended response..o - and Object to be broadcasted.resource - an AtmosphereResourceFuture that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> broadcastOnResume(T o)
Object when an AtmosphereResource is resumed by a timeout or when using
AtmosphereResource.resume()o - and Object to be broadcasted.Future that can be used to synchronize using the Future.get()<T> java.util.concurrent.Future<T> broadcast(T o,
java.util.Set<AtmosphereResource> subset)
Object to all suspended response, e.g. invoke
AtmosphereHandler.onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent) with a Set of AtmosphereResource,
representing a set of AtmosphereHandler.o - and Object to be broadcasted.subset - a Set of AtmosphereResourceFuture that can be used to synchronize using the Future.get()Broadcaster addAtmosphereResource(AtmosphereResource resource)
AtmosphereResource to the list of item to be notified when
the broadcast(T) is invoked. It is strongly recommended to suspend the AtmosphereResource
before adding it to a Broadcaster.resource - an AtmosphereResourceBroadcaster removeAtmosphereResource(AtmosphereResource resource)
AtmosphereResource from the list of item to be notified when
the broadcast(T) is invoked.resource - an AtmosphereResourcevoid setBroadcasterConfig(BroadcasterConfig bc)
BroadcasterConfig instance.bc - Configuration to be set.BroadcasterConfig getBroadcasterConfig()
BroadcasterConfigBroadcasterConfigvoid destroy()
ExecutorServicejava.util.Collection<AtmosphereResource> getAtmosphereResources()
List of AtmosphereResource.List of AtmosphereResource associated with this Broadcaster.addAtmosphereResource(AtmosphereResource)void setScope(Broadcaster.SCOPE scope)
scope - Broadcaster.SCOPE to set.Broadcaster.SCOPE getScope()
Broadcaster.SCOPEBroadcaster.SCOPE of Broadcaster.void setID(java.lang.String name)
Broadcastername - ID of this Broadcasterjava.lang.String getID()
BroadcasterBroadcastervoid resumeAll()
AtmosphereResource) added via
addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource).void releaseExternalResources()
AtmosphereResource and some resource (like database connections, JMS queue, etc.) needs to be
closed.void setBroadcasterLifeCyclePolicy(BroadcasterLifeCyclePolicy policy)
BroadcasterLifeCyclePolicy. Make sure you are selecting the right policy
to avoid unexpected situation.policy - a BroadcasterLifeCyclePolicyvoid addBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
b - a BroadcasterLifeCyclePolicyListenervoid removeBroadcasterLifeCyclePolicyListener(BroadcasterLifeCyclePolicyListener b)
BroadcasterLifeCyclePolicyListenerb - a BroadcasterLifeCyclePolicyListenerboolean isDestroyed()
Broadcaster has been destroyedBroadcaster has been destroyed<T> java.util.concurrent.Future<T> awaitAndBroadcast(T t,
long time,
java.util.concurrent.TimeUnit timeUnit)
AtmosphereResource before broadcasting. This method will block until
addAtmosphereResource(AtmosphereResource) gets invoked.Broadcaster addBroadcasterListener(BroadcasterListener b)
BroadcasterListenerb - a BroadcasterListenerBroadcaster removeBroadcasterListener(BroadcasterListener b)
BroadcasterListenerb - a BroadcasterListenerCopyright © 2018. All Rights Reserved.