Package org.osgi.service.component

Examples of org.osgi.service.component.ComponentContext


                }
            }
        };
        ctxA.addServiceListener(listener);

        ComponentContext ccA1 = srvA.getServiceA1().getComponentContext();
        ccA1.disableComponent(ServiceA1.class.getName());

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));

        ServiceReference<ServiceA> srefA = ctxA.getServiceReference(ServiceA.class);
        Assert.assertNull("ServiceReference null", srefA);
View Full Code Here


     * @throws ConfigurationException
     */
    @Test
    public void testEngine() throws EngineException, IOException, ConfigurationException {
        LangIdEnhancementEngine langIdEngine = new LangIdEnhancementEngine();
        ComponentContext context =  new MockComponentContext();
        context.getProperties().put(EnhancementEngine.PROPERTY_NAME, "langid");
        langIdEngine.activate(context);
        ContentItem ci = ciFactory.createContentItem(new StringSource(text));
        langIdEngine.computeEnhancements(ci);
        HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
View Full Code Here

        InputStream in = LanguageDetectionEngineTest.class.getClassLoader().getResourceAsStream(TEST_FILE_NAMES[0]);
        assertNotNull("failed to load resource " + TEST_FILE_NAMES[0], in);
        String text = IOUtils.toString(in, "UTF-8");
        in.close();
        LanguageDetectionEnhancementEngine langIdEngine = new LanguageDetectionEnhancementEngine();
        ComponentContext context =  new MockComponentContext();
        context.getProperties().put(EnhancementEngine.PROPERTY_NAME, "langdetect");
        langIdEngine.activate(context);
        ContentItem ci = ciFactory.createContentItem(new StringSource(text));
        langIdEngine.computeEnhancements(ci);
        HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
View Full Code Here

            // FABRIC-1052: register listener using the same bundle context that is used for listeners related to SCR
            bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, filter);

            // Disable the BootstrapConfiguration component
            LOGGER.debug("Disable BootstrapConfiguration");
            ComponentContext componentContext = bootConfig.getComponentContext();
            componentContext.disableComponent(BootstrapConfiguration.COMPONENT_NAME);

            if (!unregisterLatch.await(30, TimeUnit.SECONDS))
                throw new TimeoutException("Timeout for unregistering BootstrapConfiguration service");

            // Do the cleanup
            runtimeProps.clearRuntimeAttributes();
            cleanConfigurations(configs);
            cleanZookeeperDirectory(karafData);
            cleanGitDirectory(karafData);

            // Setup the registration listener for the new {@link BootstrapConfiguration}
            final CountDownLatch registerLatch = new CountDownLatch(1);
            final AtomicReference<ServiceReference<?>> sref = new AtomicReference<ServiceReference<?>>();
            listener = new ServiceListener() {
                @Override
                public void serviceChanged(ServiceEvent event) {
                    if (event.getType() == ServiceEvent.REGISTERED) {
                        LOGGER.debug("Registered BootstrapConfiguration");
                        syscontext.removeServiceListener(this);
                        sref.set(event.getServiceReference());
                        registerLatch.countDown();
                    }
                }
            };
            syscontext.addServiceListener(listener, "(objectClass=" + BootstrapConfiguration.class.getName() + ")");

            // Enable the {@link BootstrapConfiguration} component and await the registration of the respective service
            LOGGER.debug("Enable BootstrapConfiguration");
            componentContext.enableComponent(BootstrapConfiguration.COMPONENT_NAME);
            if (!registerLatch.await(30, TimeUnit.SECONDS))
                throw new TimeoutException("Timeout for registering BootstrapConfiguration service");

            return (BootstrapConfiguration) syscontext.getService(sref.get());
View Full Code Here

    }

    @Override
    public Object addingService(ServiceReference reference) {
        invalidateExecutionPlan();
        ComponentContext context = this.context;
        if(context != null){
            return context.getBundleContext().getService(reference);
        } else {
            log.warn("Unable to get EnhancementEngine for Reference {} because" +
                "this {} seams already be deactivated -> return null",
                reference.getProperty(EnhancementEngine.PROPERTY_NAME),
                toString());
View Full Code Here

    }

    @Override
    public void removedService(ServiceReference reference, Object service) {
        invalidateExecutionPlan();
        ComponentContext context = this.context;
        if(context != null){
            context.getBundleContext().ungetService(reference);
        }
    }
View Full Code Here

   
    @BeforeClass
    public static final void init() throws ConfigurationException {
        Dictionary<String,Object> config = new Hashtable<String,Object>();
        config.put(LabelTokenizer.SUPPORTED_LANUAGES, "*");
        ComponentContext cc = new MockComponentContext(config);
        tokenizer = new OpenNlpLabelTokenizer();
        tokenizer.openNlp = new OpenNLP(new ClasspathDataFileProvider(null));
        tokenizer.activate(cc);
    }
View Full Code Here

            Activator.initPaodingDictionary(paodingDict, PaodingLabelTokenizerTest.class.
                getClassLoader().getResourceAsStream(Activator.DICT_ARCHIVE));
        }
        Activator.initPaodingDictHomeProperty(paodingDict);
        Dictionary<String,Object> config = new Hashtable<String,Object>();
        ComponentContext cc = new MockComponentContext(config);
        labelTokenizer = new PaodingLabelTokenizer();
        labelTokenizer.activate(cc);
    }
View Full Code Here

    public static void init() throws ConfigurationException {
        Dictionary<String,Object> config = new Hashtable<String,Object>();
        config.put(LuceneLabelTokenizer.PROPERTY_TOKENIZER_FACTORY, TOKENIZER_FACTORY_CLASS);
        config.put(LuceneLabelTokenizer.PROPERTY_TOKEN_FILTER_FACTORY,TOKEN_FILTER_FACTORY_CLASSES);
        config.put(LabelTokenizer.SUPPORTED_LANUAGES, "zh");
        ComponentContext cc = new MockComponentContext(config);
        luceneLabelTokenizer = new LuceneLabelTokenizer();
        luceneLabelTokenizer.activate(cc);
    }
View Full Code Here

    @BeforeClass
    public static void init() throws ConfigurationException {
        Dictionary<String,Object> config = new Hashtable<String,Object>();
        config.put(LuceneLabelTokenizer.PROPERTY_TOKENIZER_FACTORY, TOKENIZER_FACTORY_CLASS);
        config.put(LabelTokenizer.SUPPORTED_LANUAGES, "en");
        ComponentContext cc = new MockComponentContext(config);
        luceneLabelTokenizer = new LuceneLabelTokenizer();
        luceneLabelTokenizer.activate(cc);
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.component.ComponentContext

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.