コード例 #1
0
 @GET
 @Path("events")
 @Produces(SseFeature.SERVER_SENT_EVENTS)
 public EventOutput itemEvents() {
   final EventOutput eventOutput = new EventOutput();
   BROADCASTER.add(eventOutput);
   return eventOutput;
 }
コード例 #2
0
 @GET
 @Path("events")
 @Produces(SseFeature.SERVER_SENT_EVENTS)
 public EventOutput subscribe() {
   EventOutput eventOutput = new EventOutput();
   broadcaster.add(eventOutput);
   return eventOutput;
 }
コード例 #3
0
 @GET
 @Produces(SseFeature.SERVER_SENT_EVENTS)
 public EventOutput get() {
   EventOutput output = new EventOutput();
   broadcaster.add(output);
   scheduler.scheduleAtFixedRate(this::broadcastStatistics, 0, 1000, TimeUnit.MILLISECONDS);
   return output;
 }
コード例 #4
0
 public void registerNewClient(EventOutput eventOutput) {
   sseBroadcaster.add(eventOutput);
   OutboundEvent event =
       eventBuilder
           .name("new-client")
           .mediaType(MediaType.TEXT_PLAIN_TYPE)
           .data(String.class, "One more client")
           .build();
   sseBroadcaster.broadcast(event);
 }