Package org.osgi.framework

Examples of org.osgi.framework.ServiceRegistration


        // register a service with PID
        String pid = "testAfterCreation";
        MockManagedService service = new MockManagedService();
        Dictionary props = new Hashtable();
        props.put( Constants.SERVICE_PID, pid );
        ServiceRegistration sr = bundleContext.registerService( ManagedService.class.getName(), service, props );

        // locales should contain MockMetaTypeProvider.LOCALES
        assertNotNull( mti.getLocales() );
        assertTrue( mti.getLocales().length == 1 );
        assertEquals( MockMetaTypeProvider.LOCALES[0], mti.getLocales()[0] );

        // pids must contain pid
        assertNotNull( mti.getPids() );
        assertTrue( mti.getPids().length == 1 );
        assertEquals( pid, mti.getPids()[0] );

        // change the service PID
        String pid2 = "testAfterCreation2";
        Dictionary props2 = new Hashtable();
        props2.put( Constants.SERVICE_PID, pid2 );
        sr.setProperties( props2 );

        // pids must contain pid2
        assertNotNull( mti.getPids() );
        assertTrue( mti.getPids().length == 1 );
        assertEquals( pid2, mti.getPids()[0] );

        // factoryPids must be empty
        assertTrue( mti.getFactoryPids() == null || mti.getFactoryPids().length == 0 );

        // unregister the service
        sr.unregister();

        // ensure everything is clear now again
        checkEmpty( mti );
    }
View Full Code Here


        // register a service with PID
        String factoryPid = "testAfterCreation_factory";
        MockManagedServiceFactory service = new MockManagedServiceFactory();
        Dictionary props = new Hashtable();
        props.put( Constants.SERVICE_PID, factoryPid );
        ServiceRegistration sr = bundleContext.registerService( ManagedServiceFactory.class.getName(), service, props );

        // locales should contain MockMetaTypeProvider.LOCALES
        assertNotNull( mti.getLocales() );
        assertTrue( mti.getLocales().length == 1 );
        assertEquals( MockMetaTypeProvider.LOCALES[0], mti.getLocales()[0] );

        // pids must be empty
        assertTrue( mti.getPids() == null || mti.getPids().length == 0 );

        // pids must contain pid
        assertNotNull( mti.getFactoryPids() );
        assertTrue( mti.getFactoryPids().length == 1 );
        assertEquals( factoryPid, mti.getFactoryPids()[0] );

        // change the service PID
        String factoryPid2 = "testAfterCreation2";
        Dictionary props2 = new Hashtable();
        props2.put( Constants.SERVICE_PID, factoryPid2 );
        sr.setProperties( props2 );

        // pids must contain pid2
        assertNotNull( mti.getFactoryPids() );
        assertTrue( mti.getFactoryPids().length == 1 );
        assertEquals( factoryPid2, mti.getFactoryPids()[0] );

        // unregister the service
        sr.unregister();

        // ensure everything is clear now again
        checkEmpty( mti );
    }
View Full Code Here

        {
            // remove service
            plugin.unregister();
            this.plugin = null;
            // unregister configuration printer too
            ServiceRegistration reg = printerRegistration;
            if (reg != null)
            {
                reg.unregister();
                printerRegistration = null;
            }
            // unregister info provider too
            reg = infoRegistration;
            if (reg != null)
            {
                reg.unregister();
                infoRegistration = null;
            }
        }

    }
View Full Code Here

                {
                    postEvent(WebEvent.UNDEPLOYING(webAppBundle, extenderBundle));

                    context.getServletContext().removeAttribute(OSGI_BUNDLE_CONTEXT);

                    ServiceRegistration registration = deployment.getRegistration();
                    if (registration != null)
                    {
                        registration.unregister();
                    }
                    deployment.setRegistration(null);
                    deployment.setContext(null);
                    context.stop();
                }
View Full Code Here

            }

            Hashtable props = new Hashtable<String, String>();
            props.put(URLConstants.URL_HANDLER_PROTOCOL, "test" + System.identityHashCode(TestURLHandlersActivator.this));

            ServiceRegistration reg = context.registerService(URLStreamHandlerService.class, this, props);

            new URL("test" + System.identityHashCode(TestURLHandlersActivator.this) + ":").openConnection();

            reg.unregister();

            try
            {
                new URL("test" + System.identityHashCode(TestURLHandlersActivator.this) + ":").openConnection();
                throw new Exception("Unexpected url resolve");
View Full Code Here

            {
                public void run()
                {
                    try
                    {
                        ServiceRegistration sr = m_registrations.remove( clazz );
                        sr.unregister();
                        m_disabledLatch.countDown();
                    }
                    catch ( Throwable e )
                    {
                        m_logService.log( LogService.LOG_ERROR, "error while enabling " + clazz, e );
View Full Code Here

                        public void run()
                        {
                            Hashtable props = new Hashtable();
                            props.put(Constants.SERVICE_PID, pid);

                            ServiceRegistration sr = bundleContext.registerService(
                                ManagedService.class.getName(),
                                new TestManagedService(managedServiceUpdated), props);
                            managedServices.add(sr);
                            try
                            {
                                Configuration c = ca.getConfiguration(pid, null);
                                c.update(new Hashtable()
                                {
                                    {
                                        put("foo", "bar");
                                    }
                                });
                                confs.add(c);
                            }
                            catch (IOException e)
                            {
                                log.error("could not create pid %s", e, pid);
                                return;
                            }
                        }
                    });
                }

                if (!managedServiceUpdated.await(MAXWAIT, TimeUnit.MILLISECONDS))
                {
                    TestCase.fail("Detected errors logged during concurrent test");
                    break;
                }
                log.info("all managed services updated");

                // Unregister managed services concurrently
                log.info("unregistering services concurrently");
                for (final ServiceRegistration sr : managedServices)
                {
                    executor.execute(new Runnable()
                    {
                        public void run()
                        {
                            sr.unregister();
                            managedServiceUnregistered.countDown();
                        }
                    });
                }
View Full Code Here

    }


    public void drop()
    {
        ServiceRegistration sr = getRegistration();
        if ( sr != null )
        {
            setRegistration( null );
            sr.unregister();
        }
    }
View Full Code Here

    }


    public SimpleServiceImpl drop()
    {
        ServiceRegistration sr = getRegistration();
        if ( sr != null )
        {
            setRegistration( null );
            sr.unregister();
        }
        return this;
    }
View Full Code Here

        {
            // remove service
            plugin.unregister();
            this.plugin = null;
            // unregister configuration printer too
            ServiceRegistration reg = printerRegistration;
            if (reg != null)
            {
                reg.unregister();
                printerRegistration = null;
            }
        }

    }
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.