Search in sources :

Example 1 with HandlerFactory

use of org.apache.felix.ipojo.HandlerFactory in project felix by apache.

the class TestUpdatedMethodAndManagedService method setUp.

@Before
public void setUp() throws IOException {
    for (HandlerFactory handler : osgiHelper.getServiceObjects(HandlerFactory.class)) {
        System.out.println("handler : " + handler.getHandlerName() + " - " + handler.getState() + " - " + handler.getMissingHandlers());
    }
    String type = "CONFIG-FooProviderType-4Updated";
    Hashtable<String, String> p = new Hashtable<String, String>();
    p.put("instance.name", "instance");
    p.put("foo", "foo");
    p.put("bar", "2");
    p.put("baz", "baz");
    instance1 = ipojoHelper.createComponentInstance(type, p);
    System.out.println(instance1.getInstanceDescription().getDescription());
    assertEquals("instance1 created", ComponentInstance.VALID, instance1.getState());
    System.out.println(instance1.getInstanceDescription().getDescription());
    type = "CONFIG-FooProviderType-3Updated";
    Hashtable<String, String> p1 = new Hashtable<String, String>();
    p1.put("instance.name", "instance-2");
    p1.put("foo", "foo");
    p1.put("bar", "2");
    p1.put("baz", "baz");
    p1.put("managed.service.pid", "instance-managed-service");
    instance2 = ipojoHelper.createComponentInstance(type, p1);
    type = "CONFIG-FooProviderType-3Updated";
    Hashtable<String, String> p2 = new Hashtable<String, String>();
    p2.put("instance.name", "instance-3");
    p2.put("managed.service.pid", "instance-3");
    instance3 = ipojoHelper.createComponentInstance(type, p2);
}
Also used : HandlerFactory(org.apache.felix.ipojo.HandlerFactory) Hashtable(java.util.Hashtable) Before(org.junit.Before)

Example 2 with HandlerFactory

use of org.apache.felix.ipojo.HandlerFactory in project felix by apache.

the class Arch method handlers.

/**
 * Displays the list of available handlers.
 */
@Descriptor("Display iPOJO handlers")
public void handlers() {
    PrintStream out = System.out;
    for (HandlerFactory m_handler : m_handlers) {
        String name = m_handler.getHandlerName();
        if ("composite".equals(m_handler.getType())) {
            name = name + " [composite]";
        }
        if (m_handler.getMissingHandlers().size() == 0) {
            out.println("Handler " + name + " (VALID)");
        } else {
            out.println("Handler " + name + " (INVALID : " + m_handler.getMissingHandlers() + ")");
        }
    }
    for (TypeDeclaration type : m_types) {
        if (!type.getStatus().isBound()) {
            out.println("HandlerFactory " + type.getComponentName() + " is not bound");
            out.println("  -> " + type.getStatus().getMessage());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) HandlerFactory(org.apache.felix.ipojo.HandlerFactory) TypeDeclaration(org.apache.felix.ipojo.extender.TypeDeclaration) Descriptor(org.apache.felix.service.command.Descriptor)

Example 3 with HandlerFactory

use of org.apache.felix.ipojo.HandlerFactory in project felix by apache.

the class IPOJOPlugin method getAllHandlers.

/**
 * Writes the JSON object containing the info for all handlers.
 * @param pw the writer when the json object is printed
 * @throws IOException the JSON object cannot be written
 */
private void getAllHandlers(JSONWriter pw) throws IOException {
    pw.object();
    // Statline:
    pw.key("count");
    pw.value(m_handlers.size());
    pw.key("valid_count");
    pw.value(StateUtils.getValidHandlersCount(m_handlers));
    pw.key("invalid_count");
    pw.value(StateUtils.getInvalidHandlersCount(m_handlers));
    // End statline
    pw.key("data");
    pw.array();
    for (HandlerFactory factory : m_handlers) {
        String version = factory.getVersion();
        String name = factory.getHandlerName();
        String state = StateUtils.getFactoryState(factory.getState());
        String bundle = factory.getBundleContext().getBundle().getSymbolicName() + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
        pw.object();
        pw.key("name");
        pw.value(name);
        if (version != null) {
            pw.key("version");
            pw.value(version);
        }
        pw.key("bundle");
        pw.value(bundle);
        pw.key("state");
        pw.value(state);
        pw.key("type");
        pw.value(factory.getType());
        if (!factory.getMissingHandlers().isEmpty()) {
            pw.key("missing");
            pw.value(factory.getMissingHandlers().toString());
        }
        pw.endObject();
    }
    pw.endArray();
    pw.endObject();
}
Also used : HandlerFactory(org.apache.felix.ipojo.HandlerFactory)

Example 4 with HandlerFactory

use of org.apache.felix.ipojo.HandlerFactory in project felix by apache.

the class TestHandlerBindingAndIgnoreAnnotation method testFooHandlerBinding.

@Test
public void testFooHandlerBinding() {
    /*
        HandlerFactory handlerFactory = ipojoHelper.getHandlerFactory("com.acme:foo");
        assertNotNull(handlerFactory);
        assertEquals(Factory.VALID, handlerFactory.getState());
*/
    // verify component's factory is here
    // verify BazService has been published
    // --> verify instance has been created
    Factory factory = ipojoHelper.getFactory(FACTORY_NAME);
    assertNotNull(factory);
    assertEquals(Factory.VALID, factory.getState());
    List<HandlerBindingTestService> services = osgiHelper.getServiceObjects(HandlerBindingTestService.class);
    assertEquals(1, services.size());
    HandlerBindingTestService baz = services.get(0);
    assertEquals("Bonjour", baz.get("greeting"));
    assertEquals("Welcome", baz.get("welcome"));
    assertNull(baz.get("ignored"));
    ipojoHelper.dispose();
}
Also used : HandlerBindingTestService(org.apache.felix.ipojo.runtime.core.services.HandlerBindingTestService) Factory(org.apache.felix.ipojo.Factory) HandlerFactory(org.apache.felix.ipojo.HandlerFactory) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Aggregations

HandlerFactory (org.apache.felix.ipojo.HandlerFactory)4 PrintStream (java.io.PrintStream)1 Hashtable (java.util.Hashtable)1 Factory (org.apache.felix.ipojo.Factory)1 TypeDeclaration (org.apache.felix.ipojo.extender.TypeDeclaration)1 HandlerBindingTestService (org.apache.felix.ipojo.runtime.core.services.HandlerBindingTestService)1 Descriptor (org.apache.felix.service.command.Descriptor)1 Before (org.junit.Before)1 Test (org.junit.Test)1 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)1