org.atmosphere.cpr
Interface Broadcaster<E extends AtmosphereEvent>

All Known Implementing Classes:
DefaultBroadcaster

public interface Broadcaster<E extends AtmosphereEvent>

A Broadcaster is responsible for delivering messages to its subscribed AtmosphereEvent, which are representing a suspended response. AtmosphereEvent can be added using addAtmosphereEvent(E), so when broadcast(java.lang.Object) execute, AtmosphereHandler.onMessage(org.atmosphere.cpr.AtmosphereEvent) will by invoked and the suspended connection will have a chance to write the message available using AtmosphereEvent.getMessage()
A Broadcaster, by default, wil use the calling Thread to execute the broadcast operation. To enable parallel execution, you can set an ExecutorService which will be used to concurrently broadcast message.

Author:
Jeanfrancois Arcand

Method Summary
 boolean addAtmosphereEvent(E event)
          Add a AtmosphereEvent to the list of item to be notified when the broadcast(java.lang.Object) is invoked.
 void broadcast(Object o)
          Broadcast the Object to all suspended response, e.g.
 void broadcast(Object o, E event)
          Broadcast the Object to all suspended response, e.g.
 void broadcast(Object o, Set<E> subset)
          Broadcast the Object to all suspended response, e.g.
 ExecutorService getExecutorService()
          Return the ExecutorService this Broadcaster support.
 boolean removeAtmosphereEvent(E event)
          Remove a AtmosphereEvent from the list of item to be notified when the broadcast(java.lang.Object) is invoked.
 void setExecutorService(ExecutorService executorService)
          Set an ExecutorService which can be used to dispatch AtmosphereEvent.
 

Method Detail

broadcast

void broadcast(Object o)
Broadcast the Object to all suspended response, e.g. invoke AtmosphereHandler.onMessage(org.atmosphere.cpr.AtmosphereEvent).

Parameters:
o - and Object to be shared.

broadcast

void broadcast(Object o,
               E event)
Broadcast the Object to all suspended response, e.g. invoke AtmosphereHandler.onMessage(org.atmosphere.cpr.AtmosphereEvent) with an instance of AtmosphereEvent, representing a set of AtmosphereHandler.

Parameters:
o - and Object to be shared.
event - an AtmosphereEvent

broadcast

void broadcast(Object o,
               Set<E> subset)
Broadcast the Object to all suspended response, e.g. invoke AtmosphereHandler.onMessage(org.atmosphere.cpr.AtmosphereEvent) with a Set of AtmosphereEvent, representing a set of AtmosphereHandler.

Parameters:
o - and Object to be shared.
event - an AtmosphereEvent

addAtmosphereEvent

boolean addAtmosphereEvent(E event)
Add a AtmosphereEvent to the list of item to be notified when the broadcast(java.lang.Object) is invoked.

Parameters:
event - an AtmosphereEvent
Returns:
true if added, false if it was already added.

removeAtmosphereEvent

boolean removeAtmosphereEvent(E event)
Remove a AtmosphereEvent from the list of item to be notified when the broadcast(java.lang.Object) is invoked.

Parameters:
event - an AtmosphereEvent
Returns:
true if removed, false if it was already removed.

setExecutorService

void setExecutorService(ExecutorService executorService)
Set an ExecutorService which can be used to dispatch AtmosphereEvent. Set it to null if broadcast must be executed using the calling thread (this is the default).

Parameters:
executorService - to be used when broadcasting.

getExecutorService

ExecutorService getExecutorService()
Return the ExecutorService this Broadcaster support. By defaul it return null, which means the calling thread is used when invoking broadcast(java.lang.Object)

Returns:
An ExecutorService.


Copyright © 2009 SUN Microsystems. All Rights Reserved.