Search in sources :

Example 1 with ReadyMarker

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

the class ReadyServiceImplTest method testTrackersAreInformedInitially.

@Test
public void testTrackersAreInformedInitially() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.markReady(new ReadyMarker("test", "id"));
    rs.registerTracker(tracker);
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) ReadyTracker(org.eclipse.smarthome.core.service.ReadyService.ReadyTracker) Test(org.junit.Test)

Example 2 with ReadyMarker

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

the class ReadyServiceImplTest method testTrackersAreInformedOnChange.

@Test
public void testTrackersAreInformedOnChange() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.registerTracker(tracker);
    rs.markReady(new ReadyMarker("test", "id"));
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    rs.unmarkReady(new ReadyMarker("test", "id"));
    verify(tracker).onReadyMarkerRemoved(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) ReadyTracker(org.eclipse.smarthome.core.service.ReadyService.ReadyTracker) Test(org.junit.Test)

Example 3 with ReadyMarker

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

the class XmlDocumentBundleTracker method registerReadyMarker.

private void registerReadyMarker(Bundle bundle) {
    String bsn = bundle.getSymbolicName();
    if (!bundleReadyMarkerRegistrations.containsKey(bsn)) {
        ReadyMarker readyMarker = new ReadyMarker(readyMarkerKey, bsn);
        readyService.markReady(readyMarker);
        bundleReadyMarkerRegistrations.put(bsn, readyMarker);
    }
}
Also used : ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker)

Example 4 with ReadyMarker

use of org.eclipse.smarthome.core.service.ReadyMarker 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 5 with ReadyMarker

use of org.eclipse.smarthome.core.service.ReadyMarker 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)

Aggregations

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