Skip to content

Getting BroadcasterFactory and AtmosphereResourceFactory with 2.2 and newer

Sebastian Lövdahl edited this page Aug 21, 2014 · 20 revisions

With the release of Atmosphere 2.2.0, the static getters BroadcasterFactory.getDefault() and AtmosphereResourceFactory.getDefault() have been deprecated. From now on you should get BroadcasterFactory and AtmosphereResourceFactory instances from an AtmosphereFramework instance instead.

AtmosphereFramework itself is available from eg. AtmosphereServlet.

atmosphere-guice

If you're using the atmosphere-guice extension, you can add the following Provider to a Guice Module:

@Provides
@Singleton
BroadcasterFactory provideBroadcasterFactory(AtmosphereGuiceServlet atmosphereGuiceServlet) {
    return atmosphereGuiceServlet.framework().getBroadcasterFactory();
}

@Provides
@Singleton
AtmosphereResourceFactory provideAtmosphereResourceFactory(AtmosphereGuiceServlet atmosphereGuiceServlet) {
    return atmosphereGuiceServlet.framework().atmosphereFactory();
}

After that it's possible to inject BroadcasterFactory and AtmosphereResourceFactory in any class created by Guice:

public class Sample {
    @Inject
    private BroadcasterFactory broadcasterFactory;
    @Inject
    private AtmosphereResourceFactory atmosphereResourceFactory;

    public void broadcast(String destination, String text) {
        broadcasterFactory.lookup(destination).broadcast(text);
    }

    public AtmosphereResource getAtmosphereResourceById(String id) {
        return atmosphereResourceFactory.find(id);
    }
}

Step by Step Tutorials

Concepts & Architecture

15 Minutes Tutorial

Advanced Topics

API

Known WebServer Issues

References

External Documentations

githalytics.com alpha

Clone this wiki locally