use of org.apache.ignite.spi.metric.MetricExporterSpi in project ignite by apache.
the class MetricsSelfTest method testAddBeforeRemoveCompletes.
/**
*/
@Test
public void testAddBeforeRemoveCompletes() throws Exception {
MetricExporterSpi checkSpi = new NoopMetricExporterSpi() {
private ReadOnlyMetricManager registry;
private Set<String> names = new HashSet<>();
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
registry.addMetricRegistryCreationListener(mreg -> {
assertFalse(mreg.name() + " should be unique", names.contains(mreg.name()));
names.add(mreg.name());
});
registry.addMetricRegistryRemoveListener(mreg -> names.remove(mreg.name()));
}
@Override
public void setMetricRegistry(ReadOnlyMetricManager registry) {
this.registry = registry;
}
};
CountDownLatch rmvStarted = new CountDownLatch(1);
CountDownLatch rmvCompleted = new CountDownLatch(1);
MetricExporterSpi blockingSpi = new NoopMetricExporterSpi() {
private ReadOnlyMetricManager registry;
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
registry.addMetricRegistryRemoveListener(mreg -> {
rmvStarted.countDown();
try {
rmvCompleted.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}
@Override
public void setMetricRegistry(ReadOnlyMetricManager registry) {
this.registry = registry;
}
};
IgniteConfiguration cfg = new IgniteConfiguration().setMetricExporterSpi(blockingSpi, checkSpi);
GridTestKernalContext ctx = new GridTestKernalContext(log(), cfg);
ctx.start();
// Add metric registry.
ctx.metric().registry("test");
// Removes it async, blockingSpi will block remove procedure.
IgniteInternalFuture rmvFut = runAsync(() -> ctx.metric().remove("test"));
rmvStarted.await();
CountDownLatch addStarted = new CountDownLatch(1);
IgniteInternalFuture addFut = runAsync(() -> {
addStarted.countDown();
ctx.metric().registry("test");
});
// Waiting for creation to start.
addStarted.await();
Thread.sleep(100);
// Complete removal.
rmvCompleted.countDown();
rmvFut.get(getTestTimeout());
addFut.get(getTestTimeout());
}
use of org.apache.ignite.spi.metric.MetricExporterSpi in project ignite by apache.
the class GridMetricManager method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
for (MetricExporterSpi spi : getSpis()) spi.setMetricRegistry(this);
startSpi();
// In case standalone kernal start.
if (ctx.internalSubscriptionProcessor() == null)
return;
ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {
/**
* {@inheritDoc}
*/
@Override
public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
roMetastorage = metastorage;
try {
metastorage.iterate(HITRATE_CFG_PREFIX, (name, val) -> onHitRateConfigChanged(name.substring(HITRATE_CFG_PREFIX.length() + 1), (Long) val));
metastorage.iterate(HISTOGRAM_CFG_PREFIX, (name, val) -> onHistogramConfigChanged(name.substring(HISTOGRAM_CFG_PREFIX.length() + 1), (long[]) val));
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
metastorage.listen(n -> n.startsWith(HITRATE_CFG_PREFIX), (name, oldVal, newVal) -> onHitRateConfigChanged(name.substring(HITRATE_CFG_PREFIX.length() + 1), (Long) newVal));
metastorage.listen(n -> n.startsWith(HISTOGRAM_CFG_PREFIX), (name, oldVal, newVal) -> onHistogramConfigChanged(name.substring(HISTOGRAM_CFG_PREFIX.length() + 1), (long[]) newVal));
}
/**
* {@inheritDoc}
*/
@Override
public void onReadyForWrite(DistributedMetaStorage metastorage) {
GridMetricManager.this.metastorage = metastorage;
}
});
}
Aggregations