Atmosphere:不推荐使用BroadcasterFactory类型的方法getDefault()

时间:2014-07-17 14:04:48

标签: atmosphere

我正在使用Atmosphere 2.2.0-RC3。我有这个警告:" BroadcasterFactory类型的方法getDefault()已被弃用"在行 BroadcasterFactory.getDefault()。lookup(topic,true) 这是代码:

@Path("/chat/{topic}")
@AtmosphereService (broadcaster = JerseyBroadcaster.class)
public class ChatResourceTopic {

    private @PathParam("topic")
    String topic;   

    @Suspend( contentType = MediaType.APPLICATION_JSON, listeners = { OnDisconnect.class })
    @GET
    public Broadcastable suspend()  {
        return new Broadcastable(BroadcasterFactory.getDefault().lookup(topic, true ));
    }
    ...
}

我检查了维基并被广泛使用:https://github.com/Atmosphere/atmosphere/wiki/Understanding-Broadcaster

如何更改代码以避免警告?

注意:我也用这个: 。BroadcasterFactory.getDefault()查找(主题).broadcast(响应);

1 个答案:

答案 0 :(得分:1)

我不使用泽西气氛(我使用@ManagedService)但你应该能够注入AtmosphereResourceBroadcasterFactory @Context注释使用泽西岛。

public Broadcastable suspend(@Context BroadcasterFactory factory) {

OR

public Broadcastable suspend(@Context AtmosphereResource resource) {
    BroadcasterFactory factory = resource.getAtmosphereConfig().getBroadcasterFactory();

我没有对此进行过测试,但它已经过了documentation