Search in sources :

Example 1 with IgniteSpiAdapter

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 2 with IgniteSpiAdapter

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(">>>");
}
Also used : IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteSpiAdapter (org.apache.ignite.spi.IgniteSpiAdapter)2 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteSpiContext (org.apache.ignite.spi.IgniteSpiContext)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1