A Broadcaster is responsible for delivering messages to its subscribed {@link AtmosphereResource}, which are representing a suspended response. {@link AtmosphereResource} can be added using {@link Broadcaster#addAtmosphereResource}, so when {@link #broadcast(java.lang.Object)} execute,{@link AtmosphereHandler#onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent)} willbe invoked and the suspended connection will have a chance to write the message available using {@link AtmosphereResourceEvent#getMessage()}
A {@link Broadcaster}, by default, will use an {@link ExecutorService}, and the number of Thread will be computed based on the core/cpu of the OS under which the application run. Thus invoking {@link org.atmosphere.cpr.Broadcaster#broadcast(Object)} will be executed
asynchronously so this is important to wait for the {@link Future#get} to awake/unblock to be garanteethe operation has completed.
One final word on Broadcaster: by default, a Broadcaster will broadcast using all {@link 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 {@link Broadcaster#setScope(org.atmosphere.cpr.Broadcaster.SCOPE)} ):
- REQUEST: broadcast events only to the AtmosphereResourceEvent associated with the current request.
- APPLICATION: broadcast events to all AtmosphereResourceEvent created for the current web application.
- VM: broadcast events to all AtmosphereResourceEvent created inside the current virtual machine.
@author Jeanfrancois Arcand