Search in sources :

Example 1 with ReadyMarkerFilter

use of org.eclipse.smarthome.core.service.ReadyMarkerFilter in project smarthome by eclipse.

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) ReadyService(org.eclipse.smarthome.core.service.ReadyService) 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.eclipse.smarthome.core.service.ReadyMarker) Consumer(java.util.function.Consumer) ReadyMarkerFilter(org.eclipse.smarthome.core.service.ReadyMarkerFilter) Component(org.osgi.service.component.annotations.Component) Map(java.util.Map) Collections(java.util.Collections) ReadyMarkerFilter(org.eclipse.smarthome.core.service.ReadyMarkerFilter)

Example 2 with ReadyMarkerFilter

use of org.eclipse.smarthome.core.service.ReadyMarkerFilter in project smarthome by eclipse.

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.eclipse.smarthome.core.service.ReadyMarker) ReadyMarkerFilter(org.eclipse.smarthome.core.service.ReadyMarkerFilter) ReadyTracker(org.eclipse.smarthome.core.service.ReadyService.ReadyTracker) Test(org.junit.Test)

Example 3 with ReadyMarkerFilter

use of org.eclipse.smarthome.core.service.ReadyMarkerFilter in project smarthome by eclipse.

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.eclipse.smarthome.core.service.ReadyMarkerFilter) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) ReadyTracker(org.eclipse.smarthome.core.service.ReadyService.ReadyTracker) Test(org.junit.Test)

Aggregations

ReadyMarker (org.eclipse.smarthome.core.service.ReadyMarker)3 ReadyMarkerFilter (org.eclipse.smarthome.core.service.ReadyMarkerFilter)3 ReadyTracker (org.eclipse.smarthome.core.service.ReadyService.ReadyTracker)2 Test (org.junit.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.eclipse.smarthome.core.service.ReadyService)1 Component (org.osgi.service.component.annotations.Component)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1