Class SseResource

java.lang.Object
org.openhab.core.io.rest.sse.SseResource
All Implemented Interfaces:
RESTResource, org.openhab.core.io.rest.sse.internal.SsePublisher

@Path("events") @RolesAllowed({"user","administrator"}) @NonNullByDefault public class SseResource extends Object implements RESTResource, org.openhab.core.io.rest.sse.internal.SsePublisher
SSE Resource for pushing events to currently listening clients.
Author:
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(org.openhab.core.io.rest.sse.internal.SseItemStatesEventBuilder itemStatesEventBuilder)
  • Method Details

    • deactivate

      public void deactivate()
    • broadcast

      public void broadcast(Event event)
      Specified by:
      broadcast in interface org.openhab.core.io.rest.sse.internal.SsePublisher
    • listen

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

      @GET @Path("/states") @Produces("text/event-stream") public void getStateEvents(@Context javax.ws.rs.sse.SseEventSink 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
      Parameters:
      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.
      Parameters:
      stateChangeEvent - the ItemStateChangedEvent containing the new state