Package org.osgi.framework

Examples of org.osgi.framework.ServiceRegistration


     */
    protected ServiceRegistration registerJobExecutor(final String topic,
            final JobExecutor handler) {
        final Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(JobConsumer.PROPERTY_TOPICS, topic);
        final ServiceRegistration reg = this.bc.registerService(JobExecutor.class.getName(),
                handler, props);
        return reg;
    }
View Full Code Here


        final Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(HealthCheck.NAME, "name_" + id);
        props.put(HealthCheck.TAGS, id);
        props.put(HealthCheck.ASYNC_CRON_EXPRESSION, "*/1 * * * * ?");
       
        @SuppressWarnings("rawtypes")
        final ServiceRegistration reg = bundleContext.registerService(HealthCheck.class, hc, props);
       
        try {
            {
                // Wait for HC to be registered
                final long timeout = System.currentTimeMillis() + 10000L;
                boolean hcFound = false;
                while(System.currentTimeMillis() < timeout) {
                    final List<HealthCheckExecutionResult> results = executor.execute(id);
                    if(!results.isEmpty()) {
                        hcFound = true;
                        break;
                    }
                    Thread.sleep(100L);
                }
                assertTrue("Expecting HC to become active", hcFound);
            }
           
            // Now reset the counter and check that HC increments it even if we don't
            // use the executor
            {
                counter.set(0);
                final long timeout = System.currentTimeMillis() + 5000L;
                while(System.currentTimeMillis() < timeout) {
                    if(counter.get() > 0) {
                        break;
                    }
                    Thread.sleep(100L);
                }
                assertTrue("Expecting counter to be incremented", counter.get() > 0);
            }
           
            // Verify that we get the right log
            final String msg = executor.execute(id).get(0).getHealthCheckResult().iterator().next().getMessage();
            assertTrue("Expecting the right message: " + msg, msg.contains("counter is now"));
           
            // And verify that calling executor lots of times doesn't increment as much
            final int previous = counter.get();
            final int n = 100;
            for(int i=0; i < n; i++) {
                executor.execute(id);
            }
            assertTrue("Expecting counter to increment asynchronously", counter.get() < previous + n);
        } finally {
            reg.unregister();
        }
       
    }
View Full Code Here

     * can use this to manage repository lifecycle. Default implementation registers the BeanFactory
     * instance which would be used by the Repository creator to create the repository
     */
    protected void dependenciesSatisfied() {
        //TODO Review the thread safety aspect
        ServiceRegistration reg = beanFactoryReg;
        if (reg == null) {
            beanFactoryReg = bundleContext.registerService(BeanFactory.class.getName(), this, new Properties());
            log.info("All dependencies are satisfied. Registering the BeanFactory instance");
        }
    }
View Full Code Here

     * can use this to manage repository lifecycle. Default implementation de-registers the BeanFactory
     * instance. And repository creator service which then depends on BeanFactory reference would then be notified and
     * can react accordingly
     */
    protected void dependenciesUnSatisfied() {
        ServiceRegistration reg = beanFactoryReg;
        if (reg != null) {
            reg.unregister();
            beanFactoryReg = null;
            log.info("Dependencies unsatisfied. Deregistering the BeanFactory instance");
        }
    }
View Full Code Here

    private void unregisterStatistics(Repository repository) {
        if (repository instanceof RepositoryImpl) {
            String mbeanName = StatisticsMBeanImpl.getMBeanName((RepositoryImpl) repository);
            try {
                ServiceRegistration serviceRegistration = statisticsServices.get(mbeanName);
                if (serviceRegistration != null) {
                    serviceRegistration.unregister();
                }
            } catch (Exception e) {
                log.warn("Failed to unregister statistics JMX bean {} ", e.getMessage());
            }
            statisticsServices.remove(mbeanName);
View Full Code Here

    }

    @Test
    public void testOsgiResourceEvents() throws RepositoryException {
        final ResourceEventListener listener = new ResourceEventListener();
        final ServiceRegistration reg = listener.register(bundleContext, SlingConstants.TOPIC_RESOURCE_ADDED);
        final Session s = repository.loginAdministrative(null);
        final int nPaths = 2500 * TEST_SCALE;
        final int timeoutMsec = 2 * nPaths;
        final String prefix = uniqueName("testOsgiResourceEvents");

        // Create N nodes with a unique name under /
        // and verify that ResourceEventListener gets an event
        // for each of them
        try {
            for(int i=0; i  < nPaths; i++) {
                s.getRootNode().addNode(prefix + i);
            }
            s.save();

            log.info("Added {} nodes, checking what ResourceEventListener got...", nPaths);
            final long timeout = System.currentTimeMillis() + timeoutMsec;
            final Set<String> missing = new HashSet<String>();
            while(System.currentTimeMillis() < timeout) {
                missing.clear();
                final Set<String> paths = listener.getPaths();
                for(int i=0; i  < nPaths; i++) {
                    final String path = "/" + prefix + i;
                    if(!paths.contains(path)) {
                        missing.add(path);
                    }
                }

                if(missing.isEmpty()) {
                    break;
                }
            }

            if(!missing.isEmpty()) {
                final String missingStr = missing.size() > 10 ? missing.size() + " paths missing" : missing.toString();
                fail("OSGi add resource events are missing for "
                        + missing.size() + "/" + nPaths + " paths after "
                        + timeoutMsec + " msec: " + missingStr);
            }
        } finally {
            reg.unregister();
            s.logout();
        }
       
        log.info("Successfuly detected OSGi observation events for " + nPaths + " paths");
    }
View Full Code Here

            final Repository repo,
            final Map<String, Object> props) {
        logger.info("Providing new configuration printer for {} : {}", repo, props);
        final Long key = (Long)props.get(Constants.SERVICE_ID);
        final RepositoryPrinter printer = new RepositoryPrinter(repo, props);
        final ServiceRegistration reg = processContext.registerService(RepositoryPrinter.class.getName(),
                printer, printer.getProperties());
        synchronized ( this.registrations ) {
            this.registrations.put(key, reg);
        }
    }
View Full Code Here

    protected void unbindRepository(final Repository repo, final Map<String, Object> props) {
        synchronized ( pendingServices ) {
            this.pendingServices.remove(new PendingService(repo, props));
        }
        final Long key = (Long)props.get(Constants.SERVICE_ID);
        final ServiceRegistration reg;
        synchronized ( this.registrations ) {
            reg = this.registrations.remove(key);
        }
        if ( reg != null ) {
            reg.unregister();
        }
    }
View Full Code Here

        };
        ch.qos.logback.classic.Logger bar = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(loggers[0]);
        bar.setLevel(Level.INFO);

        props.put("loggers", loggers);
        ServiceRegistration sr = bundleContext.registerService(Appender.class.getName(), ta, props);

        delay();

        // Level should be INFO now
        assertEquals(java.util.logging.Level.INFO, julLogger.getLevel());
View Full Code Here

        config.put(RequestLoggerService.PARAM_FORMAT, format);
        config.put(RequestLoggerService.PARAM_OUTPUT, output);
        config.put(RequestLoggerService.PARAM_OUTPUT_TYPE, outputType);

        final RequestLoggerService service = new RequestLoggerService(bundleContext, config);
        final ServiceRegistration reg = bundleContext.registerService(service.getClass().getName(), service, config);
        services.put(reg, service);
    }
View Full Code Here

TOP

Related Classes of org.osgi.framework.ServiceRegistration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.