/** {@inheritDoc} */ @Override public void registerGatewayGroup(GatewayGroup gatewayGroup) { m_registrations.add( m_serviceRegistry.register(gatewayGroup, GatewayGroup.class)); }
private GeolocationResolver getGeolocationResolver() { return serviceRegistry.findProvider(GeolocationResolver.class); }
public List<SystemReportFormatter> getFormatters() { initializeSpring(); final List<SystemReportFormatter> formatters = new ArrayList<SystemReportFormatter>(m_serviceRegistry.findProviders(SystemReportFormatter.class)); Collections.sort(formatters); return formatters; }
Registration registration = m_registry.register(provider, Hello.class, Goodbye.class); m_registry.addRegistrationHook(hook, true); Collection<Hello> hellos = m_registry.findProviders(Hello.class); Collection<Goodbye> goodbyes = m_registry.findProviders(Goodbye.class); hellos = m_registry.findProviders(Hello.class); goodbyes = m_registry.findProviders(Goodbye.class);
@Test public void testRegistrationListener() { Listener<Hello> helloListener = new Listener<>(); Listener<Goodbye> goodbyeListener = new Listener<>(); 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()); }
@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)); }
/** * <p>afterPropertiesSet</p> * * @throws java.lang.Exception if any. */ @Override public void afterPropertiesSet() throws Exception { Assert.notNull(m_serviceRegistry, "The serviceRegistry must be set"); Assert.notNull(m_serviceInterface, "The serviceInterface must be set"); m_serviceRegistry.addListener(m_serviceInterface, this, true); }
@Override public void start(final BundleContext bundleContext) throws InvalidSyntaxException { LOG.debug("Starting BundleActivator {}", this.toString()); m_bundleContext.set(bundleContext); // register for ONMS registrations to forward registrations to OSGi service registry getRegistry().addRegistrationHook(this, true); // register service listener for export osgi services to forward to ONMS registry String exportFilter = "("+REGISTRATION_EXPORT+"=*)"; bundleContext.addServiceListener(this, exportFilter); // forward any existing exported OSGi services with ONMS service registry ServiceReference<?>[] osgiServices = bundleContext.getAllServiceReferences(null, exportFilter); if (osgiServices != null) { for(ServiceReference<?> reference : osgiServices) { registerWithOnmsRegistry(reference); } } LOG.debug("BundleActivator {} started", this.toString()); }
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); m_registry.addRegistrationHook(hook, true); Collection<Hello> hellos = m_registry.findProviders(Hello.class); Collection<Goodbye> goodbyes = m_registry.findProviders(Goodbye.class); Collection<Hello> bigHellos = m_registry.findProviders(Hello.class, "(size=big)"); Collection<Goodbye> bigGoodbyes = m_registry.findProviders(Goodbye.class, "(size=big)"); 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)"); assertTrue(m_registry.findProviders(Hello.class, "(size=big)").isEmpty()); assertEquals(1, m_registry.findProviders(Hello.class, "(size=small)").size()); 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);
/** * <p>afterPropertiesSet</p> * * @throws java.lang.Exception if any. */ @Override public void afterPropertiesSet() throws Exception { Assert.notNull(m_serviceRegistry, "The serviceRegistry must be set"); Assert.notNull(m_serviceInterface, "The serviceInterface must be set"); m_serviceRegistry.addListener(m_serviceInterface, this, true); }
@Override public void start(final BundleContext bundleContext) throws InvalidSyntaxException { LOG.debug("Starting BundleActivator {}", this.toString()); m_bundleContext.set(bundleContext); // register for ONMS registrations to forward registrations to OSGi service registry getRegistry().addRegistrationHook(this, true); // register service listener for export osgi services to forward to ONMS registry String exportFilter = "("+REGISTRATION_EXPORT+"=*)"; bundleContext.addServiceListener(this, exportFilter); // forward any existing exported OSGi services with ONMS service registry ServiceReference<?>[] osgiServices = bundleContext.getAllServiceReferences(null, exportFilter); if (osgiServices != null) { for(ServiceReference<?> reference : osgiServices) { registerWithOnmsRegistry(reference); } } LOG.debug("BundleActivator {} started", this.toString()); }
private <T> void addAllExtensions(Collection<T> extensions, Class<?>... extensionPoints) { if (extensions == null || extensions.isEmpty()) { LOG.info("Found NO Extensions for ExtensionPoints {}", Arrays.toString(extensionPoints)); return; } for(T extension : extensions) { LOG.info("Register Extension {} for ExtensionPoints {}", extension, Arrays.toString(extensionPoints)); m_serviceRegistry.register(extension, extensionPoints); } }
@Override public <T> T lookup(Class<?> serviceType, String filter) { Objects.requireNonNull(serviceType); final T service = (T) this.registry.findProvider(serviceType, filter); return service; } }
public List<SystemReportPlugin> getPlugins() { initializeSpring(); final List<SystemReportPlugin> plugins = new ArrayList<SystemReportPlugin>(m_serviceRegistry.findProviders(SystemReportPlugin.class)); Collections.sort(plugins); return plugins; }
private ConfigReloadContainer(Builder<V> builder) { clazz = builder.clazz; object = builder.initialConfig; if (object != null) { // We have some initial state if (builder.lastUpdate != null) { // The user specified an initial date, use it lastUpdate = builder.lastUpdate.getTime(); } else { // We have some object, but no date was specified, default to "now" lastUpdate = System.currentTimeMillis(); } // We were provided with some object, so defer the reload check until // the specified interval has passed lastReloadCheck = System.currentTimeMillis(); } if (builder.reloadCheckIntervalInMs == null) { reloadCheckIntervalInMs = DEFAULT_RELOAD_CHECK_INTERVAL_MS; } else if (builder.reloadCheckIntervalInMs <= 0) { reloadCheckIntervalInMs = -1; } else { reloadCheckIntervalInMs = builder.reloadCheckIntervalInMs; } builder.providers.forEach(p -> { providers.add(new ConfigurationProviderState<V>(p)); }); merger = builder.merger; REGISTRY.addListener(ConfigurationProvider.class, this, true); }
private <T> void addAllExtensions(Collection<T> extensions, Class<?>... extensionPoints) { if (extensions == null || extensions.isEmpty()) { LOG.info("Found NO Extensions for ExtensionPoints {}", Arrays.toString(extensionPoints)); return; } for(T extension : extensions) { LOG.info("Register Extension {} for ExtensionPoints {}", extension, Arrays.toString(extensionPoints)); m_serviceRegistry.register(extension, extensionPoints); } }
/** {@inheritDoc} */ @Override protected Object createObject() throws Exception { Object object = m_serviceRegistry.findProvider(m_serviceInterface, m_filter); if (object == null) { throw new IllegalStateException("Unable to find an object that implements '" + m_serviceInterface + (m_filter == null ? "'" : " matching filter "+m_filter)); } return object; }
public List<SystemReportPlugin> getPlugins() { initializeSpring(); final List<SystemReportPlugin> plugins = new ArrayList<SystemReportPlugin>(m_serviceRegistry.findProviders(SystemReportPlugin.class)); Collections.sort(plugins); return plugins; }
/** * <p>afterPropertiesSet</p> * * @throws java.lang.Exception if any. */ @Override public void afterPropertiesSet() throws Exception { boolean hasText = StringUtils.hasText(m_targetBeanName); Assert.isTrue(hasText || m_target != null, "targetBeanName or target must be set"); Assert.notEmpty(m_serviceInterfaces, "interfaces must be set"); if (m_target == null) { Assert.notNull(m_beanFactory, "beanFactory must not be null"); } Object provider = m_target != null ? m_target : m_beanFactory.getBean(m_targetBeanName); m_registration = m_serviceRegistry.register(provider, m_serviceProperties, m_serviceInterfaces); }
@Override public <T> T lookup(Class<?> serviceType, String filter) { Objects.requireNonNull(serviceType); final T service = (T) this.registry.findProvider(serviceType, filter); return service; } }