Search in sources :

Example 1 with Registration

use of org.apache.jackrabbit.oak.spi.whiteboard.Registration in project jackrabbit-oak by apache.

the class OsgiWhiteboard method register.

@Override
public <T> Registration register(final Class<T> type, final T service, Map<?, ?> properties) {
    checkNotNull(type);
    checkNotNull(service);
    checkNotNull(properties);
    checkArgument(type.isInstance(service));
    Dictionary<Object, Object> dictionary = new Hashtable<Object, Object>();
    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        dictionary.put(entry.getKey(), entry.getValue());
    }
    final ServiceRegistration registration = context.registerService(type.getName(), service, dictionary);
    return new Registration() {

        private volatile boolean unregistered;

        @Override
        public void unregister() {
            try {
                if (!unregistered) {
                    registration.unregister();
                    unregistered = true;
                } else {
                    log.warn("Service {} of type {} unregistered multiple times", service, type);
                }
            } catch (IllegalStateException ex) {
                log.warn("Error unregistering service: {} of type {}", service, type.getName(), ex);
            }
        }
    };
}
Also used : Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) Map(java.util.Map) Maps.newTreeMap(com.google.common.collect.Maps.newTreeMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) SortedMap(java.util.SortedMap) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with Registration

use of org.apache.jackrabbit.oak.spi.whiteboard.Registration in project jackrabbit-oak by apache.

the class AsyncIndexerService method registerAsyncReindexSupport.

private void registerAsyncReindexSupport(Whiteboard whiteboard) {
    // async reindex
    String name = IndexConstants.ASYNC_REINDEX_VALUE;
    AsyncIndexUpdate task = new AsyncIndexUpdate(name, nodeStore, indexEditorProvider, statisticsProvider, true);
    PropertyIndexAsyncReindex asyncPI = new PropertyIndexAsyncReindex(task, executor);
    final Registration reg = new CompositeRegistration(registerMBean(whiteboard, PropertyIndexAsyncReindexMBean.class, asyncPI, PropertyIndexAsyncReindexMBean.TYPE, "async"), registerMBean(whiteboard, IndexStatsMBean.class, task.getIndexStats(), IndexStatsMBean.TYPE, name));
    closer.register(new Closeable() {

        @Override
        public void close() throws IOException {
            reg.unregister();
        }
    });
}
Also used : CompositeRegistration(org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) IndexStatsMBean(org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean) Closeable(java.io.Closeable) PropertyIndexAsyncReindex(org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindex) IOException(java.io.IOException) CompositeRegistration(org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration) PropertyIndexAsyncReindexMBean(org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindexMBean)

Example 3 with Registration

use of org.apache.jackrabbit.oak.spi.whiteboard.Registration in project jackrabbit-oak by apache.

the class SegmentCompactionIT method setUp.

@Before
public void setUp() throws Exception {
    assumeTrue(ENABLED);
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    MetricStatisticsProvider statisticsProvider = new MetricStatisticsProvider(mBeanServer, executor);
    SegmentGCOptions gcOptions = defaultGCOptions().setEstimationDisabled(true).setForceTimeout(3600);
    FileStoreBuilder builder = fileStoreBuilder(folder.getRoot());
    fileStore = builder.withMemoryMapping(true).withGCMonitor(gcMonitor).withGCOptions(gcOptions).withIOMonitor(new MetricsIOMonitor(statisticsProvider)).withStatisticsProvider(statisticsProvider).build();
    nodeStore = SegmentNodeStoreBuilders.builder(fileStore).withStatisticsProvider(statisticsProvider).build();
    WriterCacheManager cacheManager = builder.getCacheManager();
    Runnable cancelGC = new Runnable() {

        @Override
        public void run() {
            fileStore.cancelGC();
        }
    };
    Supplier<String> status = new Supplier<String>() {

        @Override
        public String get() {
            return fileStoreGCMonitor.getStatus();
        }
    };
    List<Registration> registrations = newArrayList();
    registrations.add(registerMBean(segmentCompactionMBean, new ObjectName("IT:TYPE=Segment Compaction")));
    registrations.add(registerMBean(new SegmentRevisionGCMBean(fileStore, gcOptions, fileStoreGCMonitor), new ObjectName("IT:TYPE=Segment Revision GC")));
    registrations.add(registerMBean(new RevisionGC(fileStore.getGCRunner(), cancelGC, status, executor), new ObjectName("IT:TYPE=Revision GC")));
    CacheStatsMBean segmentCacheStats = fileStore.getSegmentCacheStats();
    registrations.add(registerMBean(segmentCacheStats, new ObjectName("IT:TYPE=" + segmentCacheStats.getName())));
    CacheStatsMBean stringCacheStats = fileStore.getStringCacheStats();
    registrations.add(registerMBean(stringCacheStats, new ObjectName("IT:TYPE=" + stringCacheStats.getName())));
    CacheStatsMBean templateCacheStats = fileStore.getTemplateCacheStats();
    registrations.add(registerMBean(templateCacheStats, new ObjectName("IT:TYPE=" + templateCacheStats.getName())));
    CacheStatsMBean stringDeduplicationCacheStats = cacheManager.getStringCacheStats();
    assertNotNull(stringDeduplicationCacheStats);
    registrations.add(registerMBean(stringDeduplicationCacheStats, new ObjectName("IT:TYPE=" + stringDeduplicationCacheStats.getName())));
    CacheStatsMBean templateDeduplicationCacheStats = cacheManager.getTemplateCacheStats();
    assertNotNull(templateDeduplicationCacheStats);
    registrations.add(registerMBean(templateDeduplicationCacheStats, new ObjectName("IT:TYPE=" + templateDeduplicationCacheStats.getName())));
    CacheStatsMBean nodeDeduplicationCacheStats = cacheManager.getNodeCacheStats();
    assertNotNull(nodeDeduplicationCacheStats);
    registrations.add(registerMBean(nodeDeduplicationCacheStats, new ObjectName("IT:TYPE=" + nodeDeduplicationCacheStats.getName())));
    registrations.add(registerMBean(nodeStore.getStats(), new ObjectName("IT:TYPE=" + "SegmentNodeStore statistics")));
    mBeanRegistration = new CompositeRegistration(registrations);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) MetricsIOMonitor(org.apache.jackrabbit.oak.segment.file.MetricsIOMonitor) ObjectName(javax.management.ObjectName) RevisionGC(org.apache.jackrabbit.oak.spi.state.RevisionGC) SegmentRevisionGC(org.apache.jackrabbit.oak.segment.compaction.SegmentRevisionGC) SegmentRevisionGCMBean(org.apache.jackrabbit.oak.segment.compaction.SegmentRevisionGCMBean) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) CompositeRegistration(org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) CacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean) MetricStatisticsProvider(org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider) Supplier(com.google.common.base.Supplier) CompositeRegistration(org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration) Before(org.junit.Before)

Example 4 with Registration

use of org.apache.jackrabbit.oak.spi.whiteboard.Registration in project jackrabbit-oak by apache.

the class LuceneIndexProviderService method deactivate.

@Deactivate
private void deactivate() throws InterruptedException, IOException {
    for (ServiceRegistration reg : regs) {
        reg.unregister();
    }
    for (Registration reg : oakRegs) {
        reg.unregister();
    }
    if (backgroundObserver != null) {
        backgroundObserver.close();
    }
    if (externalIndexObserver != null) {
        externalIndexObserver.close();
    }
    if (indexProvider != null) {
        indexProvider.close();
        indexProvider = null;
    }
    if (documentQueue != null) {
        documentQueue.close();
    }
    if (nrtIndexFactory != null) {
        nrtIndexFactory.close();
    }
    //Close the copier first i.e. before executorService
    if (indexCopier != null) {
        indexCopier.close();
    }
    if (executorService != null) {
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.MINUTES);
    }
    InfoStream.setDefault(InfoStream.NO_OUTPUT);
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) ServiceRegistration(org.osgi.framework.ServiceRegistration) Deactivate(org.apache.felix.scr.annotations.Deactivate)

Example 5 with Registration

use of org.apache.jackrabbit.oak.spi.whiteboard.Registration in project jackrabbit-oak by apache.

the class OsgiWhiteboardTest method testDoubleUnregister.

/**
     * OAK-3409
     */
@Test
public void testDoubleUnregister() {
    BundleContext bundleContext = mock(BundleContext.class);
    OsgiWhiteboard w = new OsgiWhiteboard(bundleContext);
    Runnable r = new Runnable() {

        @Override
        public void run() {
        //
        }
    };
    final AtomicBoolean unregistered = new AtomicBoolean();
    ServiceRegistration sr = new ServiceRegistration() {

        @Override
        public void unregister() {
            if (unregistered.get()) {
                throw new IllegalStateException("Service already unregistered.");
            }
            unregistered.set(true);
        }

        @Override
        public void setProperties(Dictionary properties) {
        }

        @Override
        public ServiceReference getReference() {
            return null;
        }
    };
    when(bundleContext.registerService(Runnable.class.getName(), r, new Hashtable<Object, Object>())).thenReturn(sr);
    Registration reg = w.register(Runnable.class, r, new HashMap<String, Object>());
    reg.unregister();
    assertTrue(unregistered.get());
    reg.unregister();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Dictionary(java.util.Dictionary) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) ServiceRegistration(org.osgi.framework.ServiceRegistration) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

Registration (org.apache.jackrabbit.oak.spi.whiteboard.Registration)8 CompositeRegistration (org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration)4 Closeable (java.io.Closeable)2 PropertyIndexAsyncReindex (org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindex)2 PropertyIndexAsyncReindexMBean (org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindexMBean)2 Test (org.junit.Test)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 Supplier (com.google.common.base.Supplier)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Maps.newTreeMap (com.google.common.collect.Maps.newTreeMap)1 ListeningScheduledExecutorService (com.google.common.util.concurrent.ListeningScheduledExecutorService)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 Executor (java.util.concurrent.Executor)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1