use of org.osgi.framework.ServiceRegistration in project aries by apache.
the class ServiceRegistryContextTest method checkProxyDynamism.
@Test
public void checkProxyDynamism() throws NamingException {
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
String className = Runnable.class.getName();
Runnable t = Skeleton.newMock(Runnable.class);
Runnable t2 = Skeleton.newMock(Runnable.class);
// we don't want the default service
reg.unregister();
ServiceRegistration reg = bc.registerService(className, t, null);
bc.registerService(className, t2, null);
Runnable r = (Runnable) ctx.lookup("osgi:service/java.lang.Runnable");
r.run();
Skeleton.getSkeleton(t).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
Skeleton.getSkeleton(t2).assertNotCalled(new MethodCall(Runnable.class, "run"));
reg.unregister();
r.run();
Skeleton.getSkeleton(t).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
Skeleton.getSkeleton(t2).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
}
use of org.osgi.framework.ServiceRegistration in project aries by apache.
the class ParserServiceImportAndIncludeXSDsTest method waitForConfig.
private boolean waitForConfig() throws InterruptedException {
final AtomicBoolean ready = new AtomicBoolean();
@SuppressWarnings("rawtypes") ServiceRegistration reg = context().registerService(BlueprintListener.class, new BlueprintListener() {
@Override
public void blueprintEvent(BlueprintEvent event) {
if (TEST_BUNDLE.equals(event.getBundle().getSymbolicName()) && BlueprintEvent.CREATED == event.getType()) {
synchronized (ready) {
ready.set(true);
ready.notify();
}
}
}
}, null);
try {
synchronized (ready) {
if (!ready.get()) {
ready.wait(3000);
}
}
return ready.get();
} finally {
reg.unregister();
}
}
use of org.osgi.framework.ServiceRegistration in project aries by apache.
the class ParserServiceImportCmAndIncorrectNamespaceHandlersTest method waitForConfig.
private void waitForConfig() throws InterruptedException {
final CountDownLatch ready = new CountDownLatch(2);
final AtomicBoolean failure = new AtomicBoolean(false);
@SuppressWarnings("rawtypes") ServiceRegistration reg = context().registerService(BlueprintListener.class, new BlueprintListener() {
@Override
public void blueprintEvent(BlueprintEvent event) {
if (NS_HANDLER_BUNDLE.equals(event.getBundle().getSymbolicName()) && BlueprintEvent.CREATED == event.getType()) {
ready.countDown();
} else if (TEST_BUNDLE.equals(event.getBundle().getSymbolicName()) && (BlueprintEvent.CREATED == event.getType() || BlueprintEvent.FAILURE == event.getType())) {
ready.countDown();
if (BlueprintEvent.FAILURE == event.getType()) {
failure.set(true);
}
}
}
}, null);
try {
assertTrue(ready.await(3000, TimeUnit.MILLISECONDS));
assertFalse("org.apache.aries.blueprint.aries1503.test bundle should successfully start Blueprint container", failure.get());
} finally {
reg.unregister();
}
}
use of org.osgi.framework.ServiceRegistration in project aries by apache.
the class ServiceStateMBeanTest method testAttributeChangeNotifications.
@Test
public void testAttributeChangeNotifications() throws Exception {
final List<AttributeChangeNotification> attributeChanges = new ArrayList<AttributeChangeNotification>();
mbeanServer.addNotificationListener(objectName, new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
if (notification instanceof AttributeChangeNotification) {
attributeChanges.add((AttributeChangeNotification) notification);
}
}
}, null, null);
assertEquals("Precondition", 0, attributeChanges.size());
long[] idsWithout = mbean.getServiceIds();
String svc = "A String Service";
ServiceRegistration reg = bundleContext.registerService(String.class.getName(), svc, null);
long id = (Long) reg.getReference().getProperty(Constants.SERVICE_ID);
long[] idsWith = new long[idsWithout.length + 1];
System.arraycopy(idsWithout, 0, idsWith, 0, idsWithout.length);
idsWith[idsWith.length - 1] = id;
Arrays.sort(idsWith);
waitForListToReachSize(attributeChanges, 1);
AttributeChangeNotification ac = attributeChanges.get(0);
assertEquals("ServiceIds", ac.getAttributeName());
long seq1 = ac.getSequenceNumber();
assertTrue(Arrays.equals(idsWithout, (long[]) ac.getOldValue()));
assertTrue(Arrays.equals(idsWith, (long[]) ac.getNewValue()));
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("somekey", "someval");
reg.setProperties(props);
// Setting the properties updates the service registration, however it should not cause the attribute notification
// Give the system a bit of time to send potential notifications
Thread.sleep(500);
assertEquals("Changing the service registration should not cause an attribute notification", 1, attributeChanges.size());
reg.unregister();
waitForListToReachSize(attributeChanges, 2);
AttributeChangeNotification ac2 = attributeChanges.get(1);
assertEquals("ServiceIds", ac2.getAttributeName());
assertEquals(seq1 + 1, ac2.getSequenceNumber());
assertTrue(Arrays.equals(idsWith, (long[]) ac2.getOldValue()));
assertTrue(Arrays.equals(idsWithout, (long[]) ac2.getNewValue()));
}
use of org.osgi.framework.ServiceRegistration in project aries by apache.
the class Activator method stop.
public void stop(BundleContext ctx) {
tm.close();
t.close();
if (nshReg != null) {
for (ServiceRegistration reg : nshReg) {
safeUnregisterService(reg);
}
}
}
Aggregations