Search in sources :

Example 61 with BundleContext

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

the class Activator method start.

@Override
public void start(BundleContext context) throws Exception {
    this.context = context;
    synchronized (this) {
        open = true;
    }
    Dictionary<String, Object> properties = getMSProperties();
    logger.info("Registering for configuration updates {}", properties);
    ManagedService service = c -> configurationUpdated(c, false);
    msReg = context.registerService(ManagedService.class, service, properties);
    new Thread(() -> {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
        }
        configurationUpdated(null, true);
    }).start();
}
Also used : ManagedService(org.osgi.service.cm.ManagedService) Logger(org.slf4j.Logger) Constants(org.osgi.framework.Constants) Enumeration(java.util.Enumeration) BundleActivator(org.osgi.framework.BundleActivator) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TransactionControl(org.osgi.service.transaction.control.TransactionControl) BundleContext(org.osgi.framework.BundleContext) Map(java.util.Map) RECREATE(org.apache.aries.tx.control.service.xa.impl.Activator.ChangeType.RECREATE) ManagedService(org.osgi.service.cm.ManagedService) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 62 with BundleContext

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

the class DefaultWorker method clearBundles.

private void clearBundles(Bundle b) {
    // we have been told about the system bundle, so we need to clear up any state for this framework.
    BundleContext ctx = b.getBundleContext();
    ctx.removeBundleListener(this);
    Bundle[] bundles = ctx.getBundles();
    for (Bundle bundle : bundles) {
        remove(bundle);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleContext(org.osgi.framework.BundleContext)

Example 63 with BundleContext

use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.

the class BaseDocumentDiscoveryLiteServiceTest method createInstance.

SimplifiedInstance createInstance(DocumentNodeStore ns, String workingDir) throws NoSuchFieldException {
    DocumentDiscoveryLiteService discoveryLite = new DocumentDiscoveryLiteService();
    PrivateAccessor.setField(discoveryLite, "nodeStore", ns);
    BundleContext bc = mock(BundleContext.class);
    ComponentContext c = mock(ComponentContext.class);
    when(c.getBundleContext()).thenReturn(bc);
    final Map<String, Object> registeredServices = new HashMap<String, Object>();
    when(bc.registerService(anyString(), anyObject(), (Properties) anyObject())).then(new Answer<ServiceRegistration>() {

        @Override
        public ServiceRegistration answer(InvocationOnMock invocation) {
            registeredServices.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
            return null;
        }
    });
    discoveryLite.activate(c);
    Descriptors d = (Descriptors) registeredServices.get(Descriptors.class.getName());
    final SimplifiedInstance result = new SimplifiedInstance(discoveryLite, ns, d, registeredServices, 500, workingDir);
    allInstances.add(result);
    logger.info("Created " + result);
    return result;
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyObject(org.mockito.Matchers.anyObject) JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject) Descriptors(org.apache.jackrabbit.oak.api.Descriptors) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 64 with BundleContext

use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.

the class DocumentDiscoveryLiteServiceTest method testActivateDeactivate.

@Test
public void testActivateDeactivate() throws Exception {
    // then test normal start with a DocumentNodeStore
    DocumentMK mk1 = createMK(1, 0);
    DocumentDiscoveryLiteService discoveryLite = new DocumentDiscoveryLiteService();
    PrivateAccessor.setField(discoveryLite, "nodeStore", mk1.nodeStore);
    BundleContext bc = mock(BundleContext.class);
    ComponentContext c = mock(ComponentContext.class);
    when(c.getBundleContext()).thenReturn(bc);
    discoveryLite.activate(c);
    verify(c, times(0)).disableComponent(DocumentDiscoveryLiteService.COMPONENT_NAME);
    discoveryLite.deactivate();
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 65 with BundleContext

use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.

the class ExternalPrincipalConfigurationTest method testRemoveSyncHandler.

@Test
public void testRemoveSyncHandler() throws Exception {
    Dictionary<String, Object> enableProps = new Hashtable(ImmutableMap.<String, Object>of(DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP, true));
    Dictionary<String, Object> disableProps = new Hashtable(ImmutableMap.<String, Object>of(DefaultSyncConfigImpl.PARAM_USER_DYNAMIC_MEMBERSHIP, false));
    DefaultSyncHandler sh = new DefaultSyncHandler();
    BundleContext bundleContext = context.bundleContext();
    ServiceRegistration registration1 = bundleContext.registerService(SyncHandler.class.getName(), sh, enableProps);
    ServiceRegistration registration2 = bundleContext.registerService(SyncHandler.class.getName(), sh, enableProps);
    ServiceRegistration registration3 = bundleContext.registerService(SyncHandler.class.getName(), sh, disableProps);
    assertIsEnabled(principalConfiguration, true);
    registration2.unregister();
    assertIsEnabled(principalConfiguration, true);
    registration1.unregister();
    assertIsEnabled(principalConfiguration, false);
    registration3.unregister();
    assertIsEnabled(principalConfiguration, false);
}
Also used : SyncHandler(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncHandler) DefaultSyncHandler(org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler) Hashtable(java.util.Hashtable) DefaultSyncHandler(org.apache.jackrabbit.oak.spi.security.authentication.external.impl.DefaultSyncHandler) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

BundleContext (org.osgi.framework.BundleContext)433 Test (org.junit.Test)188 ServiceReference (org.osgi.framework.ServiceReference)124 Bundle (org.osgi.framework.Bundle)119 Hashtable (java.util.Hashtable)72 ArrayList (java.util.ArrayList)39 ServiceRegistration (org.osgi.framework.ServiceRegistration)38 Dictionary (java.util.Dictionary)29 HashMap (java.util.HashMap)28 Matchers.anyString (org.mockito.Matchers.anyString)28 File (java.io.File)23 Before (org.junit.Before)23 URL (java.net.URL)21 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)20 IOException (java.io.IOException)19 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)18 MimeTypeToTransformerMapper (ddf.mime.MimeTypeToTransformerMapper)15 Map (java.util.Map)15 Configuration (org.osgi.service.cm.Configuration)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13