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);
}
}
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 + "/";
}
Aggregations