org.atmosphere.cpr
Class DefaultBroadcaster

java.lang.Object
  extended by org.atmosphere.cpr.DefaultBroadcaster
All Implemented Interfaces:
Broadcaster<AtmosphereEventImpl>

public class DefaultBroadcaster
extends Object
implements Broadcaster<AtmosphereEventImpl>

Broadcaster implementation. Broadcast messages to suspended reponse using the caller's Thread. This basic Broadcaster isn't using any ExecutorService to broadcast messages, so it is single threaded.

Author:
Jeanfrancois Arcand

Constructor Summary
DefaultBroadcaster(AtmosphereHandler atmosphereHandler)
           
 
Method Summary
 boolean addAtmosphereEvent(AtmosphereEventImpl event)
          Add a AtmosphereEvent to the list of item to be notified when the Broadcaster.broadcast(java.lang.Object) is invoked.
 void broadcast(Object msg)
          Broadcast the Object to all suspended response, e.g.
 void broadcast(Object msg, AtmosphereEventImpl event)
          Broadcast the Object to all suspended response, e.g.
 void broadcast(Object msg, Set<AtmosphereEventImpl> subset)
          Broadcast the Object to all suspended response, e.g.
 ExecutorService getExecutorService()
          Return the ExecutorService this Broadcaster support.
 boolean removeAtmosphereEvent(AtmosphereEventImpl event)
          Remove a AtmosphereEvent from the list of item to be notified when the Broadcaster.broadcast(java.lang.Object) is invoked.
 void setExecutorService(ExecutorService executorService)
          Set an ExecutorService which can be used to dispatch AtmosphereEvent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBroadcaster

public DefaultBroadcaster(AtmosphereHandler atmosphereHandler)
Method Detail

broadcast

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

Specified by:
broadcast in interface Broadcaster<AtmosphereEventImpl>
Parameters:
msg - and Object to be shared.

broadcast

public void broadcast(Object msg,
                      AtmosphereEventImpl 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.

Specified by:
broadcast in interface Broadcaster<AtmosphereEventImpl>
Parameters:
msg - and Object to be shared.
event - an AtmosphereEvent

broadcast

public void broadcast(Object msg,
                      Set<AtmosphereEventImpl> 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.

Specified by:
broadcast in interface Broadcaster<AtmosphereEventImpl>
Parameters:
msg - and Object to be shared.

addAtmosphereEvent

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

Specified by:
addAtmosphereEvent in interface Broadcaster<AtmosphereEventImpl>
Parameters:
event - an AtmosphereEvent
Returns:
true if added, false if it was already added.

removeAtmosphereEvent

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

Specified by:
removeAtmosphereEvent in interface Broadcaster<AtmosphereEventImpl>
Parameters:
event - an AtmosphereEvent
Returns:
true if removed, false if it was already removed.

setExecutorService

public 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).

Specified by:
setExecutorService in interface Broadcaster<AtmosphereEventImpl>
Parameters:
executorService - to be used when broadcasting.

getExecutorService

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

Specified by:
getExecutorService in interface Broadcaster<AtmosphereEventImpl>
Returns:
An ExecutorService.


Copyright © 2009 SUN Microsystems. All Rights Reserved.