Search in sources :

Example 1 with ReadyMarkerFilter

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);
}
Also used : Logger(org.slf4j.Logger) ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadyMarker(org.openhab.core.service.ReadyMarker) Consumer(java.util.function.Consumer) Component(org.osgi.service.component.annotations.Component) ReadyService(org.openhab.core.service.ReadyService) Map(java.util.Map) Collections(java.util.Collections) ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter)

Example 2 with ReadyMarkerFilter

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);
}
Also used : ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Test(org.junit.jupiter.api.Test)

Example 3 with ReadyMarkerFilter

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);
}
Also used : ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Test(org.junit.jupiter.api.Test)

Example 4 with ReadyMarkerFilter

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)));
}
Also used : ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Thing(org.openhab.core.thing.Thing)

Example 5 with ReadyMarkerFilter

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)));
}
Also used : ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

ReadyMarkerFilter (org.openhab.core.service.ReadyMarkerFilter)5 ReadyMarker (org.openhab.core.service.ReadyMarker)4 ReadyTracker (org.openhab.core.service.ReadyService.ReadyTracker)3 Test (org.junit.jupiter.api.Test)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Consumer (java.util.function.Consumer)1 ReadyService (org.openhab.core.service.ReadyService)1 Thing (org.openhab.core.thing.Thing)1 Activate (org.osgi.service.component.annotations.Activate)1 Component (org.osgi.service.component.annotations.Component)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1