Search in sources :

Example 1 with FooService

use of org.apache.felix.ipojo.handler.temporal.services.FooService in project felix by apache.

the class CollectionCheckServiceProviderHelper method check.

public boolean check() {
    boolean result = true;
    // Use a local variable to avoid to wait at each access.
    Collection col = fs;
    if (col != null) {
        // Get the cached copy
        Iterator it = col.iterator();
        while (it != null && it.hasNext()) {
            FooService svc = (FooService) it.next();
            result = result && svc.foo();
        }
    }
    return result;
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 2 with FooService

use of org.apache.felix.ipojo.handler.temporal.services.FooService in project felix by apache.

the class TemporalTest method testDelay.

@Test
public void testDelay() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProviderUsingTemporal", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    assertNull("No FooService", osgiHelper.getServiceReference(FooService.class.getName(), null));
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider, 200);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    assertTrue("Assert delay (" + (end - begin) + ")", (end - begin) >= 200);
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 3", ref_cs);
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 3", cs.check());
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with FooService

use of org.apache.felix.ipojo.handler.temporal.services.FooService in project felix by apache.

the class CollectionCheckServiceProvider method check.

public boolean check() {
    boolean result = true;
    // Use a local variable to avoid to wait at each access.
    Collection col = fs;
    if (col != null) {
        Iterator it = col.iterator();
        while (it.hasNext()) {
            FooService svc = (FooService) it.next();
            result = result && svc.foo();
        }
    }
    return result;
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 4 with FooService

use of org.apache.felix.ipojo.handler.temporal.services.FooService in project felix by apache.

the class DelayTest method testDelay.

@Test
public void testDelay() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProvider", un);
    ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
    assertNotNull("Check foo availability", ref_fs);
    ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability", ref_cs);
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation", cs.check());
    // Stop the provider.
    provider.stop();
    assertNull("No FooService", osgiHelper.getServiceReference(FooService.class.getName(), null));
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 2", ref_cs);
    long begin = System.currentTimeMillis();
    DelayedProvider dp = new DelayedProvider(provider, 200);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 2", cs.check());
    long end = System.currentTimeMillis();
    assertTrue("Assert delay (" + (end - begin) + ")", (end - begin) >= 200);
    ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
    assertNotNull("Check cs availability - 3", ref_cs);
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    assertTrue("Check invocation - 3", cs.check());
    provider.stop();
    provider.dispose();
    under.stop();
    under.dispose();
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)4 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)2 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)2 Test (org.junit.Test)2 ServiceReference (org.osgi.framework.ServiceReference)2