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);
}
}
};
}
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();
}
});
}
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);
}
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);
}
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();
}
Aggregations