@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()); }
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); }
@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); }
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(); } }
@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); }
@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); }
@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); }
@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); }
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); }