/** * Get the new SSE message stream channel. * * @return new SSE message stream channel. */ @GET @Produces(SseFeature.SERVER_SENT_EVENTS) public EventOutput getMessageStream() { LOGGER.info("--> SSE connection received."); final EventOutput eventOutput = new EventOutput(); broadcaster.add(eventOutput); return eventOutput; }
@Path("process/{id}") @Produces(SseFeature.SERVER_SENT_EVENTS) @GET public EventOutput getProgress(@PathParam("id") int id, @DefaultValue("false") @QueryParam("testSource") boolean testSource) { final Process process = processes.get(id); if (process != null) { if (testSource) { process.release(); } final EventOutput eventOutput = new EventOutput(); process.getBroadcaster().add(eventOutput); return eventOutput; } else { throw new NotFoundException(); } }
@Override public <OUT extends ChunkedOutput<OutboundEvent>> boolean add(OUT chunkedOutput) { outputs.put((TerracottaEventOutput) chunkedOutput, new TerracottaEventOutputFlushingMetadata()); return super.add(chunkedOutput); }
protected void activate() { broadcaster = new SseBroadcaster(); broadcaster.add(this); }
@GET @Path("/events.stream") @Produces(SseFeature.SERVER_SENT_EVENTS) @ApiOperation(value = "Get Event Stream of Application Events", notes = "Returns a continuous stream of application events using Server-Sent Events.") public EventOutput errors() { final EventOutput eventOutput = new EventOutput(); BROADCASTER.add(eventOutput); return eventOutput; }
/** * Creates a subscription for the stream of sitemap events. * * @return a subscription id */ @POST @Path(SEGMENT_EVENTS + "/subscribe") @ApiOperation(value = "Creates a sitemap event subscription.") @ApiResponses(value = { @ApiResponse(code = 201, message = "Subscription created.") }) public Object createEventSubscription() { String subscriptionId = subscriptions.createSubscription(this); final EventOutput eventOutput = new SitemapEventOutput(subscriptions, subscriptionId); broadcaster.add(eventOutput); eventOutputs.put(subscriptionId, eventOutput); URI uri = uriInfo.getBaseUriBuilder().path(PATH_SITEMAPS).path(SEGMENT_EVENTS).path(subscriptionId).build(); return Response.created(uri); }
@Activate protected void activate() { broadcaster = new SseBroadcaster(); broadcaster.add(this); // The clean SSE subscriptions job sends an ALIVE event to all subscribers. This will trigger // an exception when the subscriber is dead, leading to the release of the SSE subscription // on server side. // In practice, the exception occurs only after the sending of a second ALIVE event. So this // will require two runs of the job to release an SSE subscription. // The clean SSE subscriptions job is run every 5 minutes. cleanSubscriptionsJob = scheduler.scheduleAtFixedRate(() -> { logger.debug("Run clean SSE subscriptions job"); if (subscriptions != null) { subscriptions.checkAliveClients(); } }, 1, 5, TimeUnit.MINUTES); }
/** * Creates a subscription for the stream of sitemap events. * * @return a subscription id */ @POST @Path(SEGMENT_EVENTS + "/subscribe") @ApiOperation(value = "Creates a sitemap event subscription.") @ApiResponses(value = { @ApiResponse(code = 201, message = "Subscription created."), @ApiResponse(code = 503, message = "Subscriptions limit reached.") }) public Object createEventSubscription() { String subscriptionId = subscriptions.createSubscription(this); if (subscriptionId == null) { return JSONResponse.createResponse(Status.SERVICE_UNAVAILABLE, null, "Max number of subscriptions is reached."); } final EventOutput eventOutput = new SitemapEventOutput(subscriptions, subscriptionId); broadcaster.add(eventOutput); eventOutputs.put(subscriptionId, eventOutput); URI uri = uriInfo.getBaseUriBuilder().path(PATH_SITEMAPS).path(SEGMENT_EVENTS).path(subscriptionId).build(); logger.debug("Client from IP {} requested new subscription => got id {}.", request.getRemoteAddr(), subscriptionId); return Response.created(uri); }
broadcaster.add(eventOutput);
broadcaster.add(eventOutput);
broadcaster.add(eventOutput); return eventOutput;