Search in sources :

Example 1 with BroadcasterFuture

use of org.atmosphere.runtime.BroadcasterFuture 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.runtime.Deliver) AtmosphereResource(org.atmosphere.runtime.AtmosphereResource) BroadcasterFuture(org.atmosphere.runtime.BroadcasterFuture) HashSet(java.util.HashSet)

Example 2 with BroadcasterFuture

use of org.atmosphere.runtime.BroadcasterFuture 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.runtime.Deliver) AtmosphereResource(org.atmosphere.runtime.AtmosphereResource) BroadcasterFuture(org.atmosphere.runtime.BroadcasterFuture) HashSet(java.util.HashSet)

Example 3 with BroadcasterFuture

use of org.atmosphere.runtime.BroadcasterFuture 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.runtime.Deliver) BroadcasterFuture(org.atmosphere.runtime.BroadcasterFuture)

Example 4 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, 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.runtime.Deliver) BroadcasterFuture(org.atmosphere.runtime.BroadcasterFuture)

Example 5 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, 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.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