use of org.osgi.framework.Filter in project aries by apache.
the class ConfigAdminPropsFileContentHandlerTest method testAries1352.
@Test
public void testAries1352() throws Exception {
// Same test than testConfigurationContentHandler, but an existing
// configuration exists before the subsystem is installed.
// The configuration should not be overwritten by the subsystem
// installation.
ConfigurationAdmin cm = bundleContext.getService(bundleContext.getServiceReference(ConfigurationAdmin.class));
Configuration blahConf = cm.getConfiguration("com.blah.Blah", "?");
Dictionary<String, Object> blahProps = new Hashtable<String, Object>(1);
blahProps.put("configVal", "Hello");
blahConf.update(blahProps);
Subsystem subsystem = installSubsystemFromFile("cmContent.esa");
subsystem.start();
// No configuration exists for the service Bar: configuration
// values are loaded by the subsystem.
Filter f = bundleContext.createFilter("(&(objectClass=java.lang.String)(test.pid=org.foo.Bar))");
ServiceTracker<String, String> barTracker = new ServiceTracker<String, String>(bundleContext, f, null);
try {
barTracker.open();
String blahSvc = barTracker.waitForService(2000);
assertEquals("Bar!", blahSvc);
} finally {
barTracker.close();
}
// A configuration exists for Blah: the subsystem installation should
// not overwrite it.
Filter f2 = bundleContext.createFilter("(&(objectClass=java.lang.String)(test.pid=com.blah.Blah))");
ServiceTracker<String, String> blahTracker = new ServiceTracker<String, String>(bundleContext, f2, null);
try {
blahTracker.open();
String blahSvc = blahTracker.waitForService(2000);
assertEquals("Hello", blahSvc);
} finally {
blahTracker.close();
}
stopAndUninstallSubsystemSilently(subsystem);
blahConf.delete();
}
use of org.osgi.framework.Filter in project aries by apache.
the class Activator method start.
@Override
public void start(BundleContext context) throws Exception {
Filter filter = context.createFilter("(&(objectClass=java.lang.String)(test=testCompositeServiceImports))");
st = new ServiceTracker<String, String>(context, filter, null);
st.open();
String svc = st.waitForService(5000);
if ("testCompositeServiceImports".equals(svc)) {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("test", "tb4");
context.registerService(String.class, "tb4", props);
}
}
use of org.osgi.framework.Filter in project aries by apache.
the class IsolationTestUtils method findHelloWorldService.
public static HelloWorld findHelloWorldService(BundleContext ctx) throws Exception {
if (ctx != null) {
// Dive into the context and pull out the composite bundle for the app
Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "=" + HelloWorld.class.getName() + ")");
ServiceTracker tracker = new ServiceTracker(ctx, osgiFilter, null);
tracker.open();
final Object hw = tracker.waitForService(DEFAULT_TIMEOUT);
tracker.close();
if (hw != null) {
// proxy because the class space between the sample app and the test bundle is not consistent
return new HelloWorld() {
public String getMessage() {
try {
Method m = hw.getClass().getMethod("getMessage");
return (String) m.invoke(hw);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
} else {
return null;
}
} else {
return null;
}
}
use of org.osgi.framework.Filter in project aries by apache.
the class Activator method start.
public void start(BundleContext ctx) {
context = ctx;
// Expose blueprint namespace handler if xbean is present
try {
nshReg = JdbcNamespaceHandler.register(ctx);
} catch (NoClassDefFoundError e) {
LOGGER.warn("Unable to register JDBC blueprint namespace handler (xbean-blueprint not available).");
} catch (Exception e) {
LOGGER.error("Unable to register JDBC blueprint namespace handler", e);
}
Filter filter;
String flt = "(&(|(objectClass=javax.sql.XADataSource)(objectClass=javax.sql.DataSource))(!(aries.managed=true)))";
try {
filter = context.createFilter(flt);
} catch (InvalidSyntaxException e) {
throw new IllegalStateException(e);
}
t = new ServiceTracker<CommonDataSource, ManagedDataSourceFactory>(ctx, filter, this);
tm = new SingleServiceTracker<AriesTransactionManager>(ctx, AriesTransactionManager.class, this);
tm.open();
}
use of org.osgi.framework.Filter in project aries by apache.
the class Activator method start.
public void start(BundleContext context) throws Exception {
ctx = context;
logger = new Logger(ctx);
Filter filter = getFilter(context, PACKAGE_ADMIN, START_LEVEL, PERMISSION_ADMIN, CONFIG_ADMIN, USER_ADMIN, PROVISIONING_SERVICE);
tracker = new ServiceTracker(context, filter, this);
tracker.open();
stateConfig = StateConfig.register(context);
registerMBean(ServiceStateMBean.class.getName(), new Factory<ServiceStateMBean>() {
public ServiceStateMBean create() {
return new ServiceState(ctx, stateConfig, logger);
}
}, ServiceStateMBean.OBJECTNAME, _serviceStateMbean);
}
Aggregations