Package org.osgi.service.component

Examples of org.osgi.service.component.ComponentInstance


        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );

        // ensure instance is bound
        final SimpleComponent sc = SimpleComponent.INSTANCE;
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );

        // ensure factory is not bound
//        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // assert two components managed
        checkConfigurationCount(name, 1, ComponentConfigurationDTO.ACTIVE);
//        final Component[] allFactoryComponents = findComponentConfigurationsByName( pid, -1 );
//        TestCase.assertNotNull( allFactoryComponents );
//        TestCase.assertEquals( 2, allFactoryComponents.length );
//        for ( int i = 0; i < allFactoryComponents.length; i++ )
//        {
//            final Component c = allFactoryComponents[i];
//            if ( c.getId() == component.getId() )
//            {
//                TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
//            }
//            else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
//            {
//                TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
//            }
//            else
//            {
//                TestCase.fail( "Unexpected Component " + c );
//            }
//        }

        // register second service
        final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
        delay();

        // ensure instance is bound
        TestCase.assertEquals( 2, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
        TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );

        // ensure factory is not bound
//        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // drop second service and ensure unbound (and active)
        srv11.drop();
        delay();
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
//        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );


        // remove the service, expect factory to deactivate and instance to dispose
        srv1.drop();
        delay();

        checkConfigurationCount(name, 0, -1);
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        //TODO this check should be whether the service is registered.
//        final Component[] allFactoryComponents2 = findComponentConfigurationsByName( pid, -1 );
//        TestCase.assertNotNull( allFactoryComponents2 );
//        TestCase.assertEquals( 1, allFactoryComponents2.length );
//        for ( int i = 0; i < allFactoryComponents2.length; i++ )
//        {
//            final Component c = allFactoryComponents2[i];
//            if ( c.getId() == component.getId() )
//            {
//                TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
//            }
//            else
//            {
//                TestCase.fail( "Unexpected Component " + c );
//            }
//        }

        // registeranother service, factory must come back, instance not
        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay();

//        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        checkConfigurationCount(name, 0, -1);
//        final Component[] allFactoryComponents3 = findComponentConfigurationsByName( pid, -1 );
//        TestCase.assertNotNull( allFactoryComponents3 );
View Full Code Here


        getConfigurationsDisabledThenEnable(componentname, 0, -1);

        TestCase.assertNull( SimpleComponent.INSTANCE );

        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);

        // check registered components
        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
       
        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);

    }
View Full Code Here

        getConfigurationsDisabledThenEnable(componentname, 0, -1);

        TestCase.assertNull( SimpleComponent.INSTANCE );

        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);

        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);

        // disable the factory
        disableAndCheck(componentname);
        delay();

        // factory is disabled but the instance is still alive
        TestCase.assertNotNull( SimpleComponent.INSTANCE );

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

    }
View Full Code Here

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        props.put( SimpleComponent.PROP_ACTIVATE_FAILURE, "Requested Failure" );
        final ComponentFactory factory = getComponentFactory(componentfactory);

        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );


        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.SATISFIED);
    }
View Full Code Here

        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
        TestCase.assertNull( SimpleComponent.INSTANCE );

        // get the component factory service
        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);

        final Object instanceObject = instance.getInstance();
        TestCase.assertNotNull( instanceObject );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instanceObject );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );                       

        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);

        // delete config, ensure factory is not active anymore and component instance gone
        //(configuration required >> dispose of instance.  Also for pre-1.3 components, removing config unconditionally
        //deactivates component.
        deleteConfig( componentname );
        delay();

        checkFactory(componentfactory, optional);

        if (expectComponent)
        {
            TestCase.assertNotNull( instance.getInstance() );
            TestCase.assertNotNull( SimpleComponent.INSTANCE );

            // with removal of the factory, the created instance should also be removed
            checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);           
        }
        else
        {
            TestCase.assertNull( instance.getInstance() );
            TestCase.assertNull( SimpleComponent.INSTANCE );

            // with removal of the factory, the created instance should also be removed
            checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);           
        }
View Full Code Here

        SimpleServiceImpl match = SimpleServiceImpl.create( bundleContext, "required" ).setFilterProperty( "required" );
        delay();

        TestCase.assertNull( SimpleComponent.INSTANCE );

        final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
        TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( match ) );

        // check registered components
        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);


        // overwritten filterprop
        Hashtable<String, String> propsNonMatch = new Hashtable<String, String>();
        propsNonMatch.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        propsNonMatch.put( "ref.target", "(filterprop=nomatch)" );
        ComponentFactory factory = getComponentFactory(componentfactory);
        final ComponentInstance instanceNonMatch = factory.newInstance( propsNonMatch );//works even without required reference
        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);

        final SimpleServiceImpl noMatch = SimpleServiceImpl.create( bundleContext, "nomatch" ).setFilterProperty(
            "nomatch" );
        delay();


        TestCase.assertNotNull( instanceNonMatch.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instanceNonMatch.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );

        TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( noMatch ) );

        // check registered components
        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);

        match.getRegistration().unregister();
        delay();

        // check registered components (ComponentFactory is still present)
        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);

        //it has already been deactivated.... this should cause an exception?
        noMatch.getRegistration().unregister();
        delay();

        // check registered components (ComponentFactory is still present)
        checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);

        // deactivated due to unsatisfied reference
        TestCase.assertNull( instanceNonMatch.getInstance() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        //Check that calling dispose on a deactivated instance has no effect
        instanceNonMatch.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instanceNonMatch.getInstance() ); // SCR 112.12.6.2
    }
View Full Code Here

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( "service.pid", "myFactoryInstance" );
        final ComponentFactory factory = getComponentFactory(componentfactory);

        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertTrue( instance.getInstance() instanceof SimpleService );
        //The referring service should now be active
        checkConfigurationCount(referringComponentName, 1, ComponentConfigurationDTO.ACTIVE);

        instance.dispose();
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

        //make sure it's unsatisfied (service is no longer available)
        checkConfigurationCount(referringComponentName, 1, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
    }
View Full Code Here

        TestCase.assertNull( SimpleComponent.INSTANCE );
       
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        props.put("ref.target", "(value=service2)");
        final ComponentInstance instance = createFactoryComponentInstance(componentfactory, props);

        log.log(LogService.LOG_WARNING, "Bound Services: " +  SimpleComponent.INSTANCE.m_multiRef);
        TestCase.assertFalse( SimpleComponent.INSTANCE.m_multiRef.contains( s1 ) );
        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( s2 ) );

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
       
        s2.drop();
        s1.drop();
    }
View Full Code Here

   
    public void run() {
      while (true) {
        try {
          //System.out.println("Creating A");
          ComponentInstance ci = _aFactory.newInstance(null);
          ci.dispose();
          if (Thread.currentThread().isInterrupted()) {
            return;
          }
        } catch (Throwable t) {
          if (!(t instanceof InterruptedException)) {
View Full Code Here

    }
   
    public void run() {
      while (true) {
        try {
          ComponentInstance ci = _cFactory.newInstance(null);
          ci.dispose();
          if (Thread.currentThread().isInterrupted()) {
            return;
          }
        } catch (Throwable t) {
          if (!(t instanceof InterruptedException)) {
View Full Code Here

TOP

Related Classes of org.osgi.service.component.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.