コード例 #1
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);
 }
コード例 #2
0
 @POST
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 public void addItem(@FormParam("name") String name) {
   ITEMS.add(name);
   // Broadcasting an un-named event with the name of the newly added item in data
   BROADCASTER.broadcast(new OutboundEvent.Builder().data(String.class, name).build());
   // Broadcasting a named "add" event with the current size of the items collection in data
   BROADCASTER.broadcast(
       new OutboundEvent.Builder().name("size").data(Integer.class, ITEMS.size()).build());
 }
コード例 #3
0
 @GET
 @Path("events")
 @Produces(SseFeature.SERVER_SENT_EVENTS)
 public EventOutput subscribe() {
   EventOutput eventOutput = new EventOutput();
   broadcaster.add(eventOutput);
   return eventOutput;
 }
コード例 #4
0
 @GET
 @Path("events")
 @Produces(SseFeature.SERVER_SENT_EVENTS)
 public EventOutput itemEvents() {
   final EventOutput eventOutput = new EventOutput();
   BROADCASTER.add(eventOutput);
   return eventOutput;
 }
コード例 #5
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;
 }
コード例 #6
0
ファイル: DomainResource.java プロジェクト: Ganeshsoft/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();
      }
    }
コード例 #7
0
 @Override
 public void message(String author, String message) {
   OutboundEvent event =
       eventBuilder
           .name("tweet")
           .mediaType(MediaType.TEXT_PLAIN_TYPE)
           .data(String.class, message)
           .build();
   sseBroadcaster.broadcast(event);
 }
コード例 #8
0
ファイル: State.java プロジェクト: bigdimboom/dht-streaming
 public void removeListener(int id, String key) {
   // TODO Close the event output stream.
   if (outputs.containsKey(id)) {
     EventOutput oput = outputs.get(id).remove(key);
     if (oput != null) {
       try {
         oput.close();
       } catch (IOException e) {
         System.out.println("State.java: Line 321 error");
       }
     }
   } else {
     // if
     SseBroadcaster bdcast = listeners.remove(key);
     if (bdcast != null) // Check if there is residue EventOutput in the
     // broadcaster
     {
       bdcast.closeAll();
     }
   }
   // Done
 }
コード例 #9
0
  @DELETE
  @Path("broker")
  public void deleteConfiguration() {
    broker.setConfiguration(new Configuration());

    // Broadcast new stream list
    OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
    OutboundEvent event =
        eventBuilder
            .name("broker")
            .mediaType(MediaType.APPLICATION_JSON_TYPE)
            .data(Configuration.class, broker.getConfiguration())
            .build();
    broadcaster.broadcast(event);
  }
コード例 #10
0
  @DELETE
  @Path("broker/{routing-id}")
  public void deleteRouting(@PathParam("routing-id") String name) {
    broker.removeRouting("^" + name + "$");

    // Broadcast new stream list
    OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
    OutboundEvent event =
        eventBuilder
            .name("broker")
            .mediaType(MediaType.APPLICATION_JSON_TYPE)
            .data(Configuration.class, broker.getConfiguration())
            .build();
    broadcaster.broadcast(event);
  }
コード例 #11
0
  @PUT
  @Path("broker/{routing-id}")
  public void addRouting(@PathParam("routing-id") String name, Routing routing) {
    routing.setName(name); // Ensure that name is the same as the one specified on the URL
    broker.addRouting(routing);

    // Broadcast new stream list
    OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
    OutboundEvent event =
        eventBuilder
            .name("broker")
            .mediaType(MediaType.APPLICATION_JSON_TYPE)
            .data(Configuration.class, broker.getConfiguration())
            .build();
    broadcaster.broadcast(event);
  }
コード例 #12
0
  @PUT
  @Path("broker")
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public void setConfiguration(Configuration configuration) {
    broker.setConfiguration(configuration);

    // Broadcast new stream list
    OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
    OutboundEvent event =
        eventBuilder
            .name("broker")
            .mediaType(MediaType.APPLICATION_JSON_TYPE)
            .data(Configuration.class, broker.getConfiguration())
            .build();
    broadcaster.broadcast(event);
  }
コード例 #13
0
  private void broadcastStatistics() {
    List<URI> monitoringEndpoints = monitoringApp.getMonitoredApps();
    List<MonitoringData> monitoringData =
        monitoringEndpoints
            .stream()
            .map(
                (endpointUri) -> {
                  Response response = client.target(endpointUri).path("monitoring").request().get();
                  MonitoringData data = response.readEntity(MonitoringData.class);
                  data.setNode(endpointUri.getHost() + ":" + endpointUri.getPort());
                  return data;
                })
            .collect(Collectors.toList());

    OutboundEvent event =
        new OutboundEvent.Builder()
            .mediaType(MediaType.APPLICATION_JSON_TYPE)
            .data(monitoringData)
            .build();
    broadcaster.broadcast(event);
  }