Search in sources :

Example 1 with Registration

use of org.opennms.core.soa.Registration in project opennms by OpenNMS.

the class OnmsOSGiBridgeActivator method unregisterWithOnmsRegistry.

private void unregisterWithOnmsRegistry(final ServiceReference<?> reference) {
    final Registration onmsRegistration = m_osgiReference2onmsRegistrationMap.remove(reference);
    if (onmsRegistration == null)
        return;
    onmsRegistration.unregister();
}
Also used : Registration(org.opennms.core.soa.Registration) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with Registration

use of org.opennms.core.soa.Registration in project opennms by OpenNMS.

the class DefaultServiceRegistryTest method testRegisterUnregisterUsingFilters.

@Test
public void testRegisterUnregisterUsingFilters() {
    MyProvider bigProvider = new MyProvider();
    MyProvider smallProvider = new MyProvider();
    Map<String, String> bigProps = new HashMap<String, String>();
    bigProps.put("size", "big");
    Map<String, String> smallProps = new HashMap<String, String>();
    smallProps.put("size", "small");
    Registration bigRegistration = m_registry.register(bigProvider, bigProps, Hello.class, Goodbye.class);
    Registration smallRegistration = m_registry.register(smallProvider, smallProps, Hello.class, Goodbye.class);
    Hook hook = new Hook();
    m_registry.addRegistrationHook(hook, true);
    assertEquals(2, hook.getCount());
    Collection<Hello> hellos = m_registry.findProviders(Hello.class);
    Collection<Goodbye> goodbyes = m_registry.findProviders(Goodbye.class);
    assertEquals(2, hellos.size());
    assertEquals(2, goodbyes.size());
    Collection<Hello> bigHellos = m_registry.findProviders(Hello.class, "(size=big)");
    Collection<Goodbye> bigGoodbyes = m_registry.findProviders(Goodbye.class, "(size=big)");
    assertEquals(1, bigHellos.size());
    assertEquals(1, bigGoodbyes.size());
    assertSame(bigProvider, bigHellos.iterator().next());
    assertSame(bigProvider, bigGoodbyes.iterator().next());
    Collection<Hello> smallHellos = m_registry.findProviders(Hello.class, "(size=small)");
    Collection<Goodbye> smallGoodbyes = m_registry.findProviders(Goodbye.class, "(size=small)");
    assertEquals(1, smallHellos.size());
    assertEquals(1, smallGoodbyes.size());
    assertSame(smallProvider, smallHellos.iterator().next());
    assertSame(smallProvider, smallGoodbyes.iterator().next());
    bigRegistration.unregister();
    assertEquals(1, hook.getCount());
    assertTrue(m_registry.findProviders(Hello.class, "(size=big)").isEmpty());
    assertEquals(1, m_registry.findProviders(Hello.class, "(size=small)").size());
    smallRegistration.unregister();
    assertEquals(0, hook.getCount());
    assertTrue(m_registry.findProviders(Hello.class, "(size=big)").isEmpty());
    assertTrue(m_registry.findProviders(Hello.class, "(size=small)").isEmpty());
    hellos = m_registry.findProviders(Hello.class);
    goodbyes = m_registry.findProviders(Goodbye.class);
    assertTrue(hellos.isEmpty());
    assertTrue(goodbyes.isEmpty());
}
Also used : RegistrationHook(org.opennms.core.soa.RegistrationHook) HashMap(java.util.HashMap) Registration(org.opennms.core.soa.Registration) Test(org.junit.Test)

Example 3 with Registration

use of org.opennms.core.soa.Registration in project opennms by OpenNMS.

the class DefaultServiceRegistryTest method testRegistrationListener.

@Test
public void testRegistrationListener() {
    Listener<Hello> helloListener = new Listener<Hello>();
    Listener<Goodbye> goodbyeListener = new Listener<Goodbye>();
    m_registry.addListener(Hello.class, helloListener);
    m_registry.addListener(Goodbye.class, goodbyeListener);
    MyProvider provider = new MyProvider();
    Registration registration = m_registry.register(provider, Hello.class, Goodbye.class);
    assertEquals(1, helloListener.size());
    assertEquals(1, goodbyeListener.size());
    assertTrue(helloListener.contains(provider));
    assertTrue(goodbyeListener.contains(provider));
    registration.unregister();
    assertEquals(0, helloListener.size());
    assertEquals(0, goodbyeListener.size());
}
Also used : RegistrationListener(org.opennms.core.soa.RegistrationListener) Registration(org.opennms.core.soa.Registration) Test(org.junit.Test)

Example 4 with Registration

use of org.opennms.core.soa.Registration in project opennms by OpenNMS.

the class NamespaceHandlerTest method testRegistrationListenerBeanDefinition.

@Test
@DirtiesContext
public void testRegistrationListenerBeanDefinition() {
    assertNotNull(m_helloListListener);
    MyProvider myProvider = new MyProvider();
    int expected = m_helloListListener.getTotalProviders() + 1;
    Registration registration = m_defaultServiceRegistry.register(myProvider, Hello.class);
    assertEquals(expected, m_helloListListener.getTotalProviders());
    expected = m_helloListListener.getTotalProviders() - 1;
    registration.unregister();
    assertEquals(expected, m_helloListListener.getTotalProviders());
}
Also used : MyProvider(org.opennms.core.soa.support.MyProvider) Registration(org.opennms.core.soa.Registration) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 5 with Registration

use of org.opennms.core.soa.Registration in project opennms by OpenNMS.

the class RegistrationListenerBeanTest method testCallBindUnbindMethods.

@Test
public void testCallBindUnbindMethods() throws Exception {
    RegistrationListenerBean<Hello> listener = new RegistrationListenerBean<Hello>();
    listener.setServiceInterface(Hello.class);
    listener.setTarget(this);
    listener.setBindMethod("bind");
    listener.setUnbindMethod("unbind");
    listener.afterPropertiesSet();
    ServiceRegistry registry = new DefaultServiceRegistry();
    Registration reg1 = registry.register(new MyProvider("prov1"), Hello.class, Goodbye.class);
    Registration reg2 = registry.register(new MyProvider("prov2"), Hello.class, Goodbye.class);
    ReferenceListFactoryBean<Hello> bean = new ReferenceListFactoryBean<Hello>();
    bean.setServiceInterface(Hello.class);
    bean.setServiceRegistry(registry);
    bean.addListener(listener);
    bean.afterPropertiesSet();
    assertEquals(2, getTotalProvided());
    Registration reg3 = registry.register(new MyProvider("prov3"), Hello.class, Goodbye.class);
    assertEquals(3, getTotalProvided());
    reg2.unregister();
    assertEquals(2, getTotalProvided());
    reg1.unregister();
    reg3.unregister();
    assertEquals(0, getTotalProvided());
}
Also used : Registration(org.opennms.core.soa.Registration) ServiceRegistry(org.opennms.core.soa.ServiceRegistry) Test(org.junit.Test)

Aggregations

Registration (org.opennms.core.soa.Registration)11 Test (org.junit.Test)9 ServiceRegistry (org.opennms.core.soa.ServiceRegistry)3 MyProvider (org.opennms.core.soa.support.MyProvider)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 HashMap (java.util.HashMap)2 RegistrationHook (org.opennms.core.soa.RegistrationHook)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 LinkedHashMap (java.util.LinkedHashMap)1 RegistrationListener (org.opennms.core.soa.RegistrationListener)1 BundleContext (org.osgi.framework.BundleContext)1