Tabnine Logo
SseBroadcaster
Code IndexAdd Tabnine to your IDE (free)

How to use
SseBroadcaster
in
org.glassfish.jersey.media.sse

Best Java code snippets using org.glassfish.jersey.media.sse.SseBroadcaster (Showing top 20 results out of 315)

origin: jersey/jersey

/**
 * 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;
}
origin: jersey/jersey

/**
 * Put a new message to the stream.
 *
 * The message will be broadcast to all registered SSE clients.
 *
 * @param message message to be broadcast.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void putMessage(final Message message) {
  LOGGER.info("--> Message received.");
  final OutboundEvent event = new OutboundEvent.Builder()
      .id(String.valueOf(nextMessageId.getAndIncrement()))
      .mediaType(MediaType.APPLICATION_JSON_TYPE)
      .data(Message.class, message)
      .build();
  broadcaster.broadcast(event);
}
origin: jersey/jersey

  public void run() {
    try {
      if (latch != null) {
        // wait for all test EventSources to be registered
        latch.await(5, TimeUnit.SECONDS);
      }
      broadcaster.broadcast(
          new OutboundEvent.Builder().name("domain-progress").data(String.class, "starting domain " + id + " ...")
              .build());
      broadcaster.broadcast(new OutboundEvent.Builder().name("domain-progress").data(String.class, "50%").build());
      broadcaster.broadcast(new OutboundEvent.Builder().name("domain-progress").data(String.class, "60%").build());
      broadcaster.broadcast(new OutboundEvent.Builder().name("domain-progress").data(String.class, "70%").build());
      broadcaster.broadcast(new OutboundEvent.Builder().name("domain-progress").data(String.class, "99%").build());
      broadcaster.broadcast(new OutboundEvent.Builder().name("domain-progress").data(String.class, "done").build());
      broadcaster.closeAll();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
origin: stackoverflow.com

public class MessageBoardResource {
  private static SseBroadcaster broadcaster = new SseBroadcaster();
    broadcaster.add(eventOutput);
    return eventOutput;
    broadcaster.broadcast(event); // invokes eventOutput.write(event);
origin: org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest.sitemap

protected void activate() {
  broadcaster = new SseBroadcaster();
  broadcaster.add(this);
}
origin: stackoverflow.com

 public class TestServlet extends HttpServlet {

SseBroadcaster broadcaster = new SseBroadcaster();

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  Scanner scanner = new Scanner(req.getInputStream());
  StringBuilder sb = new StringBuilder();
  while(scanner.hasNextLine()) {
    sb.append(scanner.nextLine());
  }
  System.out.println("sb = " + sb);
  broadcaster.broadcast("message",sb.toString());
}

//http://cjihrig.com/blog/the-server-side-of-server-sent-events/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  broadcaster.addListener(req);
}
}
origin: org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest.sse

public SseResource() {
  this.executorService = Executors.newSingleThreadExecutor();
  this.broadcaster = new SseBroadcaster();
}
origin: org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest.sitemap

protected void deactivate() {
  broadcaster.remove(this);
  broadcaster = null;
}
origin: openhab/openhab-core

@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);
}
origin: openhab/openhab-core

public SseResource() {
  this.executorService = Executors.newSingleThreadExecutor();
  this.broadcaster = new SseBroadcaster();
}
origin: openhab/openhab-core

@Override
public void onRelease(String subscriptionId) {
  logger.debug("SSE connection for subscription {} has been released.", subscriptionId);
  EventOutput eventOutput = eventOutputs.remove(subscriptionId);
  if (eventOutput != null) {
    broadcaster.remove(eventOutput);
  }
}
origin: jersey/jersey

@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();
  }
}
origin: openhab/openhab-core

  @Override
  public void run() {
    broadcaster.broadcast(SseUtil.buildEvent(event));
  }
});
origin: openhab/openhab-core

@Deactivate
protected void deactivate() {
  if (cleanSubscriptionsJob != null && !cleanSubscriptionsJob.isCancelled()) {
    logger.debug("Cancel clean SSE subscriptions job");
    cleanSubscriptionsJob.cancel(true);
    cleanSubscriptionsJob = null;
  }
  broadcaster.remove(this);
  broadcaster = null;
}
origin: vgoldin/cqrs-eventsourcing-kafka

@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;
}
origin: org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest.sse

  @Override
  public void run() {
    broadcaster.broadcast(SseUtil.buildEvent(event));
  }
});
origin: openhab/openhab-core

@Override
public void onClose(ChunkedOutput<OutboundEvent> event) {
  if (event instanceof SitemapEventOutput) {
    SitemapEventOutput sitemapEvent = (SitemapEventOutput) event;
    logger.debug("SSE connection for subscription {} has been closed.", sitemapEvent.getSubscriptionId());
    subscriptions.removeSubscription(sitemapEvent.getSubscriptionId());
    EventOutput eventOutput = eventOutputs.remove(sitemapEvent.getSubscriptionId());
    if (eventOutput != null) {
      broadcaster.remove(eventOutput);
    }
  }
}
origin: org.terracotta/management-common-resources-v2

@Override
public <OUT extends ChunkedOutput<OutboundEvent>> boolean add(OUT chunkedOutput) {
 outputs.put((TerracottaEventOutput) chunkedOutput, new TerracottaEventOutputFlushingMetadata());
 return super.add(chunkedOutput);
}
origin: vgoldin/cqrs-eventsourcing-kafka

  @Override
  public void update(Observable o, Object arg) {
    if (o instanceof StreamBroadcaster && arg != null) {
      EventEnvelope e = (EventEnvelope) arg;
      OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
      OutboundEvent event = eventBuilder
          .mediaType(MediaType.APPLICATION_JSON_TYPE)
          .id(e.eventId.orElse(null))
          .name(e.eventType)
          .data(e.eventData)
          .build();

      BROADCASTER.broadcast(event);
    }
  }
}
origin: org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest.sitemap

/**
 * 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);
}
org.glassfish.jersey.media.sseSseBroadcaster

Javadoc

Used for broadcasting SSE to multiple EventOutput instances.

Most used methods

  • add
  • broadcast
  • <init>
    Can be used by subclasses to override the default functionality of adding self to the set of org.gla
  • remove
  • addListener
  • closeAll

Popular in Java

  • Reading from database using SQL prepared statement
  • notifyDataSetChanged (ArrayAdapter)
  • getApplicationContext (Context)
  • setRequestProperty (URLConnection)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • JLabel (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now