Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ComponentInstance


     * annotations and with the brand new JMX handler syntax.
     */
    @Test
    public void testMBeanWithoutAnnotations() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ListenerNotFoundException, ReflectionException, MBeanException {
        // Create an instance of the component
        ComponentInstance componentInstance = ipojoHelper
                .createComponentInstance("org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponent");
        String instanceName = componentInstance.getInstanceName();
        ObjectName objectName = new ObjectName(
                "org.apache.felix.ipojo.handler.jmx.components:type=org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponent,instance="
                        + instanceName);
        doTest(objectName);
    }
View Full Code Here


     * annotations and with the deprecated JMX handler syntax.
     */
    @Test
    public void testMBeanWithoutAnnotationsDeprecated() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ListenerNotFoundException, ReflectionException, MBeanException {
        // Create an instance of the component
        ComponentInstance componentInstance = ipojoHelper
                .createComponentInstance("org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentDeprecated");
        String instanceName = componentInstance.getInstanceName();
        ObjectName objectName = new ObjectName(
                "org.apache.felix.ipojo.handler.jmx.components:type=org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponent,instance="
                        + instanceName);
        doTest(objectName);
    }
View Full Code Here

    @Test
    public void testMBeanWithAnnotations() throws MalformedObjectNameException, IntrospectionException,
            InstanceNotFoundException, ListenerNotFoundException,
            ReflectionException, MBeanException {
        // Create an instance of the component
        ComponentInstance componentInstance = ipojoHelper
                .createComponentInstance("org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentAnnotated");
        String instanceName = componentInstance.getInstanceName();
        ObjectName objectName = new ObjectName(
                "org.apache.felix.ipojo.handler.jmx.components:type=org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentAnnotated,instance="
                        + instanceName);
        doTest(objectName);
    }
View Full Code Here

    @Test
    public void testMBeanWithAnnotationsDeprecated() throws MalformedObjectNameException, IntrospectionException,
            InstanceNotFoundException, ListenerNotFoundException,
            ReflectionException, MBeanException {
        // Create an instance of the component
        ComponentInstance componentInstance = ipojoHelper
                .createComponentInstance("org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentAnnotatedDeprecated");
        String instanceName = componentInstance.getInstanceName();
        ObjectName objectName = new ObjectName(
                "org.apache.felix.ipojo.handler.jmx.components:type=org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentAnnotatedDeprecated,instance="
                        + instanceName);
        doTest(objectName);
    }
View Full Code Here

        // Create the donut consumer instance, listening on a pattern topic
        properties.put("instance.name", "subscriber with pattern topic");
        topics.put("donut-subscriber", "a/pattern/topic/*");
        properties.put("event.topics", topics);

        ComponentInstance instance = m_utils.getDonutConsumerFactory()
                .createComponentInstance(properties);
        instance.dispose();
    }
View Full Code Here

        // Create the donut consumer instance, listening on a pattern topic
        properties.put("instance.name", "subscriber with pattern topic");
        topics.put("donut-subscriber", "a/pattern/topic/*");
        properties.put("event.topics", topics);

        ComponentInstance instance = m_utils.getDonutConsumerFactory()
                .createComponentInstance(properties);
        instance.dispose();
    }
View Full Code Here

        // Create the donut consumer instance, listening on a pattern topic
        properties.put("instance.name", "subscriber with pattern topic");
        topics.put("donut-subscriber", "a/pattern/topic/*");
        properties.put("event.topics", topics);

        ComponentInstance instance = m_utils.getDonutConsumer2Factory()
                .createComponentInstance(properties);
        instance.dispose();
    }
View Full Code Here

        Factory fact = ipojoHelper.getFactory(factName);
        assertNotNull("Cannot find the factory FooProvider-1", fact);

        Properties props = new Properties();
        props.put("instance.name", compName);
        ComponentInstance ci = null;
        try {
            ci = fact.createComponentInstance(props);
        } catch (Exception e1) {
            fail(e1.getMessage());
        }

        assertEquals("Check instance name", compName, ci.getInstanceName());

        // Get a FooService provider
        ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), compName);

        assertNotNull("FS not available", ref);

        // Get foo object
        FooService fs = (FooService) osgiHelper.getServiceObject(ref);

        // Cast to POJO
        Pojo pojo = (Pojo) fs;
        Field im = fs.getClass().getDeclaredField("__IM");
        assertNotNull(im);
        im.setAccessible(true);
        assertNotNull(im.get(fs));

        Method method = fs.getClass().getMethod("getComponentInstance");
        assertNotNull(method);

        // GetComponentInstance
        ComponentInstance instance = pojo.getComponentInstance();
        assertNotNull(instance);
        assertEquals("Check component instance name", instance.getInstanceName(), compName);
        assertEquals("Check component factory name", instance.getFactory().getName(), factName);
        assertNotNull("Instance description not null", instance.getInstanceDescription());
        PrimitiveInstanceDescription id = (PrimitiveInstanceDescription) instance.getInstanceDescription();
        assertTrue("Check instance state", id.getState() == ComponentInstance.VALID);
        assertEquals("Check created pojo count", id.getCreatedObjects().length, 1);
        assertEquals("Check instance description name", id.getName(), compName);

        ci.dispose();
View Full Code Here

    PrimitiveManipulationTestService prim;

    @Before
    public void setUp() {
        ComponentInstance instance =
                ipojoHelper.createComponentInstance("ManipulationPrimitives-PrimitiveManipulationTesterA");
        assertTrue("check instance state", instance.getState() == ComponentInstance.VALID);
        ServiceReference ref = ipojoHelper.getServiceReferenceByName(PrimitiveManipulationTestService.class.getName(),
                instance.getInstanceName());
        assertNotNull("Check prim availability", ref);
        prim = (PrimitiveManipulationTestService) osgiHelper.getServiceObject(ref);
    }
View Full Code Here

                ));
    }

    @Test
    public void testInvalidation() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
        final ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
        ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");

        Assert.assertEquals(ComponentInstance.VALID, prov.getState());
        Assert.assertEquals(ComponentInstance.VALID, under.getState());

        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
        Assert.assertNotNull(ref);

        osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
        TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);

        Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                prov.dispose();
            }
        });

        thread.start();

        tm.begin();
        Transaction t = tm.getTransaction();
        cs.doSomethingLong(); // 5s, so prov should be disposed during this time and under becomes invalid

        Assert.assertEquals(ComponentInstance.INVALID, under.getState());

        Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());

        t.rollback();
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.ComponentInstance

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.