mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 19:55:48 +01:00
rest/sse: Use constructor injection to simplify lifecycle (#838)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
8b59505145
commit
3ab9bab2f4
@ -15,10 +15,13 @@ package org.eclipse.smarthome.io.rest.sse.internal.listeners;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.smarthome.core.events.Event;
|
||||
import org.eclipse.smarthome.core.events.EventFilter;
|
||||
import org.eclipse.smarthome.core.events.EventSubscriber;
|
||||
import org.eclipse.smarthome.io.rest.sse.SseResource;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
|
||||
@ -29,28 +32,25 @@ import org.osgi.service.component.annotations.Reference;
|
||||
* @author Stefan Bußweiler - Initial contribution
|
||||
*/
|
||||
@Component
|
||||
@NonNullByDefault
|
||||
public class SseEventSubscriber implements EventSubscriber {
|
||||
|
||||
private final Set<String> subscribedEventTypes = Collections.singleton(EventSubscriber.ALL_EVENT_TYPES);
|
||||
|
||||
private SseResource sseResource;
|
||||
private final SseResource sseResource;
|
||||
|
||||
@Reference
|
||||
protected void setSseResource(SseResource sseResource) {
|
||||
@Activate
|
||||
public SseEventSubscriber(final @Reference SseResource sseResource) {
|
||||
this.sseResource = sseResource;
|
||||
}
|
||||
|
||||
protected void unsetSseResource(SseResource sseResource) {
|
||||
this.sseResource = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSubscribedEventTypes() {
|
||||
return subscribedEventTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFilter getEventFilter() {
|
||||
public @Nullable EventFilter getEventFilter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -58,5 +58,4 @@ public class SseEventSubscriber implements EventSubscriber {
|
||||
public void receive(Event event) {
|
||||
sseResource.broadcastEvent(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user