5

I am using Atmosphere framework and it looks in the newest version(s) of the library the method: BroadcasterFactory.getDefault() is depricated. (and this method was essentially used everywhere and I cannot find an example how to use the new "way" )

The javadoc states :

 @deprecated Use {@link org.atmosphere.cpr.AtmosphereConfig#resourcesFactory()}

However I cannot find a single documentation how to get the AtmosphereConfig to be able to get the resourceFactory (which is an instance method).

Can someone tell me how to get the config .. or the AtmosphereFramework object itself from which I can get the config or any example which is up2date ?

jNayden
  • 1,592
  • 2
  • 17
  • 29

2 Answers2

0

Not sure if it works, but try to get ServletContext and use getAttribute(AtmosphereFramework.class.getName()) to obtain AtmosphereFramework. If you are using Spring, try to autowire AtmosphereFramework directly.

You can also get BroadcasterFactory from AtmosphereResource and then lookup for Broadcaster like:

private String path;

private BroadcasterFactory broadcasterFactory;

@Ready(value = Ready.DELIVER_TO.ALL)
public void onReady(final AtmosphereResource r) {

    System.out.println("onConnect");

    r.addEventListener(new AtmosphereConnectionController());

    if(broadcasterFactory == null){
        path = r.getBroadcaster().getID();
        broadcasterFactory = r.getAtmosphereConfig().getBroadcasterFactory();
    }
}
//later in code
broadcasterFactory.lookup(path).broadcast("message");
mayr
  • 451
  • 6
  • 14
0

Use dependency injection. In my project, it goes like this:

@MeteorService(path = "/recursos/fila-de-atendimento", interceptors = {AtmosphereResourceLifecycleInterceptor.class})
public class FilaDeAtendimentoResource extends HttpServlet {

    @Inject
    private BroadcasterFactory broadcasterFactory;

    ...

    /** Used for registering for a message */
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
        ...
        Broadcaster broadcaster = broadcasterFactory.lookup(broadcasterId, true);
        meteor.setBroadcaster(broadcaster);
        ...
    }

}
diogenesgg
  • 2,601
  • 2
  • 20
  • 29
  • This does not work, for me at least, Don't know why, but BroadcasterFactory is not being injected properly and is null. – CrazySabbath Oct 13 '17 at 06:43