use of org.atmosphere.cpr.Broadcaster in project cxf by apache.
the class SseAtmosphereEventSinkImpl method close.
@Override
public void close() {
if (!closed) {
closed = true;
LOG.fine("Closing Atmosphere SSE event output");
if (resource.isSuspended()) {
LOG.fine("Atmosphere resource is suspended, resuming");
resource.resume();
}
final Broadcaster broadcaster = resource.getBroadcaster();
resource.removeFromAllBroadcasters();
try {
final AtmosphereResponse response = resource.getResponse();
try {
// or stream.
if (usingStream) {
response.getOutputStream().close();
} else {
response.getWriter().close();
}
} catch (final IOException ex) {
LOG.warning("Failed to flush AtmosphereResponse buffer: " + ex.getMessage());
}
} finally {
try {
resource.close();
} catch (IOException ex) {
// ignore
}
broadcaster.destroy();
LOG.fine("Atmosphere SSE event output is closed");
}
}
}
use of org.atmosphere.cpr.Broadcaster in project cxf by apache.
the class SseAtmosphereEventSinkContextProvider method createContext.
@Override
public SseEventSink createContext(Message message) {
final HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
if (request == null) {
throw new IllegalStateException("Unable to retrieve HTTP request from the context");
}
final AtmosphereResource resource = (AtmosphereResource) request.getAttribute(AtmosphereResource.class.getName());
if (resource == null) {
throw new IllegalStateException("AtmosphereResource is not present, " + "is AtmosphereServlet configured properly?");
}
final Broadcaster broadcaster = resource.getAtmosphereConfig().getBroadcasterFactory().lookup(resource.uuid(), true);
resource.removeFromAllBroadcasters();
resource.setBroadcaster(broadcaster);
final MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter(ServerProviderFactory.getInstance(message), message.getExchange());
return new SseAtmosphereEventSinkImpl(writer, resource);
}
use of org.atmosphere.cpr.Broadcaster in project scheduling by ow2-proactive.
the class SchedulerStateRest method subscribe.
/*
* Atmosphere 2.0 framework based implementation of Scheduler Eventing mechanism for REST
* clients. It is configured to use WebSocket as the underneath protocol between the client and
* the server.
*/
/**
* Initialize WebSocket based communication channel between the client and
* the server.
*/
@GET
@Path("/events")
public String subscribe(@Context HttpServletRequest req, @HeaderParam("sessionid") String sessionId) throws NotConnectedRestException {
checkAccess(sessionId);
HttpSession session = checkNotNull(req.getSession(), "HTTP session object is null. HTTP session support is requried for REST Scheduler eventing.");
AtmosphereResource atmosphereResource = checkNotNull((AtmosphereResource) req.getAttribute(AtmosphereResource.class.getName()), "No AtmosphereResource is attached with current request.");
// use session id as the 'topic' (or 'id') of the broadcaster
session.setAttribute(ATM_BROADCASTER_ID, sessionId);
session.setAttribute(ATM_RESOURCE_ID, atmosphereResource.uuid());
Broadcaster broadcaster = lookupBroadcaster(sessionId, true);
if (broadcaster != null) {
atmosphereResource.setBroadcaster(broadcaster).suspend();
}
return null;
}
Aggregations