org.atmosphere.cpr
Class DefaultBroadcasterFactory

java.lang.Object
  extended by org.atmosphere.cpr.BroadcasterFactory
      extended by org.atmosphere.cpr.DefaultBroadcasterFactory

public class DefaultBroadcasterFactory
extends BroadcasterFactory

This class is responsible for creating Broadcaster instance. You can also add and remove Broadcaster and lookup using BroadcasterFactory.getDefault() ()} from any Classes loaded using the same class loader.

Author:
Jeanfrancois Arcand

Nested Class Summary
static class DefaultBroadcasterFactory.BroadcasterCreationException
           
 
Field Summary
 
Fields inherited from class org.atmosphere.cpr.BroadcasterFactory
config, factory
 
Constructor Summary
protected DefaultBroadcasterFactory(Class<? extends Broadcaster> clazz, String broadcasterLifeCyclePolicy, AtmosphereServlet.AtmosphereConfig c)
           
 
Method Summary
 boolean add(Broadcaster b, Object id)
          Add a Broadcaster to the list.
static BroadcasterFactory buildAndReplaceDefaultfactory(Class<? extends Broadcaster> clazz, AtmosphereServlet.AtmosphereConfig c)
          Build a default BroadcasterFactory returned when invoking BroadcasterFactory.getDefault() ()}.
 void destroy()
          Shutdown all Broadcaster
 Broadcaster get()
          Return an instance of the default Broadcaster The name of the Broadcaster will be randmly generated.
 Broadcaster get(Class<? extends Broadcaster> c, Object id)
          Create a new instance of Broadcaster and store it for
 Broadcaster get(Object id)
          Create a new instance of Broadcaster and store it for
 Broadcaster lookup(Class<? extends Broadcaster> c, Object id)
          Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()
 Broadcaster lookup(Class<? extends Broadcaster> c, Object id, boolean createIfNull)
          Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()
 Broadcaster lookup(Object id)
          Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()
 Broadcaster lookup(Object id, boolean createIfNull)
          Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()
 Collection<Broadcaster> lookupAll()
          Return an immutable Collection of Broadcaster this factory contains.
 boolean remove(Broadcaster b, Object id)
          Remove a Broadcaster to the list.
 void removeAllAtmosphereResource(AtmosphereResource<?,?> r)
          Remove all instance of AtmosphereResource from all registered Broadcaster
 
Methods inherited from class org.atmosphere.cpr.BroadcasterFactory
getDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBroadcasterFactory

protected DefaultBroadcasterFactory(Class<? extends Broadcaster> clazz,
                                    String broadcasterLifeCyclePolicy,
                                    AtmosphereServlet.AtmosphereConfig c)
Method Detail

get

public final Broadcaster get()
Return an instance of the default Broadcaster The name of the Broadcaster will be randmly generated.

Specified by:
get in class BroadcasterFactory
Returns:
an instance of the default Broadcaster

get

public final Broadcaster get(Object id)
Create a new instance of Broadcaster and store it for

Specified by:
get in class BroadcasterFactory
Parameters:
id - The unique ID used to retrieve Broadcaster
Returns:
a new instance of Broadcaster

get

public final Broadcaster get(Class<? extends Broadcaster> c,
                             Object id)
Create a new instance of Broadcaster and store it for

Specified by:
get in class BroadcasterFactory
Parameters:
c - The Broadcaster class instance.
id - The unique ID used to retrieve Broadcaster
Returns:
a new instance of Broadcaster

add

public boolean add(Broadcaster b,
                   Object id)
Add a Broadcaster to the list.

Specified by:
add in class BroadcasterFactory
Parameters:
b - a Broadcaster
Returns:
false if a with the same name Broadcaster was already stored

remove

public boolean remove(Broadcaster b,
                      Object id)
Remove a Broadcaster to the list.

Specified by:
remove in class BroadcasterFactory
Parameters:
b - a Broadcaster
Returns:
false if wasn't present, or Broadcaster

lookup

public final Broadcaster lookup(Class<? extends Broadcaster> c,
                                Object id)
Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()

Specified by:
lookup in class BroadcasterFactory
id - The Broadcaster's unique ID, or name.
Returns:
a Broadcaster, or null if not found.

lookup

public final Broadcaster lookup(Object id)
Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()

Specified by:
lookup in class BroadcasterFactory
Parameters:
id - The Broadcaster's unique ID, or name.
Returns:
a Broadcaster, or null if not found.

lookup

public final Broadcaster lookup(Object id,
                                boolean createIfNull)
Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()

Specified by:
lookup in class BroadcasterFactory
Parameters:
id - The Broadcaster's unique ID, or name.
createIfNull - If the broadcaster is not found, create it.
Returns:
a Broadcaster, or null if not found.

lookup

public Broadcaster lookup(Class<? extends Broadcaster> c,
                          Object id,
                          boolean createIfNull)
Lookup a Broadcaster instance using Broadcaster.getID() or ID used when invoking BroadcasterFactory.getDefault()

Specified by:
lookup in class BroadcasterFactory
id - The Broadcaster's unique ID, or name.
createIfNull - If the broadcaster is not found, create it.
Returns:
a Broadcaster, or null if not found.

removeAllAtmosphereResource

public void removeAllAtmosphereResource(AtmosphereResource<?,?> r)
Remove all instance of AtmosphereResource from all registered Broadcaster

Specified by:
removeAllAtmosphereResource in class BroadcasterFactory
Parameters:
r - an void AtmosphereResource

lookupAll

public Collection<Broadcaster> lookupAll()
Return an immutable Collection of Broadcaster this factory contains.

Specified by:
lookupAll in class BroadcasterFactory
Returns:
an immutable Collection of Broadcaster this factory contains.

destroy

public void destroy()
Shutdown all Broadcaster

Specified by:
destroy in class BroadcasterFactory

buildAndReplaceDefaultfactory

public static BroadcasterFactory buildAndReplaceDefaultfactory(Class<? extends Broadcaster> clazz,
                                                               AtmosphereServlet.AtmosphereConfig c)
                                                        throws InstantiationException,
                                                               IllegalAccessException
Build a default BroadcasterFactory returned when invoking BroadcasterFactory.getDefault() ()}.

Parameters:
clazz - A class implementing Broadcaster
c - An instance of AtmosphereServlet.AtmosphereConfig
Returns:
the default BroadcasterFactory.
Throws:
InstantiationException
IllegalAccessException


Copyright © 2011. All Rights Reserved.