Search in sources :

Example 1 with Deliver

use of org.atmosphere.cpr.Deliver in project atmosphere by Atmosphere.

the class ExcludeSessionBroadcaster method broadcast.

/**
 * the AtmosphereResources subset will be exclude for this broadcast
 *
 * @param msg
 * @param subset
 * @return
 */
@Override
public Future<Object> broadcast(Object msg, Set<AtmosphereResource> subset) {
    if (destroyed.get()) {
        return futureDone(msg);
    }
    subset.retainAll(resources);
    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.cpr.Deliver) BroadcasterFuture(org.atmosphere.cpr.BroadcasterFuture)

Example 2 with Deliver

use of org.atmosphere.cpr.Deliver in project atmosphere by Atmosphere.

the class ExcludeSessionBroadcaster method broadcast.

/**
 * session will be exclude for this broadcast
 *
 * @param msg
 * @param s
 * @return
 */
public Future<Object> broadcast(Object msg, HttpSession s) {
    if (destroyed.get()) {
        return futureDone(msg);
    }
    Set<AtmosphereResource> subset = new HashSet<AtmosphereResource>();
    subset.addAll(resources);
    for (AtmosphereResource r : resources) {
        if (!r.getAtmosphereResourceEvent().isCancelled() && s.equals(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.cpr.Deliver) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) BroadcasterFuture(org.atmosphere.cpr.BroadcasterFuture) HashSet(java.util.HashSet)

Example 3 with Deliver

use of org.atmosphere.cpr.Deliver in project atmosphere by Atmosphere.

the class ExcludeSessionBroadcaster method broadcast.

/**
 * the AtmosphereResource r will be exclude for this broadcast
 *
 * @param msg
 * @param r
 * @return
 */
@Override
public Future<Object> broadcast(Object msg, AtmosphereResource r) {
    if (destroyed.get()) {
        throw new IllegalStateException("This Broadcaster has been destroyed and cannot be used");
    }
    Set<AtmosphereResource> sub = new HashSet<AtmosphereResource>();
    sub.addAll(resources);
    sub.remove(r);
    start();
    Object newMsg = filter(msg);
    if (newMsg == null) {
        return null;
    }
    BroadcasterFuture<Object> f = new BroadcasterFuture<Object>(newMsg, sub.size());
    dispatchMessages(new Deliver(newMsg, sub, f, msg));
    return f;
}
Also used : Deliver(org.atmosphere.cpr.Deliver) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) BroadcasterFuture(org.atmosphere.cpr.BroadcasterFuture) HashSet(java.util.HashSet)

Example 4 with Deliver

use of org.atmosphere.cpr.Deliver in project atmosphere by Atmosphere.

the class SimpleBroadcaster method broadcast.

@Override
public Future<Object> broadcast(Object msg, AtmosphereResource r) {
    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, r, f, msg));
    return f;
}
Also used : Deliver(org.atmosphere.cpr.Deliver) BroadcasterFuture(org.atmosphere.cpr.BroadcasterFuture)

Example 5 with Deliver

use of org.atmosphere.cpr.Deliver in project atmosphere by Atmosphere.

the class SimpleBroadcaster method broadcast.

@Override
public Future<Object> broadcast(Object msg, Set<AtmosphereResource> subset) {
    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, subset, f, msg));
    return f;
}
Also used : Deliver(org.atmosphere.cpr.Deliver) BroadcasterFuture(org.atmosphere.cpr.BroadcasterFuture)

Aggregations

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