Search in sources :

Example 16 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class BundleRepositoryManagerImpl method getAllBundleRepositories.

public Collection<BundleRepository> getAllBundleRepositories() {
    LOGGER.debug(LOG_ENTRY, "getAllBundleRepositories");
    ServiceCollection<BundleRepository> providers = new ArrayServiceList<BundleRepository>(bc);
    try {
        ServiceReference[] refs = bc.getServiceReferences(BundleRepository.class.getName(), null);
        if (refs != null) {
            for (ServiceReference ref : refs) {
                providers.addService(ref);
            }
        }
    } catch (InvalidSyntaxException e) {
        LOGGER.error(LOG_EXCEPTION, e);
    }
    LOGGER.debug(LOG_EXIT, "getAllBundleRepositories");
    return providers;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ServiceReference(org.osgi.framework.ServiceReference)

Example 17 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class AriesRepositoryGenerator method getOsgiService.

private Object getOsgiService(BundleContext bc, String className) {
    ServiceTracker tracker = null;
    try {
        String flt = "(" + Constants.OBJECTCLASS + "=" + className + ")";
        Filter osgiFilter = FrameworkUtil.createFilter(flt);
        tracker = new ServiceTracker(bc, osgiFilter, null);
        tracker.open();
        // add tracker to the list of trackers we close at tear down
        srs.add(tracker);
        Object x = tracker.waitForService(DEFAULT_TIMEOUT);
        if (x == null) {
            throw new RuntimeException("Gave up waiting for service " + flt);
        }
        return x;
    } catch (InvalidSyntaxException e) {
        throw new IllegalArgumentException("Invalid filter", e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 18 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class AbstractServiceReferenceRecipe method start.

public void start(SatisfactionListener listener) {
    if (listener == null)
        throw new NullPointerException("satisfactionListener is null");
    if (started.compareAndSet(false, true)) {
        try {
            satisfactionListener = listener;
            satisfied.set(optional);
            // though this may not be sufficient because we don't control ordering of those events
            synchronized (tracked) {
                getBundleContextForServiceLookup().addServiceListener(this, getOsgiFilter());
                ServiceReference[] references = getBundleContextForServiceLookup().getServiceReferences((String) null, getOsgiFilter());
                tracked.setInitial(references != null ? references : new ServiceReference[0]);
            }
            tracked.trackInitial();
            satisfied.set(optional || !tracked.isEmpty());
            retrack();
            LOGGER.debug("Found initial references {} for OSGi service {}", getServiceReferences(), getOsgiFilter());
        } catch (InvalidSyntaxException e) {
            throw new ComponentDefinitionException(e);
        }
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 19 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class DSLTest method testConfigurationsAndRegistrations.

@Test
public void testConfigurationsAndRegistrations() throws InvalidSyntaxException, IOException, InterruptedException {
    ServiceReference<ConfigurationAdmin> serviceReference = bundleContext.getServiceReference(ConfigurationAdmin.class);
    ConfigurationAdmin configurationAdmin = bundleContext.getService(serviceReference);
    /*  For each factory configuration register a service with the property
            key set to the value of the property key that comes with the
            configuration */
    OSGi<ServiceRegistration<Service>> program = configurations("test.configuration").map(d -> d.get("key")).flatMap(key -> register(Service.class, new Service(), new HashMap<String, Object>() {

        {
            put("key", key);
        }
    }));
    OSGiResult<ServiceRegistration<Service>> result = program.run(bundleContext);
    assertEquals(0, bundleContext.getServiceReferences(Service.class, "(test.configuration=*)").size());
    CountDownLatch addedLatch = new CountDownLatch(3);
    ServiceRegistration<?> addedServiceRegistration = bundleContext.registerService(ManagedServiceFactory.class, new ManagedServiceFactory() {

        @Override
        public String getName() {
            return "";
        }

        @Override
        public void updated(String s, Dictionary<String, ?> dictionary) throws ConfigurationException {
            addedLatch.countDown();
        }

        @Override
        public void deleted(String s) {
        }
    }, new Hashtable<String, Object>() {

        {
            put("service.pid", "test.configuration");
        }
    });
    CountDownLatch deletedLatch = new CountDownLatch(3);
    ServiceRegistration<?> deletedServiceRegistration = bundleContext.registerService(ManagedServiceFactory.class, new ManagedServiceFactory() {

        @Override
        public String getName() {
            return "";
        }

        @Override
        public void updated(String s, Dictionary<String, ?> dictionary) throws ConfigurationException {
        }

        @Override
        public void deleted(String s) {
            deletedLatch.countDown();
        }
    }, new Hashtable<String, Object>() {

        {
            put("service.pid", "test.configuration");
        }
    });
    Configuration configuration = configurationAdmin.createFactoryConfiguration("test.configuration");
    configuration.update(new Hashtable<String, Object>() {

        {
            put("key", "service one");
        }
    });
    Configuration configuration2 = configurationAdmin.createFactoryConfiguration("test.configuration");
    configuration2.update(new Hashtable<String, Object>() {

        {
            put("key", "service two");
        }
    });
    Configuration configuration3 = configurationAdmin.createFactoryConfiguration("test.configuration");
    configuration3.update(new Hashtable<String, Object>() {

        {
            put("key", "service three");
        }
    });
    assertTrue(addedLatch.await(10, TimeUnit.SECONDS));
    assertEquals(1, bundleContext.getServiceReferences(Service.class, "(key=service one)").size());
    assertEquals(1, bundleContext.getServiceReferences(Service.class, "(key=service two)").size());
    assertEquals(1, bundleContext.getServiceReferences(Service.class, "(key=service three)").size());
    configuration3.delete();
    configuration2.delete();
    configuration.delete();
    assertTrue(deletedLatch.await(10, TimeUnit.SECONDS));
    assertEquals(0, bundleContext.getServiceReferences(Service.class, "(test.configuration=*)").size());
    addedServiceRegistration.unregister();
    deletedServiceRegistration.unregister();
    result.close();
    bundleContext.ungetService(serviceReference);
}
Also used : OSGi.configurations(org.apache.aries.osgi.functional.OSGi.configurations) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) OSGi.onClose(org.apache.aries.osgi.functional.OSGi.onClose) OSGi.register(org.apache.aries.osgi.functional.OSGi.register) HighestRankingRouter.highest(org.apache.aries.osgi.functional.test.HighestRankingRouter.highest) Configuration(org.osgi.service.cm.Configuration) ConfigurationException(org.osgi.service.cm.ConfigurationException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OSGi.configuration(org.apache.aries.osgi.functional.OSGi.configuration) ServiceReference(org.osgi.framework.ServiceReference) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration) ManagedServiceFactory(org.osgi.service.cm.ManagedServiceFactory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) OSGi.serviceReferences(org.apache.aries.osgi.functional.OSGi.serviceReferences) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) OSGi.just(org.apache.aries.osgi.functional.OSGi.just) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) OSGi.services(org.apache.aries.osgi.functional.OSGi.services) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) OSGi(org.apache.aries.osgi.functional.OSGi) FrameworkUtil(org.osgi.framework.FrameworkUtil) OSGiResult(org.apache.aries.osgi.functional.OSGiResult) Dictionary(java.util.Dictionary) Assert.assertEquals(org.junit.Assert.assertEquals) Configuration(org.osgi.service.cm.Configuration) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedServiceFactory(org.osgi.service.cm.ManagedServiceFactory) ConfigurationException(org.osgi.service.cm.ConfigurationException) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 20 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project karaf by apache.

the class Dump method dump.

public static void dump(BundleContext bundleContext, DumpDestination destination, boolean noThreadDump, boolean noHeapDump) {
    List<DumpProvider> providers = new ArrayList<>();
    providers.add(new EnvironmentDumpProvider(bundleContext));
    providers.add(new MemoryDumpProvider());
    if (!noThreadDump)
        providers.add(new ThreadDumpProvider());
    if (!noHeapDump)
        providers.add(new HeapDumpProvider());
    providers.add(new BundleDumpProvider(bundleContext));
    for (DumpProvider provider : providers) {
        try {
            provider.createDump(destination);
        } catch (Throwable t) {
        // Ignore
        }
    }
    try {
        for (ServiceReference<DumpProvider> ref : bundleContext.getServiceReferences(DumpProvider.class, null)) {
            DumpProvider provider = bundleContext.getService(ref);
            try {
                provider.createDump(destination);
            } catch (Throwable t) {
            // Ignore
            } finally {
                bundleContext.ungetService(ref);
            }
        }
    } catch (InvalidSyntaxException e) {
    // Ignore
    }
    try {
        destination.save();
    } catch (Throwable t) {
    // Ignore
    }
}
Also used : ArrayList(java.util.ArrayList) ThreadDumpProvider(org.apache.karaf.diagnostic.core.providers.ThreadDumpProvider) MemoryDumpProvider(org.apache.karaf.diagnostic.core.providers.MemoryDumpProvider) BundleDumpProvider(org.apache.karaf.diagnostic.core.providers.BundleDumpProvider) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) HeapDumpProvider(org.apache.karaf.diagnostic.core.providers.HeapDumpProvider) BundleDumpProvider(org.apache.karaf.diagnostic.core.providers.BundleDumpProvider) ThreadDumpProvider(org.apache.karaf.diagnostic.core.providers.ThreadDumpProvider) EnvironmentDumpProvider(org.apache.karaf.diagnostic.core.providers.EnvironmentDumpProvider) MemoryDumpProvider(org.apache.karaf.diagnostic.core.providers.MemoryDumpProvider) HeapDumpProvider(org.apache.karaf.diagnostic.core.providers.HeapDumpProvider) EnvironmentDumpProvider(org.apache.karaf.diagnostic.core.providers.EnvironmentDumpProvider)

Aggregations

InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)105 ServiceReference (org.osgi.framework.ServiceReference)54 Filter (org.osgi.framework.Filter)26 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)20 BundleContext (org.osgi.framework.BundleContext)16 ServiceTracker (org.osgi.util.tracker.ServiceTracker)14 HashMap (java.util.HashMap)12 Configuration (org.osgi.service.cm.Configuration)12 Map (java.util.Map)10 Test (org.junit.Test)9 Dictionary (java.util.Dictionary)8 Hashtable (java.util.Hashtable)8 List (java.util.List)6 ConfigurationException (org.osgi.service.cm.ConfigurationException)6 Metacard (ddf.catalog.data.Metacard)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 CatalogFramework (ddf.catalog.CatalogFramework)3 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)3 InputTransformer (ddf.catalog.transform.InputTransformer)3