本文整理汇总了Java中org.osgi.service.cm.Configuration.getPid方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.getPid方法的具体用法?Java Configuration.getPid怎么用?Java Configuration.getPid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.service.cm.Configuration
的用法示例。
在下文中一共展示了Configuration.getPid方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Override
public Object execute() throws Exception {
if (schedulerManager.getSchedulerNames().contains(schedulerName)) {
throw new IllegalArgumentException("Scheduler with that name already exists");
}
Configuration configuration = configurationAdmin.createFactoryConfiguration(VolatileSchedulerProvider.CONFIG_FACTORY_NAME, "?");
Dictionary<String, Object> dict = new Hashtable<>();
dict.put(VolatileSchedulerProvider.PROPERTY_NAME, schedulerName);
dict.put(VolatileSchedulerProvider.PROPERTY_THREADS, threads);
dict.put(VolatileSchedulerProvider.PROPERTY_PRIORITY, priority);
configuration.update(dict);
return configuration.getPid();
}
示例2: storeConfigurations
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
private void storeConfigurations ( final ZipOutputStream zos, final List<Configuration> cfgs ) throws Exception
{
zos.putNextEntry ( new ZipEntry ( CFG_FILE_NAME ) );
final XmlHelper xml = new XmlHelper ();
final Document doc = xml.create ();
final Element root = doc.createElement ( "configuration" );
doc.appendChild ( root );
root.setAttribute ( "version", BACKUP_VERSION );
for ( final Configuration cfg : cfgs )
{
final Element entry = XmlHelper.addElement ( root, "entry" );
if ( cfg.getFactoryPid () != null )
{
entry.setAttribute ( "factoryPid", cfg.getFactoryPid () );
}
else if ( cfg.getPid () != null )
{
entry.setAttribute ( "pid", cfg.getPid () );
}
for ( final String key : Collections.list ( cfg.getProperties ().keys () ) )
{
final Object value = cfg.getProperties ().get ( key );
final Element prop = XmlHelper.addElement ( entry, "property" );
prop.setAttribute ( "key", key );
if ( value != null )
{
prop.setAttribute ( "type", value.getClass ().getName () );
prop.setTextContent ( value.toString () );
}
}
}
xml.write ( doc, zos );
zos.closeEntry ();
}
示例3: test_basic_configuration_factory_configure_then_start
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_basic_configuration_factory_configure_then_start() throws BundleException, IOException
{
final String factoryPid = "test_basic_configuration_factory_configure_then_start";
bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
bundle.start();
delay();
final Configuration config = createFactoryConfiguration( factoryPid, null, true );
final String pid = config.getPid();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
Dictionary<?, ?> props = tester.configs.get( pid );
TestCase.assertNotNull( props );
TestCase.assertEquals( pid, props.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid, props.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props.get( PROP_NAME ) );
TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
// delete
config.delete();
delay();
// ==> update with null
TestCase.assertNull( tester.configs.get( pid ) );
TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryDeleteCalls );
}
示例4: test_basic_configuration_factory_start_then_configure
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_basic_configuration_factory_start_then_configure() throws BundleException, IOException
{
// 1. create config with pid and locationA
// 2. update config with properties
final String factoryPid = "test_basic_configuration_factory_start_then_configure";
final Configuration config = createFactoryConfiguration( factoryPid, null, true );
final String pid = config.getPid();
// 3. register ManagedService ms1 with pid from said locationA
bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
bundle.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
Dictionary<?, ?> props = tester.configs.get( pid );
TestCase.assertNotNull( props );
TestCase.assertEquals( pid, props.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid, props.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props.get( PROP_NAME ) );
TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
// delete
config.delete();
delay();
// ==> update with null
TestCase.assertNull( tester.configs.get( pid ) );
TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 1, tester.numManagedServiceFactoryDeleteCalls );
}
示例5: test_two_services_same_pid_in_same_bundle_configure_before_registration
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_two_services_same_pid_in_same_bundle_configure_before_registration() throws BundleException
{
final String factoryPid = "test.pid";
final Configuration config = createFactoryConfiguration( factoryPid );
final String pid = config.getPid();
TestCase.assertEquals( factoryPid, config.getFactoryPid() );
TestCase.assertNull( config.getBundleLocation() );
bundle = installBundle( factoryPid, MultiManagedServiceFactoryTestActivator.class );
bundle.start();
// give cm time for distribution
delay();
final MultiManagedServiceFactoryTestActivator tester = MultiManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( "Activator not started !!", tester );
// assert activater has configuration (two calls, one per pid)
TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
bundle.uninstall();
bundle = null;
delay();
TestCase.assertNull( config.getBundleLocation() );
// remove the configuration for good
deleteConfig( pid );
}
示例6: test_two_services_same_pid_in_same_bundle_configure_after_registration
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_two_services_same_pid_in_same_bundle_configure_after_registration() throws BundleException
{
final String factoryPid = "test.pid";
bundle = installBundle( factoryPid, MultiManagedServiceFactoryTestActivator.class );
bundle.start();
// give cm time for distribution
delay();
final MultiManagedServiceFactoryTestActivator tester = MultiManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( "Activator not started !!", tester );
// no configuration yet
TestCase.assertTrue( "Expect Properties after Service Registration", tester.configs.isEmpty() );
TestCase.assertEquals( "Expect two update calls", 0, tester.numManagedServiceFactoryUpdatedCalls );
final Configuration config = createFactoryConfiguration( factoryPid );
final String pid = config.getPid();
delay();
TestCase.assertEquals( factoryPid, config.getFactoryPid() );
TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
// assert activater has configuration (two calls, one per pid)
TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
TestCase.assertEquals( "Expect another two single update call", 2, tester.numManagedServiceFactoryUpdatedCalls );
bundle.uninstall();
bundle = null;
delay();
TestCase.assertNull( config.getBundleLocation() );
// remove the configuration for good
deleteConfig( pid );
}
示例7: test_switch_static_binding_factory
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_switch_static_binding_factory() throws BundleException, IOException
{
// 1. create config with pid and locationA
// 2. update config with properties
final String factoryPid = "test_switch_static_binding_factory";
final String locationA = "test:location/A/" + factoryPid;
final Configuration config = createFactoryConfiguration( factoryPid, locationA, true );
final String pid = config.getPid();
// 3. register ManagedService ms1 with pid from said locationA
final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( testerA1.configs.get( pid ) );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + factoryPid;
final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
bundleB.start();
delay();
// ==> configuration not supplied to service ms2
final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
TestCase.assertNull( testerB1.configs.get( pid ));
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation( locationB );
delay();
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
/*
* According to BJ Hargrave configuration is not re-dispatched
* due to setting the bundle location.
* <p>
* Therefore, we have two sets one with re-dispatch expectation and
* one without re-dispatch expectation.
*/
if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
{
// ==> configuration removed from service ms1
TestCase.assertNull( testerA1.configs.get( pid ));
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryDeleteCalls );
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
else
{
// ==> configuration not removed from service ms1
TestCase.assertNotNull( testerA1.configs.get( pid ));
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 0, testerA1.numManagedServiceFactoryDeleteCalls );
// ==> configuration not supplied to the service ms2
TestCase.assertNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
}
// 6. Update configuration now
config.update();
delay();
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
示例8: test_switch_dynamic_binding_factory
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_switch_dynamic_binding_factory() throws BundleException, IOException
{
// 1. create config with pid and locationA
// 2. update config with properties
final String factoryPid = "test_switch_static_binding_factory";
final String locationA = "test:location/A/" + factoryPid;
final Configuration config = createFactoryConfiguration( factoryPid, null, true );
final String pid = config.getPid();
TestCase.assertNull( config.getBundleLocation() );
// 3. register ManagedService ms1 with pid from said locationA
final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( testerA1.configs.get( pid ) );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( locationA, config.getBundleLocation() );
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + factoryPid;
final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
bundleB.start();
delay();
// ==> configuration not supplied to service ms2
final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
TestCase.assertNull( testerB1.configs.get( pid ));
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( locationA, config.getBundleLocation() );
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation( locationB );
delay();
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
/*
* According to BJ Hargrave configuration is not re-dispatched
* due to setting the bundle location.
* <p>
* Therefore, we have two sets one with re-dispatch expectation and
* one without re-dispatch expectation.
*/
if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
{
// ==> configuration removed from service ms1
TestCase.assertNull( testerA1.configs.get( pid ));
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryDeleteCalls );
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
else
{
// ==> configuration not removed from service ms1
TestCase.assertNotNull( testerA1.configs.get( pid ));
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 0, testerA1.numManagedServiceFactoryDeleteCalls );
// ==> configuration not supplied to the service ms2
TestCase.assertNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
}
// 6. Update configuration now
config.update();
delay();
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
示例9: test_switch_dynamic_binding_factory_after_uninstall
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_switch_dynamic_binding_factory_after_uninstall() throws BundleException, IOException
{
// 1. create config with pid and locationA
// 2. update config with properties
final String factoryPid = "test_switch_static_binding_factory";
final String locationA = "test:location/A/" + factoryPid;
final Configuration config = createFactoryConfiguration( factoryPid, null, true );
final String pid = config.getPid();
TestCase.assertNull( config.getBundleLocation() );
// 3. register ManagedService ms1 with pid from said locationA
final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( testerA1.configs.get( pid ) );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( locationA, config.getBundleLocation() );
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + factoryPid;
final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
bundleB.start();
delay();
// ==> configuration not supplied to service ms2
final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
TestCase.assertNull( testerB1.configs.get( pid ));
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( locationA, config.getBundleLocation() );
// 5. Uninstall bundle A
bundleA.uninstall();
delay();
/*
* According to BJ Hargrave configuration is not re-dispatched
* due to setting the bundle location.
* <p>
* Therefore, we have two sets one with re-dispatch expectation and
* one without re-dispatch expectation.
*/
if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
{
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
else
{
// ==> configuration is unbound
TestCase.assertNull( config.getBundleLocation() );
// ==> configuration not supplied to the service ms2
TestCase.assertNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
}
// 6. Update configuration now
config.update();
delay();
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
示例10: test_two_services_same_pid_in_two_bundle_configure_before_registration
import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_two_services_same_pid_in_two_bundle_configure_before_registration() throws BundleException
{
Bundle bundle2 = null;
try
{
final String factoryPid = "test.pid";
final Configuration config = createFactoryConfiguration( factoryPid );
final String pid = config.getPid();
TestCase.assertEquals( factoryPid, config.getFactoryPid() );
TestCase.assertNull( config.getBundleLocation() );
bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
bundle.start();
bundle2 = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class );
bundle2.start();
// give cm time for distribution
delay();
final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( "Activator not started !!", tester );
final ManagedServiceFactoryTestActivator2 tester2 = ManagedServiceFactoryTestActivator2.INSTANCE;
TestCase.assertNotNull( "Activator 2 not started !!", tester2 );
// expect first activator to have received properties
// assert first bundle has configuration (two calls, one per srv)
TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceFactoryUpdatedCalls );
// assert second bundle has no configuration
TestCase.assertTrue( tester2.configs.isEmpty() );
TestCase.assertEquals( 0, tester2.numManagedServiceFactoryUpdatedCalls );
// expect configuration bound to first bundle
TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
bundle.uninstall();
bundle = null;
delay();
/*
* According to BJ Hargrave configuration is not re-dispatched
* due to setting the bundle location.
* <p>
* Therefore, we have two sets one with re-dispatch expectation and
* one without re-dispatch expectation.
*/
if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
{
// expect configuration reassigned
TestCase.assertEquals( bundle2.getLocation(), config.getBundleLocation() );
}
else
{
// expected configuration unbound
TestCase.assertNull( config.getBundleLocation() );
}
// remove the configuration for good
deleteConfig( pid );
}
finally
{
if ( bundle2 != null )
{
bundle2.uninstall();
}
}
}