use of org.apache.felix.dm.tracker.ServiceTracker in project felix by apache.
the class ServiceDependencyImpl method start.
@Override
public void start() {
if (m_trackedServiceName != null) {
BundleContext ctx = m_component.getBundleContext();
if (m_trackedServiceFilter != null) {
try {
m_tracker = new ServiceTracker(ctx, ctx.createFilter(m_trackedServiceFilter), this);
} catch (InvalidSyntaxException e) {
throw new IllegalStateException("Invalid filter definition for dependency: " + m_trackedServiceFilter);
}
} else if (m_trackedServiceReference != null) {
m_tracker = new ServiceTracker(ctx, m_trackedServiceReference, this);
} else {
m_tracker = new ServiceTracker(ctx, m_trackedServiceName.getName(), this);
}
} else {
throw new IllegalStateException("Could not create tracker for dependency, no service name specified.");
}
if (m_debug) {
m_tracker.setDebug(m_debugKey);
}
m_tracker.open();
super.start();
}
use of org.apache.felix.dm.tracker.ServiceTracker in project felix by apache.
the class MultiPropertyFilterIndex method close.
public void close() {
ServiceTracker tracker;
synchronized (m_lock) {
if (m_context == null) {
throw new IllegalStateException("Filter already closed.");
}
tracker = m_tracker;
m_tracker = null;
m_context = null;
}
tracker.close();
}
use of org.apache.felix.dm.tracker.ServiceTracker in project felix by apache.
the class TrackedTest method testSetInitialTrackAspects.
@Test
public void testSetInitialTrackAspects() {
System.out.println("testSetInitialTrackAspects");
TestCustomizer customizer = new TestCustomizer();
ServiceTracker tracker = new TestTracker(customizer);
tracker.open(false, true);
Tracked tracked = tracker.getTracked();
Object[] initialReferences = new Object[] { createServiceReference(1L), createServiceReference(2L, 1L, 10), createServiceReference(3L, 1L, 5) };
tracked.setInitial(initialReferences);
tracked.trackInitial();
tracked.getExecutor().execute();
assertArrayEquals(new Long[] { 1L, 2L, 3L }, customizer.getServiceReferenceIds());
}
use of org.apache.felix.dm.tracker.ServiceTracker in project felix by apache.
the class TrackedTest method testSetInitialHideAspects.
@Test
public void testSetInitialHideAspects() {
System.out.println("testSetInitialHideAspects");
TestCustomizer customizer = new TestCustomizer();
ServiceTracker tracker = new TestTracker(customizer);
tracker.open();
Tracked tracked = tracker.getTracked();
Object[] initialReferences = new Object[] { createServiceReference(1L), createServiceReference(2L, 1L, 10), createServiceReference(3L), createServiceReference(4L, 1L, 5), createServiceReference(5L, 3L, 5) };
tracked.setInitial(initialReferences);
tracked.trackInitial();
tracked.getExecutor().execute();
assertArrayEquals(new Long[] { 2L, 5L }, customizer.getServiceReferenceIds());
}
use of org.apache.felix.dm.tracker.ServiceTracker in project felix by apache.
the class TrackedTest method testUnHideAspect.
@Test
public void testUnHideAspect() {
System.out.println("testUnhideAspect");
TestCustomizer customizer = new TestCustomizer();
ServiceTracker tracker = new TestTracker(customizer);
tracker.open();
Tracked tracked = tracker.getTracked();
ServiceReference<?>[] initialReferences = new ServiceReference[] { createServiceReference(1L), createServiceReference(2L, 1L, 10), createServiceReference(3L), createServiceReference(4L, 1L, 5), createServiceReference(5L, 3L, 5) };
tracked.setInitial(initialReferences);
tracked.trackInitial();
tracked.getExecutor().execute();
assertArrayEquals(new Long[] { 2L, 5L }, customizer.getServiceReferenceIds());
// create a service event that unregisters service with id 2, we would expect it to be swapped with 4.
ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, initialReferences[1]);
tracked.serviceChanged(event);
assertArrayEquals(new Long[] { 5L, 4L }, customizer.getServiceReferenceIds());
// create a service event that unregisters service with id 4, we would expect it to be swapped with 1.
event = new ServiceEvent(ServiceEvent.UNREGISTERING, initialReferences[3]);
tracked.serviceChanged(event);
assertArrayEquals(new Long[] { 5L, 1L }, customizer.getServiceReferenceIds());
}
Aggregations