use of org.apache.ignite.spi.IgniteSpiAdapter in project ignite by apache.
the class GridManagerAdapter method startSpi.
/**
* Starts wrapped SPI.
*
* @throws IgniteCheckedException If wrapped SPI could not be started.
*/
protected final void startSpi() throws IgniteCheckedException {
Collection<String> names = U.newHashSet(spis.length);
for (T spi : spis) {
if (spi instanceof IgniteSpiAdapter)
((IgniteSpiAdapter) spi).onBeforeStart();
// Save SPI to map to make sure to stop it properly.
Boolean res = spiMap.put(spi, Boolean.TRUE);
assert res == null;
if (!injected) {
// Inject all spi resources.
ctx.resource().inject(spi);
// Inject SPI internal objects.
inject(spi);
}
// Print-out all SPI parameters only in DEBUG mode.
if (log.isDebugEnabled())
log.debug("Starting SPI: " + spi);
if (names.contains(spi.getName()))
throw new IgniteCheckedException("Duplicate SPI name (need to explicitly configure 'setName()' property): " + spi.getName());
names.add(spi.getName());
if (log.isDebugEnabled())
log.debug("Starting SPI implementation: " + spi.getClass().getName());
onBeforeSpiStart();
try {
spi.spiStart(ctx.igniteInstanceName());
} catch (IgniteSpiException e) {
throw new IgniteCheckedException("Failed to start SPI: " + spi, e);
}
onAfterSpiStart();
parseNodeAttributes(spi);
if (log.isDebugEnabled())
log.debug("SPI module started OK: " + spi.getClass().getName());
}
injected = true;
}
use of org.apache.ignite.spi.IgniteSpiAdapter in project ignite by apache.
the class GridManagerLocalMessageListenerSelfTest method testSendMessage.
/**
* @throws Exception If failed.
*/
@Test
public void testSendMessage() throws Exception {
startGridsMultiThreaded(2);
IgniteSpiContext ctx0 = ((IgniteSpiAdapter) grid(0).context().io().getSpi()).getSpiContext();
IgniteSpiContext ctx1 = ((IgniteSpiAdapter) grid(1).context().io().getSpi()).getSpiContext();
String topic = "test-topic";
final CountDownLatch latch = new CountDownLatch(1);
ctx1.addLocalMessageListener(topic, new IgniteBiPredicate<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
assertEquals("Message", msg);
latch.countDown();
return true;
}
});
long time = System.nanoTime();
ctx0.send(grid(1).localNode(), "Message", topic);
assert latch.await(3, SECONDS);
time = System.nanoTime() - time;
info(">>>");
info(">>> send() time (ms): " + MILLISECONDS.convert(time, NANOSECONDS));
info(">>>");
}
Aggregations