Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ServiceContext


            fail("Fail to instantiate the foo2 component " + e.getMessage());
        }

        // The foo service is available => import1 must be valid
        assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import3);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // Stop the second provider
        foo2.dispose();
        assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import3);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 2", refs);
        assertEquals("Test foo availability inside the composite - 2.1 (" + refs.length + ")", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // stop the foo provider
        foo.stop();

        // No provider -> Invalid
        assertTrue("Test component invalidity - 2", import3.getState() == ComponentInstance.VALID);

        foo.start();
        assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import3);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo.dispose();
        // No provider -> Invalid
        assertTrue("Test component invalidity - 3", import3.getState() == ComponentInstance.VALID);
    }
View Full Code Here


            fail("Fail to instantiate the foo2 component " + e.getMessage());
        }

        // The foo service is available => import1 must be valid
        assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import3);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // Stop the second provider
        foo1.stop();
        assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import3);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 2", refs);
        assertEquals("Test foo availability inside the composite - 2.1 (" + refs.length + ")", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // stop the foo provider
        foo2.dispose();

        // No provider -> Invalid
        assertTrue("Test component invalidity - 2", import3.getState() == ComponentInstance.VALID);

        foo1.start();
        assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import3);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo1.dispose();
        // No provider -> Invalid
        assertTrue("Test component invalidity - 3", import3.getState() == ComponentInstance.VALID);
    }
View Full Code Here

            fail("Fail to instantiate the foo2 component " + e.getMessage());
        }

        // The foo service is available => import1 must be valid
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import2);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2 (" + refs.length + ")", refs.length, 2);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        FooService fs2 = (FooService) sc.getService(refs[1]);
        assertTrue("Test foo invocation", fs2.foo());
        sc.ungetService(refs[0]);
        sc.ungetService(refs[1]);

        // Stop the second provider
        foo2.dispose();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 2", refs);
        assertEquals("Test foo availability inside the composite - 2.1 (" + refs.length + ")", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // stop the foo provider
        foo.stop();

        // No provider -> Invalid
        assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);

        foo.start();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo.dispose();
        // No provider -> Invalid
        assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.INVALID);
    }
View Full Code Here

            fail("Fail to instantiate the foo2 component " + e.getMessage());
        }

        // The foo service is available => import1 must be valid
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import2);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2 (" + refs.length + ")", refs.length, 2);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        FooService fs2 = (FooService) sc.getService(refs[1]);
        assertTrue("Test foo invocation", fs2.foo());
        sc.ungetService(refs[0]);
        sc.ungetService(refs[1]);

        // Stop the first provider
        foo1.stop();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 2", refs);
        assertEquals("Test foo availability inside the composite - 2.1 (" + refs.length + ")", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // stop the second foo provider
        foo2.dispose();

        // No provider -> Invalid
        assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);

        foo1.start();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo1.dispose();
        // No provider -> Invalid
        assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.INVALID);
    }
View Full Code Here

            fail("Fail to instantiate the foo2 component " + e.getMessage());
        }

        // The foo service is available => import1 must be valid
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import2);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2 (" + refs.length + ")", refs.length, 2);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        FooService fs2 = (FooService) sc.getService(refs[1]);
        assertTrue("Test foo invocation", fs2.foo());
        sc.ungetService(refs[0]);
        sc.ungetService(refs[1]);

        // Stop the second provider
        foo2.dispose();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 2", refs);
        assertEquals("Test foo availability inside the composite - 2.1 (" + refs.length + ")", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // stop the foo provider
        foo.stop();

        // No provider -> valid
        assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);

        foo.start();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo.dispose();
        // No provider -> Invalid
        assertTrue("Test component validity - 3", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
View Full Code Here

            fail("Fail to instantiate the foo2 component " + e.getMessage());
        }

        // The foo service is available => import1 must be valid
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import2);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2 (" + refs.length + ")", refs.length, 2);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        FooService fs2 = (FooService) sc.getService(refs[1]);
        assertTrue("Test foo invocation", fs2.foo());
        sc.ungetService(refs[0]);
        sc.ungetService(refs[1]);

        // Stop the first provider
        foo1.stop();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 2", refs);
        assertEquals("Test foo availability inside the composite - 2.1 (" + refs.length + ")", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // stop the second foo provider
        foo2.dispose();

        // No provider -> Invalid
        assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);

        foo1.start();
        assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo1.dispose();
        // No provider -> Invalid
        assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import2);
View Full Code Here

    @Test
    public void testSimple() {
        import1.start();
        //Two providers
        assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import1);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo1.stop();
        assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import1);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        // Stop the second provider
        foo2.stop();
        assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);

        foo2.start();
        assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import1);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);
    }
View Full Code Here

    @Ignore("known as broken after interception inception in service dependencies")
    public void testSimple2() {
        import1.start();
        //Two providers
        assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(import1);
        ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 1", refs);
        assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
        FooService fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);

        foo2.stop();
        assertTrue("Test component invalidity - 1", import1.getState() == ComponentInstance.INVALID);

        // Stop the second provider
        foo1.stop();
        assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);

        foo1.start();
        assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);

        foo2.start();
        assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
        sc = getServiceContext(import1);
        refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
        assertNotNull("Test foo availability inside the composite - 3", refs);
        assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
        fs = (FooService) sc.getService(refs[0]);
        assertTrue("Test foo invocation", fs.foo());
        sc.ungetService(refs[0]);
    }
View Full Code Here

     * This list contains only instances who exposed their architecture.
     * @return the list of contained instances.
     */
    public InstanceDescription[] getContainedInstances() {
        // Get instances description of internal instance
        ServiceContext internal = ((CompositeManager) m_instance).getServiceContext();
        try {
            ServiceReference[] refs = internal.getServiceReferences(Architecture.class.getName(), null);
            if (refs != null) {
                InstanceDescription[] desc = new InstanceDescription[refs.length];
                for (int i = 0; i < refs.length; i++) {
                    Architecture arch = (Architecture) internal.getService(refs[i]);
                    desc[i] = arch.getInstanceDescription();
                    internal.ungetService(refs[i]);
                }
                return desc;
            }
        } catch (InvalidSyntaxException e) {
            // Cannot happen
View Full Code Here

     * Gets the list of internally published services.
     * @return the list of published services.
     */
    public Element getInternalServices() {
        Element services = new Element("services", "");
        ServiceContext internal = ((CompositeManager) m_instance)
                .getServiceContext();
        try {
            ServiceReference[] refs = internal.getServiceReferences((String) null, "(!(objectclass=" + Factory.class
                    .getName() + "))");
            for (int i = 0; refs != null && i < refs.length; i++) {
                Element svc = new Element("service", "");
                String[] keys = refs[i].getPropertyKeys();
                for (int j = 0; j < keys.length; j++) {
View Full Code Here

TOP

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

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.