use of org.openhab.core.service.ReadyMarkerFilter in project openhab-core by openhab.
the class ReadyServiceImpl method notifyTracker.
private void notifyTracker(ReadyTracker readyTracker, Consumer<ReadyMarker> action) {
ReadyMarkerFilter f = trackers.get(readyTracker);
markers.stream().filter(marker -> f.apply(marker)).forEach(action);
}
use of org.openhab.core.service.ReadyMarkerFilter in project openhab-core by openhab.
the class ReadyServiceImplTest method testTrackersAreInformedOnlyOnMatch.
@Test
public void testTrackersAreInformedOnlyOnMatch() {
ReadyTracker tracker = mock(ReadyTracker.class);
ReadyServiceImpl rs = new ReadyServiceImpl();
rs.registerTracker(tracker, new ReadyMarkerFilter().withType("test"));
rs.markReady(new ReadyMarker("foo", "id"));
verifyNoMoreInteractions(tracker);
rs.markReady(new ReadyMarker("test", "id"));
verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
verifyNoMoreInteractions(tracker);
}
use of org.openhab.core.service.ReadyMarkerFilter in project openhab-core by openhab.
the class ReadyServiceImplTest method testUnregisterTracker.
@Test
public void testUnregisterTracker() {
ReadyTracker tracker = mock(ReadyTracker.class);
ReadyServiceImpl rs = new ReadyServiceImpl();
rs.markReady(new ReadyMarker("foo", "id"));
rs.registerTracker(tracker, new ReadyMarkerFilter());
verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
rs.unregisterTracker(tracker);
verify(tracker).onReadyMarkerRemoved(isA(ReadyMarker.class));
verifyNoMoreInteractions(tracker);
}
use of org.openhab.core.service.ReadyMarkerFilter in project openhab-core by openhab.
the class ThingManagerImpl method initializeStartLevelSetter.
private void initializeStartLevelSetter() {
readyService.registerTracker(new ReadyTracker() {
@Override
public void onReadyMarkerRemoved(ReadyMarker readyMarker) {
}
@Override
public void onReadyMarkerAdded(ReadyMarker readyMarker) {
startLevelSetterJob = scheduler.scheduleWithFixedDelay(() -> {
for (Thing t : things) {
if (!ThingHandlerHelper.isHandlerInitialized(t) && t.isEnabled()) {
return;
}
}
readyService.markReady(marker);
if (startLevelSetterJob != null) {
startLevelSetterJob.cancel(false);
}
readyService.unregisterTracker(this);
}, 2, 2, TimeUnit.SECONDS);
}
}, new ReadyMarkerFilter().withType(StartLevelService.STARTLEVEL_MARKER_TYPE).withIdentifier(Integer.toString(StartLevelService.STARTLEVEL_MODEL)));
}
use of org.openhab.core.service.ReadyMarkerFilter in project openhab-core by openhab.
the class DefaultMetricsRegistration method activate.
@Activate
protected void activate() {
logger.trace("Activating DefaultMetricsRegistration...");
readyService.registerTracker(this, new ReadyMarkerFilter().withType(StartLevelService.STARTLEVEL_MARKER_TYPE).withIdentifier(Integer.toString(StartLevelService.STARTLEVEL_RULES)));
}
Aggregations