Package org.openhab.core.io.rest.sse
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 Summary
-
Constructor Summary
ConstructorDescriptionSseResource
(org.openhab.core.io.rest.sse.internal.SseItemStatesEventBuilder itemStatesEventBuilder) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
getStateEvents
(javax.ws.rs.sse.SseEventSink sseEventSink, javax.servlet.http.HttpServletResponse response) Subscribes the connecting client for state updates.void
handleEventBroadcastItemState
(ItemStateChangedEvent stateChangeEvent) Broadcasts a state event to all currently listening clients, after transforming it to a simple map.void
listen
(javax.ws.rs.sse.SseEventSink sseEventSink, javax.servlet.http.HttpServletResponse response, String eventFilter) updateTrackedItems
(@Nullable String connectionId, @Nullable Set<String> itemNames) Alters the list of tracked items for a given state update connection
-
Field Details
-
PATH_EVENTS
- See Also:
-
ALIVE_INTERVAL_SECONDS
public static final int ALIVE_INTERVAL_SECONDS- See Also:
-
-
Constructor Details
-
SseResource
public SseResource(org.openhab.core.io.rest.sse.internal.SseItemStatesEventBuilder itemStatesEventBuilder)
-
-
Method Details
-
deactivate
public void deactivate() -
broadcast
- Specified by:
broadcast
in interfaceorg.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 changeitemNames
- the list of items to track
-
handleEventBroadcastItemState
Broadcasts a state event to all currently listening clients, after transforming it to a simple map.- Parameters:
stateChangeEvent
- theItemStateChangedEvent
containing the new state
-