Package org.apache.felix.dm.tracker

Examples of org.apache.felix.dm.tracker.ServiceTracker


        // Make sure we don't reuse old latches...
        m_latch = null;
    }

    private void configureService(final String pid, Properties props) throws Exception {
        ServiceTracker tracker = new ServiceTracker(m_context, ConfigurationAdmin.class.getName(), null);
        tracker.open();

        ServiceRegistration reg = null;

        try {
            ConfigurationAdmin configAdmin = (ConfigurationAdmin) tracker.waitForService(TimeUnit.SECONDS.toMillis(5));
            assertNotNull("No configuration admin service found?!", configAdmin);

            final CountDownLatch latch = new CountDownLatch(1);
            final int configEvent = (props != null) ? ConfigurationEvent.CM_UPDATED : ConfigurationEvent.CM_DELETED;

            Configuration config = configAdmin.getConfiguration(pid, null);

            reg = m_context.registerService(ConfigurationListener.class.getName(), new ConfigurationListener() {
                @Override
                public void configurationEvent(ConfigurationEvent event) {
                    if (pid.equals(event.getPid()) && event.getType() == configEvent) {
                        // NOTE: this is delivered asynchronously, so it might well be that we receive the event before the configuration is actually updated...
                        try {
                            TimeUnit.MILLISECONDS.sleep(50);
                        } catch (InterruptedException exception) {
                            Thread.currentThread().interrupt();
                        }
                       
                        latch.countDown();
                    }
                }
            }, null);

            if (props != null) {
                config.update(props);
            } else {
                config.delete();
            }

            assertTrue("Configuration not provisioned in time!", latch.await(5, TimeUnit.SECONDS));
        } finally {
            if (reg != null) {
                reg.unregister();
            }

            tracker.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.dm.tracker.ServiceTracker

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.