Class SseResource

All Implemented Interfaces:

@Path("events") @RolesAllowed({"user","administrator"}) @NonNullByDefault public class SseResource extends Object implements RESTResource,
SSE Resource for pushing events to currently listening clients.
Ivan Iliev - Initial contribution, Yordan Zhelev - Added Swagger annotations, Yannick Schaus - Add endpoints to track item state updates, Markus Rathgeb - Drop Glassfish dependency and use API only, Wouter Born - Rework SSE item state sinks for dropping Glassfish, Wouter Born - Migrated to OpenAPI annotations
  • Field Details

  • Constructor Details

    • SseResource

      public SseResource( itemStatesEventBuilder)
  • Method Details

    • deactivate

      public void deactivate()
    • broadcast

      public void broadcast(Event event)
      Specified by:
      broadcast in interface
    • listen

      @GET @Produces("text/event-stream") public void listen(@Context sseEventSink, @Context javax.servlet.http.HttpServletResponse response, @QueryParam("topics") String eventFilter)
    • getStateEvents

      @GET @Path("/states") @Produces("text/event-stream") public void getStateEvents(@Context sseEventSink, @Context javax.servlet.http.HttpServletResponse response)
      Subscribes the connecting client for state updates. It will initially only send a "ready" event with a unique connectionId that the client can use to dynamically alter the list of tracked items.
    • updateTrackedItems

      @POST @Path("/states/{connectionId}") public Object updateTrackedItems(@PathParam("connectionId") @Nullable String connectionId, @Nullable Set<String> itemNames)
      Alters the list of tracked items for a given state update connection
      connectionId - the connection Id to change
      itemNames - the list of items to track
    • handleEventBroadcastItemState

      public void handleEventBroadcastItemState(ItemStateChangedEvent stateChangeEvent)
      Broadcasts a state event to all currently listening clients, after transforming it to a simple map.
      stateChangeEvent - the ItemStateChangedEvent containing the new state