Interface Broadcaster

All Known Implementing Classes:
AbstractBroadcasterProxy, DefaultBroadcaster, ExcludeSessionBroadcaster, SimpleBroadcaster

public interface Broadcaster
A Broadcaster is responsible for delivering messages to its subscribed AtmosphereResources, which are representing suspended responses. AtmosphereResource can be added using addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource), so when broadcast(java.lang.Object) is executed, 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().

A Broadcaster will by default use an ExecutorService, and the number of Threads will be computed based on the number of cores/CPUs of the OS under which the application runs. Thus invoking broadcast(Object) will be executed asynchronously so this is important to wait for the Future.get() to awake/unblock to be guaranteed that the operation has completed.

One final word on Broadcaster: by default, a Broadcaster will broadcast using all 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) ):

  • 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