Search in sources :

Example 6 with Filter

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();
}
Also used : Configuration(org.osgi.service.cm.Configuration) Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Hashtable(java.util.Hashtable) Subsystem(org.osgi.service.subsystem.Subsystem) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 7 with Filter

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);
    }
}
Also used : Filter(org.osgi.framework.Filter) Hashtable(java.util.Hashtable)

Example 8 with Filter

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;
    }
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Method(java.lang.reflect.Method) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) HelloWorld(org.apache.aries.isolated.sample.HelloWorld)

Example 9 with Filter

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();
}
Also used : Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) AriesTransactionManager(org.apache.aries.transaction.AriesTransactionManager) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CommonDataSource(javax.sql.CommonDataSource)

Example 10 with Filter

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);
}
Also used : ServiceState(org.apache.aries.jmx.framework.ServiceState) Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceStateMBean(org.osgi.jmx.framework.ServiceStateMBean) Logger(org.apache.aries.jmx.Logger)

Aggregations

Filter (org.osgi.framework.Filter)81 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)29 ArrayList (java.util.ArrayList)22 ServiceReference (org.osgi.framework.ServiceReference)20 Hashtable (java.util.Hashtable)18 Test (org.junit.Test)14 BundleContext (org.osgi.framework.BundleContext)13 List (java.util.List)12 Bundle (org.osgi.framework.Bundle)11 Dictionary (java.util.Dictionary)9 SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)9 Configuration (org.osgi.service.cm.Configuration)9 HashMap (java.util.HashMap)7 Map (java.util.Map)6 IOException (java.io.IOException)5 URL (java.net.URL)5 InstallInfo (org.apache.aries.subsystem.scope.InstallInfo)5 ScopeUpdate (org.apache.aries.subsystem.scope.ScopeUpdate)5 Iterator (java.util.Iterator)4