Search in sources :

Example 26 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project felix by apache.

the class ConfigurationManagerTest method createConfigurationManager.

private static ConfigurationManager createConfigurationManager(final LogService logService) {
    ConfigurationManager configMgr = new ConfigurationManager();
    try {
        Field field = configMgr.getClass().getDeclaredField("logTracker");
        field.setAccessible(true);
        field.set(configMgr, new ServiceTracker(new MockBundleContext(), "", null) {

            @Override
            public Object getService() {
                return logService;
            }
        });
    } catch (Throwable ignore) {
        throw (IllegalArgumentException) new IllegalArgumentException("Cannot set logTracker field value").initCause(ignore);
    }
    return configMgr;
}
Also used : Field(java.lang.reflect.Field) ServiceTracker(org.osgi.util.tracker.ServiceTracker) MockBundleContext(org.apache.felix.cm.MockBundleContext)

Example 27 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project felix by apache.

the class ConfigurationTestBase method setUp.

@Before
public void setUp() {
    configAdminTracker = new ServiceTracker(bundleContext, ConfigurationAdmin.class.getName(), null);
    configAdminTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Before(org.junit.Before)

Example 28 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project felix by apache.

the class AgentContext method setTrackers.

// ////////////////////////////////////////////////////////////////////
// ////////////////PRIVATE////////////////////////////////////////////
private void setTrackers() {
    try {
        logTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + LogService.class.getName() + ")"), null);
        logReaderTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + LogReaderService.class.getName() + ")"), null);
        startLevelTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + StartLevel.class.getName() + ")"), null);
        packageAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + PackageAdmin.class.getName() + ")"), null);
        permissionAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + PermissionAdmin.class.getName() + ")"), null);
        userAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + UserAdmin.class.getName() + ")"), null);
        configAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + ConfigurationAdmin.class.getName() + ")"), null);
    } catch (InvalidSyntaxException e) {
        warning("INVALID FILTER ");
    }
    logTracker.open();
    logReaderTracker.open();
    startLevelTracker.open();
    packageAdminTracker.open();
    permissionAdminTracker.open();
    userAdminTracker.open();
    configAdminTracker.open();
}
Also used : UserAdmin(org.osgi.service.useradmin.UserAdmin) ServiceTracker(org.osgi.util.tracker.ServiceTracker) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) StartLevel(org.osgi.service.startlevel.StartLevel) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) LogReaderService(org.osgi.service.log.LogReaderService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) LogService(org.osgi.service.log.LogService) PermissionAdmin(org.osgi.service.permissionadmin.PermissionAdmin)

Example 29 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project felix by apache.

the class ConfigurationManagerTest method setServiceTrackerField.

private static ServiceReference[] setServiceTrackerField(ConfigurationManager configMgr, String fieldName, Object... services) throws Exception {
    final Map<ServiceReference, Object> refMap = new HashMap<>();
    for (Object svc : services) {
        ServiceReference sref = Mockito.mock(ServiceReference.class);
        Mockito.when(sref.getProperty("objectClass")).thenReturn(new String[] { "TestService" });
        refMap.put(sref, svc);
    }
    Field field = configMgr.getClass().getDeclaredField(fieldName);
    field.setAccessible(true);
    field.set(configMgr, new ServiceTracker(new MockBundleContext(), "", null) {

        @Override
        public ServiceReference[] getServiceReferences() {
            return refMap.keySet().toArray(new ServiceReference[0]);
        }

        @Override
        public Object getService(ServiceReference reference) {
            return refMap.get(reference);
        }
    });
    return refMap.keySet().toArray(new ServiceReference[0]);
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ServiceTracker(org.osgi.util.tracker.ServiceTracker) MockBundleContext(org.apache.felix.cm.MockBundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 30 with ServiceTracker

use of org.osgi.util.tracker.ServiceTracker in project felix by apache.

the class ConfigurationManagerTest method createConfigurationManagerAndLog.

private static ConfigurationManager createConfigurationManagerAndLog(final LogService logService) throws IOException {
    final PersistenceManager pm = Mockito.mock(PersistenceManager.class);
    ConfigurationManager configMgr = new ConfigurationManager(new CachingPersistenceManagerProxy(pm), null);
    try {
        Field field = Log.class.getDeclaredField("logTracker");
        field.setAccessible(true);
        field.set(Log.logger, new ServiceTracker(new MockBundleContext(), "", null) {

            @Override
            public Object getService() {
                return logService;
            }
        });
    } catch (Throwable ignore) {
        throw (IllegalArgumentException) new IllegalArgumentException("Cannot set logTracker field value").initCause(ignore);
    }
    return configMgr;
}
Also used : Field(java.lang.reflect.Field) PersistenceManager(org.apache.felix.cm.PersistenceManager) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) ServiceTracker(org.osgi.util.tracker.ServiceTracker) MockBundleContext(org.apache.felix.cm.MockBundleContext) CachingPersistenceManagerProxy(org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy)

Aggregations

ServiceTracker (org.osgi.util.tracker.ServiceTracker)321 ServiceReference (org.osgi.framework.ServiceReference)65 Filter (org.osgi.framework.Filter)41 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)32 BundleContext (org.osgi.framework.BundleContext)28 Hashtable (java.util.Hashtable)26 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)23 Activate (org.apache.felix.scr.annotations.Activate)20 IContainerManager (org.eclipse.ecf.core.IContainerManager)20 Bundle (org.osgi.framework.Bundle)19 LogService (org.osgi.service.log.LogService)17 Dictionary (java.util.Dictionary)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 IOException (java.io.IOException)11 Test (org.junit.Test)10 ConfigurationException (org.osgi.service.cm.ConfigurationException)10 Map (java.util.Map)7 List (java.util.List)6 Properties (java.util.Properties)6