Search in sources :

Example 1 with BroadcasterFactory

use of org.atmosphere.cpr.BroadcasterFactory in project scheduling by ow2-proactive.

the class SchedulerEventBroadcaster method broadcast.

private void broadcast(EventNotification eventNotification) {
    try {
        ServletContext servletContext = ServletContextFactory.getDefault().getServletContext();
        ((BroadcasterFactory) servletContext.getAttribute(BroadcasterFactory.class.getName())).lookup(broadcasterUUID).broadcast(mapper.writeValueAsString(eventNotification));
    } catch (Exception e) {
        log.error("Cannot broadcast event notification.", e);
        Throwables.propagate(e);
    }
}
Also used : BroadcasterFactory(org.atmosphere.cpr.BroadcasterFactory) ServletContext(javax.servlet.ServletContext)

Example 2 with BroadcasterFactory

use of org.atmosphere.cpr.BroadcasterFactory in project joynr by bmwcarit.

the class LongPollingMessagingDelegate method createChannel.

/**
 * Creates a long polling channel.
 *
 * @param ccid
 *            the identifier of the channel
 * @param atmosphereTrackingId
 *            the tracking ID of the channel
 * @return the path segment for the channel. The path, appended to the base
 *         URI of the channel service, can be used to post messages to the
 *         channel.
 */
public String createChannel(String ccid, String atmosphereTrackingId) {
    throwExceptionIfTrackingIdnotSet(atmosphereTrackingId);
    log.info("CREATE channel for cluster controller: {} trackingId: {} ", ccid, atmosphereTrackingId);
    Broadcaster broadcaster = null;
    // look for an existing broadcaster
    BroadcasterFactory defaultBroadcasterFactory = BroadcasterFactory.getDefault();
    if (defaultBroadcasterFactory == null) {
        throw new JoynrHttpException(500, 10009, "broadcaster was null");
    }
    broadcaster = defaultBroadcasterFactory.lookup(Broadcaster.class, ccid, false);
    // create a new one if none already exists
    if (broadcaster == null) {
        broadcaster = defaultBroadcasterFactory.get(BounceProxyBroadcaster.class, ccid);
    }
    // especially as seen in js, where every second refresh caused a fail
    for (AtmosphereResource resource : broadcaster.getAtmosphereResources()) {
        if (resource.uuid() != null && resource.uuid().equals(atmosphereTrackingId)) {
            resource.resume();
        }
    }
    UUIDBroadcasterCache broadcasterCache = (UUIDBroadcasterCache) broadcaster.getBroadcasterConfig().getBroadcasterCache();
    broadcasterCache.activeClients().put(atmosphereTrackingId, System.currentTimeMillis());
    return "/channels/" + ccid + "/";
}
Also used : BroadcasterFactory(org.atmosphere.cpr.BroadcasterFactory) JoynrHttpException(io.joynr.communications.exceptions.JoynrHttpException) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) Broadcaster(org.atmosphere.cpr.Broadcaster) UUIDBroadcasterCache(org.atmosphere.cache.UUIDBroadcasterCache)

Aggregations

BroadcasterFactory (org.atmosphere.cpr.BroadcasterFactory)2 JoynrHttpException (io.joynr.communications.exceptions.JoynrHttpException)1 ServletContext (javax.servlet.ServletContext)1 UUIDBroadcasterCache (org.atmosphere.cache.UUIDBroadcasterCache)1 AtmosphereResource (org.atmosphere.cpr.AtmosphereResource)1 Broadcaster (org.atmosphere.cpr.Broadcaster)1