/** * <p>destroy</p> * * @throws java.lang.Exception if any. */ @Override public void destroy() throws Exception { for(Registration registration : m_registrations) { registration.unregister(); } }
@Override public void registrationAdded(final Registration onmsRegistration) { final Map<String, String> onmsProperties = onmsRegistration.getProperties() == null ? Collections.<String,String>emptyMap() : onmsRegistration.getProperties(); if (OSGI_SOURCE.equals(onmsProperties.get(REGISTRATION_SOURCE))) return; final Class<?>[] providerInterfaces = onmsRegistration.getProvidedInterfaces(); final String[] serviceClasses = new String[providerInterfaces.length]; for(int i = 0; i < providerInterfaces.length; i++) { serviceClasses[i] = providerInterfaces[i].getName(); } final Dictionary<String,String> props = new Hashtable<String,String>(); for(final Entry<String, String> entry : onmsProperties.entrySet()) { props.put(entry.getKey(), entry.getValue()); } props.put(REGISTRATION_SOURCE, ONMS_SOURCE); final BundleContext bundleContext = m_bundleContext.get(); if (bundleContext != null) { ServiceRegistration<?> osgiRegistration = bundleContext.registerService(serviceClasses, onmsRegistration.getProvider(), props); m_onmsRegistration2osgiRegistrationMap.put(onmsRegistration, osgiRegistration); } }
private void invokeMethod(String methodName, Registration registration) { try { Method method = getMethod(methodName); method.invoke(m_target, registration.getProvider(m_serviceInterface), registration.getProperties()); } catch (Throwable e) { throw new UndeclaredThrowableException(e, "Unexexpected exception invoking method " + methodName); } finally { } }
@Override public void providerRegistered(Registration registration, ConfigurationProvider provider) { if (clazz.equals(registration.getProvider(ConfigurationProvider.class).getType()) && providers.add(new ConfigurationProviderState<>(provider))) { LOG.debug("Registered configuration provider {} for {}.", provider, clazz.getCanonicalName()); // Force a check on the next get forceReload = true; } }
@Test @DirtiesContext public void testInjected() { assertEquals(m_provider, m_simpleRegistration.getProvider(Hello.class)); assertContains(m_simpleRegistration.getProvidedInterfaces(), Hello.class); assertEquals(m_provider, m_nestedRegistration.getProvider(Hello.class)); assertContains(m_nestedRegistration.getProvidedInterfaces(), Hello.class, Goodbye.class); }
/** {@inheritDoc} */ @Override public void providerRegistered(Registration registration, T provider) { if (m_filter != null && !m_filter.match(registration.getProperties())) { // this object doesn't match the filter so skip it return; } m_providerRegistrations.add(provider); for(RegistrationListener<T> listener : m_listeners) { listener.providerRegistered(registration, provider); } }
private <T> void fireProviderRegistered(Class<T> serviceInterface, Registration registration) { Set<RegistrationListener<T>> listeners = getListeners(serviceInterface); for(RegistrationListener<T> listener : listeners) { listener.providerRegistered(registration, registration.getProvider(serviceInterface)); } }
private void invokeMethod(String methodName, Registration registration) { try { Method method = getMethod(methodName); method.invoke(m_target, registration.getProvider(m_serviceInterface), registration.getProperties()); } catch (Throwable e) { throw new UndeclaredThrowableException(e, "Unexexpected exception invoking method " + methodName); } finally { } }
/** {@inheritDoc} */ @Override public void providerRegistered(Registration registration, T provider) { if (m_filter != null && !m_filter.match(registration.getProperties())) { // this object doesn't match the filter so skip it return; } m_providerRegistrations.add(provider); for(RegistrationListener<T> listener : m_listeners) { listener.providerRegistered(registration, provider); } }
/** * <p>destroy</p> * * @throws java.lang.Exception if any. */ @Override public void destroy() throws Exception { if ( m_registration != null ) { m_registration.unregister(); } }
@Override public void registrationAdded(final Registration onmsRegistration) { final Map<String, String> onmsProperties = onmsRegistration.getProperties() == null ? Collections.<String,String>emptyMap() : onmsRegistration.getProperties(); if (OSGI_SOURCE.equals(onmsProperties.get(REGISTRATION_SOURCE))) return; final Class<?>[] providerInterfaces = onmsRegistration.getProvidedInterfaces(); final String[] serviceClasses = new String[providerInterfaces.length]; for(int i = 0; i < providerInterfaces.length; i++) { serviceClasses[i] = providerInterfaces[i].getName(); } final Dictionary<String,String> props = new Hashtable<String,String>(); for(final Entry<String, String> entry : onmsProperties.entrySet()) { props.put(entry.getKey(), entry.getValue()); } props.put(REGISTRATION_SOURCE, ONMS_SOURCE); final BundleContext bundleContext = m_bundleContext.get(); if (bundleContext != null) { ServiceRegistration<?> osgiRegistration = bundleContext.registerService(serviceClasses, onmsRegistration.getProvider(), props); m_onmsRegistration2osgiRegistrationMap.put(onmsRegistration, osgiRegistration); } }
private <T> void fireProviderUnregistered(Class<T> serviceInterface, Registration registration) { Set<RegistrationListener<T>> listeners = getListeners(serviceInterface); for(RegistrationListener<T> listener : listeners) { listener.providerUnregistered(registration, registration.getProvider(serviceInterface)); } }
@Test @DirtiesContext public void testServiceProperties() { assertNotNull(m_bigRegistration); assertNotNull(m_bigRegistration.getProperties()); assertEquals("big", m_bigRegistration.getProperties().get("size")); assertNotNull(m_smallRegistration); assertNotNull(m_smallRegistration.getProperties()); assertEquals("small", m_smallRegistration.getProperties().get("size")); }
/** * <p>destroy</p> * * @throws java.lang.Exception if any. */ @Override public void destroy() throws Exception { if ( m_registration != null ) { m_registration.unregister(); } }
private <T> void fireProviderRegistered(Class<T> serviceInterface, Registration registration) { Set<RegistrationListener<T>> listeners = getListeners(serviceInterface); for(RegistrationListener<T> listener : listeners) { listener.providerRegistered(registration, registration.getProvider(serviceInterface)); } }
private void unregisterWithOnmsRegistry(final ServiceReference<?> reference) { final Registration onmsRegistration = m_osgiReference2onmsRegistrationMap.remove(reference); if (onmsRegistration == null) return; onmsRegistration.unregister(); }
private <T> void fireProviderUnregistered(Class<T> serviceInterface, Registration registration) { Set<RegistrationListener<T>> listeners = getListeners(serviceInterface); for(RegistrationListener<T> listener : listeners) { listener.providerUnregistered(registration, registration.getProvider(serviceInterface)); } }
private void unregisterWithOnmsRegistry(final ServiceReference<?> reference) { final Registration onmsRegistration = m_osgiReference2onmsRegistrationMap.remove(reference); if (onmsRegistration == null) return; onmsRegistration.unregister(); }
@Test @DirtiesContext public void testRegistration() { assertNotNull(m_provider); assertNotNull(m_registration); assertNotNull(m_registry); assertSame(m_provider, m_registration.getProvider(Hello.class)); assertSame(m_provider, m_registration.getProvider(Goodbye.class)); assertEquals(1, m_registry.findProviders(Hello.class).size()); assertEquals(1, m_registry.findProviders(Goodbye.class).size()); assertSame(m_provider, m_registry.findProvider(Hello.class)); assertSame(m_provider, m_registry.findProvider(Goodbye.class)); }
@Override public void reloadConfig() throws NorthbounderException { LOG.info("Reloading JMS northbound configuration."); try { m_configDao.reload(); m_registrations.forEach((k,v) -> { if (k != getName()) v.unregister();}); registerNorthnounders(); } catch (Exception e) { throw new NorthbounderException("Can't reload the JMS northbound configuration", e); } }