Search in sources :

Example 6 with BroadcasterFuture

use of org.atmosphere.runtime.BroadcasterFuture in project atmosphere by Atmosphere.

the class ExcludeSessionBroadcaster method broadcast.

/**
     * a list of sessions will be exclude for this broadcast
     *
     * @param msg
     * @param sessions
     * @return
     */
public Future<Object> broadcast(Object msg, List<HttpSession> sessions) {
    if (destroyed.get()) {
        return futureDone(msg);
    }
    Set<AtmosphereResource> subset = new HashSet<AtmosphereResource>();
    subset.addAll(resources);
    for (AtmosphereResource r : resources) {
        if (!r.getAtmosphereResourceEvent().isCancelled() && sessions.contains(r.getRequest().getSession())) {
            subset.remove(r);
        }
    }
    start();
    Object newMsg = filter(msg);
    if (newMsg == null) {
        return futureDone(msg);
    }
    BroadcasterFuture<Object> f = new BroadcasterFuture<Object>(newMsg, subset.size());
    dispatchMessages(new Deliver(newMsg, subset, f, msg));
    return f;
}
Also used : Deliver(org.atmosphere.runtime.Deliver) AtmosphereResource(org.atmosphere.runtime.AtmosphereResource) BroadcasterFuture(org.atmosphere.runtime.BroadcasterFuture) HashSet(java.util.HashSet)

Example 7 with BroadcasterFuture

use of org.atmosphere.runtime.BroadcasterFuture in project atmosphere by Atmosphere.

the class SimpleBroadcaster method broadcast.

@Override
public Future<Object> broadcast(Object msg) {
    if (destroyed.get()) {
        logger.warn("This Broadcaster has been destroyed and cannot be used");
        return futureDone(msg);
    }
    start();
    Object newMsg = filter(msg);
    if (newMsg == null)
        return null;
    BroadcasterFuture<Object> f = new BroadcasterFuture<Object>(newMsg);
    push(new Deliver(newMsg, f, msg));
    return f;
}
Also used : Deliver(org.atmosphere.runtime.Deliver) BroadcasterFuture(org.atmosphere.runtime.BroadcasterFuture)

Aggregations

BroadcasterFuture (org.atmosphere.runtime.BroadcasterFuture)7 Deliver (org.atmosphere.runtime.Deliver)7 HashSet (java.util.HashSet)3 AtmosphereResource (org.atmosphere.runtime.AtmosphereResource)3