Package org.osgi.service.cm

Examples of org.osgi.service.cm.ManagedServiceFactory


    reconf.put("int", new Integer(5));
    reconf.put("long", new Long(43));
    reconf.put("string", new String("toto"));
    reconf.put("strAProp", new String[] {"foo", "baz"});
    reconf.put("intAProp", new int[] {3, 2, 1});
    ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
    try {
      fact.updated("FooProvider-2", reconf);
    } catch (ConfigurationException e) {
      fail("Configuration non acceptable : " + reconf);
    }
   
    // Check service properties after the reconfiguration
View Full Code Here


      if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
    }
   
    // Reconfiguration
    ServiceReference fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
    ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
    Properties p3 = new Properties();
    p3.put("int", new Integer(1));
    p3.put("boolean", new Boolean(true));
    p3.put("string", new String("foo"));
    p3.put("strAProp", new String[] {"foo", "bar", "baz"});
    p3.put("intAProp", new int[] { 1, 2, 3});
    try {
      fact.updated("FooProvider-3", p3);
    } catch (ConfigurationException e) {
      fail("Unable to reconfigure the instance with : " + p3);
    }
   
    sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
   
    // Check service properties
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
   
    assertEquals("Check intProp equality", intProp, new Integer(1));
    assertEquals("Check longProp equality", boolProp, new Boolean(true));
    assertEquals("Check strProp equality", strProp, new String("foo"));
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] {"foo", "bar", "baz"};
    for (int i = 0; i < strAProp.length; i++) {
      if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    v2 = new int[] { 1, 2, 3};
    for (int i = 0; i < intAProp.length; i++) {
      if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
    } 
   
    // Invoke
    FooService fs = (FooService) getServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
   
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
   
    assertEquals("Check intProp equality", intProp, new Integer(2));
    assertEquals("Check longProp equality", boolProp, new Boolean(true));
    assertEquals("Check strProp equality", strProp, new String("foo"));
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] {"foo", "bar"};
    for (int i = 0; i < strAProp.length; i++) {
      if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
    }
    assertNull("Check intAProp hidding (no value)", intAProp);
   
    //  Reconfiguration
    fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
    fact = (ManagedServiceFactory) getServiceObject(fact_ref);
    p3 = new Properties();
    p3.put("int", new Integer(1));
    p3.put("boolean", new Boolean(true));
    p3.put("string", new String("foo"));
    p3.put("strAProp", new String[] {"foo", "bar", "baz"});
    p3.put("intAProp", new int[] { 1, 2, 3});
    try {
      fact.updated("FooProvider-3", p3);
    } catch (ConfigurationException e) {
      fail("Unable to reconfigure the instance with : " + p3);
    }
   
    sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
View Full Code Here

        if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
      }
     
      // Reconfiguration
      ServiceReference fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
      ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
      Properties p3 = new Properties();
      p3.put("int", "1");
      p3.put("boolean", "true");
      p3.put("string", "foo");
      p3.put("strAProp", "{foo, bar, baz}");
      p3.put("intAProp", "{ 1, 2, 3}");
      try {
        fact.updated("FooProvider-3", p3);
      } catch (ConfigurationException e) {
        fail("Unable to reconfigure the instance with : " + p3);
      }
     
      sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
      assertNotNull("Check the availability of the FS service", sr);
     
      // Check service properties
      intProp = (Integer) sr.getProperty("int");
      boolProp = (Boolean) sr.getProperty("boolean");
      strProp = (String) sr.getProperty("string");
      strAProp = (String[]) sr.getProperty("strAProp");
      intAProp = (int[]) sr.getProperty("intAProp");
     
      assertEquals("Check intProp equality", intProp, new Integer(1));
      assertEquals("Check longProp equality", boolProp, new Boolean(true));
      assertEquals("Check strProp equality", strProp, new String("foo"));
      assertNotNull("Check strAProp not nullity", strAProp);
      v = new String[] {"foo", "bar", "baz"};
      for (int i = 0; i < strAProp.length; i++) {
        if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
      }
      assertNotNull("Check intAProp not nullity", intAProp);
      v2 = new int[] { 1, 2, 3};
      for (int i = 0; i < intAProp.length; i++) {
        if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
      } 
     
      // Invoke
      FooService fs = (FooService) getServiceObject(sr);
      assertTrue("invoke fs", fs.foo());
     
      // Re-check the property (change)
      intProp = (Integer) sr.getProperty("int");
      boolProp = (Boolean) sr.getProperty("boolean");
      strProp = (String) sr.getProperty("string");
      strAProp = (String[]) sr.getProperty("strAProp");
      intAProp = (int[]) sr.getProperty("intAProp");
     
      assertEquals("Check intProp equality", intProp, new Integer(2));
      assertEquals("Check longProp equality", boolProp, new Boolean(true));
      assertEquals("Check strProp equality", strProp, new String("foo"));
      assertNotNull("Check strAProp not nullity", strAProp);
      v = new String[] {"foo", "bar"};
      for (int i = 0; i < strAProp.length; i++) {
        if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
      }
      assertNull("Check intAProp hidding (no value)", intAProp);
     
      //  Reconfiguration
      fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
      fact = (ManagedServiceFactory) getServiceObject(fact_ref);
      p3 = new Properties();
      p3.put("int", "1");
        p3.put("boolean", "true");
        p3.put("string", "foo");
        p3.put("strAProp", "{foo, bar, baz}");
        p3.put("intAProp", "{ 1, 2, 3}");
      try {
        fact.updated("FooProvider-3", p3);
      } catch (ConfigurationException e) {
        fail("Unable to reconfigure the instance with : " + p3);
      }
     
      sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
View Full Code Here

 
  /**
   * Check creation.
   */
  public void testCreation() {
    ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
   
    Properties  p = new Properties();
    p.put("int", new Integer(3));
    p.put("long", new Long(42));
    p.put("string", "absdir");
    p.put("strAProp", new String[] {"a"});
    p.put("intAProp", new int[] {1,2});
   
    try {
      f.updated("ok2", p);
      ServiceReference ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "ok2");
      assertNotNull("Check instance creation", ref);
      f.deleted("ok2");
      ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "ok2");
      assertNull("Check instance deletion", ref);
    } catch (ConfigurationException e) {
      fail("An acceptable configuration is rejected : " + e.getMessage());
    }
View Full Code Here

 
  /**
   * Check creation (push String).
   */
  public void testCreationString() {
        ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
       
        Properties  p = new Properties();
        p.put("int", "3");
        p.put("long", "42");
        p.put("string", "absdir");
        p.put("strAProp", "{a}");
        p.put("intAProp", "{1,2}");
       
        try {
            f.updated("ok2", p);
            ServiceReference ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "ok2");
            assertNotNull("Check instance creation", ref);
            f.deleted("ok2");
            ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "ok2");
            assertNull("Check instance deletion", ref);
        } catch (ConfigurationException e) {
            fail("An acceptable configuration is rejected : " + e.getMessage());
        }
View Full Code Here

 
  /**
   * Check update and delete.
   */
  public void testUpdate() {
    ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
   
    Properties  p = new Properties();
    p.put("int", new Integer(3));
    p.put("long", new Long(42));
    p.put("string", "absdir");
    p.put("strAProp", new String[] {"a"});
    p.put("intAProp", new int[] {1,2});
   
    try {
      f.updated("okkkk", p);
      ServiceReference ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "okkkk");
      assertNotNull("Check instance creation", ref);
      p.put("int", new Integer("4"));
      f.updated("okkkk", p);
      ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "okkkk");
      Integer test = (Integer) ref.getProperty("int");
      assertEquals("Check instance modification", 4, test.intValue());
      f.deleted("okkkk");
      ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "okkkk");
      assertNull("Check instance deletion", ref);
    } catch (ConfigurationException e) {
      fail("An acceptable configuration is rejected : " + e.getMessage());
    }
View Full Code Here

    /**
     * Check update and delete.
     * (Push String).
     */
    public void testUpdateString() {
      ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
     
      Properties  p = new Properties();
      p.put("int", "3");
      p.put("long", "42");
      p.put("string", "absdir");
      p.put("strAProp", "{a}");
      p.put("intAProp", "{1,2}");
     
      try {
        f.updated("okkkk", p);
        ServiceReference ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "okkkk");
        assertNotNull("Check instance creation", ref);
        p.put("int", new Integer("4"));
        f.updated("okkkk", p);
        ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "okkkk");
        Integer test = (Integer) ref.getProperty("int");
        assertEquals("Check instance modification", 4, test.intValue());
        f.deleted("okkkk");
        ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "okkkk");
        assertNull("Check instance deletion", ref);
      } catch (ConfigurationException e) {
        fail("An acceptable configuration is rejected : " + e.getMessage());
      }
View Full Code Here

        for (int t = 0; t < references.length; t++) {
            ServiceReference reference = references[t];

            // Get the service to update.
            ManagedServiceFactory factory =
                    (ManagedServiceFactory) context.getService(reference);
            try {
                if (factory == null) {
                    // Must have deregistered so nothing to do.
                    return;
                }

                for (int i = 0; i < allProperties.length; i++) {
                    Dictionary dictionary = allProperties[i];

                    String pid = (String) dictionary.get(
                            FrameworkConstants.SERVICE_PID);

                    try {
                        factory.updated(pid,
                                new CaseInsensitiveDictionary(dictionary));
                    } catch (ConfigurationException e) {
                        log.log(reference, LogService.LOG_ERROR,
                                "updated(" + pid + ", " + dictionary +
                                        ") method failed:",
View Full Code Here

    protected void doTask(BundleContext context, LogService log) {
        for (int i = 0; i < references.length; i++) {
            ServiceReference reference = references[i];

            // Get the service to update.
            ManagedServiceFactory factory =
                    (ManagedServiceFactory) context.getService(reference);
            try {
                if (factory == null) {
                    // Must have deregistered so nothing to do.
                    return;
                }


                try {
                    factory.deleted(pid);
                } catch (Throwable throwable) {
                    log.log(reference, LogService.LOG_ERROR,
                            "deleted(" + pid + ") method failed:",
                            throwable);
                }
View Full Code Here

            }
        };
    }

    public void testCreateManagedServiceFactory() throws Exception {
        ManagedServiceFactory sf = createManagedServiceFactory();


        assertNotNull("name should not be null", sf.getName());
        {
            try {
                sf.updated("bob", null);
                fail("An Exception should have been thrown");
            } catch (IllegalArgumentException iae) {
                // success
            }
        }

        {
            try {
                sf.updated(null, new Hashtable());
                fail("An Exception should have been thrown");
            } catch (IllegalArgumentException iae) {
                // success
            }
        }
        {
            try {
                sf.deleted(null);
                fail("An Exception should have been thrown");
            } catch (IllegalArgumentException iae) {
                // success
            }
        }
View Full Code Here

TOP

Related Classes of org.osgi.service.cm.ManagedServiceFactory

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.