Search in sources :

Example 1 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project camel by apache.

the class IgniteMessagingEndpoint method createIgniteMessaging.

private IgniteMessaging createIgniteMessaging() {
    Ignite ignite = ignite();
    IgniteMessaging messaging = clusterGroupExpression == null ? ignite.message() : ignite.message(clusterGroupExpression.getClusterGroup(ignite));
    return messaging;
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging) Ignite(org.apache.ignite.Ignite)

Example 2 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project camel by apache.

the class IgniteMessagingEndpoint method createConsumer.

@Override
public Consumer createConsumer(Processor processor) throws Exception {
    // Validate options.
    if (topic == null) {
        throw new IllegalStateException("Cannot initialize an Ignite Messaging Consumer with a null topic.");
    }
    // Initialize the Consumer.
    IgniteMessaging messaging = createIgniteMessaging();
    IgniteMessagingConsumer consumer = new IgniteMessagingConsumer(this, processor, messaging);
    configureConsumer(consumer);
    return consumer;
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging)

Example 3 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project ignite by apache.

the class MessagingSandboxTest method execute.

/**
 */
private void execute(Ignite node, BiFunction<IgniteMessaging, String, UUID> func, boolean isForbiddenCase) {
    final String topic = "test_topic";
    IgniteMessaging messaging = node.message(node.cluster().forNodeId(grid(SRV).localNode().id()));
    UUID listenerId = func.apply(messaging, topic);
    try {
        GridTestUtils.RunnableX r = () -> {
            error = null;
            latch = new CountDownLatch(1);
            grid(SRV_SENDER).message().send(topic, "Hello!");
            latch.await(10, TimeUnit.SECONDS);
            if (error != null)
                throw error;
        };
        if (isForbiddenCase)
            runForbiddenOperation(r, AccessControlException.class);
        else
            runOperation(r);
    } finally {
        messaging.stopRemoteListen(listenerId);
    }
}
Also used : GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteMessaging(org.apache.ignite.IgniteMessaging) AccessControlException(java.security.AccessControlException) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project ignite by apache.

the class MessagingRemoteSecurityContextCheckTest method execute.

/**
 */
private void execute(BiFunction<IgniteMessaging, String, UUID> func) {
    runAndCheck(() -> {
        Ignite loc = Ignition.localIgnite();
        IgniteMessaging messaging = loc.message(loc.cluster().forNodeIds(nodesToCheckIds()));
        Integer idx = TOPIC_INDEX.incrementAndGet();
        String topic = "test_topic_" + idx;
        UUID id = func.apply(messaging, topic);
        try {
            grid(SRV).message().send(topic, idx);
            wait(idx);
        } finally {
            messaging.stopRemoteListen(id);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteMessaging(org.apache.ignite.IgniteMessaging) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Example 5 with IgniteMessaging

use of org.apache.ignite.IgniteMessaging in project ignite by apache.

the class GridMessagingSelfTest method testAsyncOld.

/**
 * @throws Exception If failed.
 */
@Test
public void testAsyncOld() throws Exception {
    final AtomicInteger msgCnt = new AtomicInteger();
    IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi) ignite2.configuration().getDiscoverySpi();
    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
    discoSpi.setInternalListener(lsnr);
    assertFalse(ignite2.message().isAsync());
    final IgniteMessaging msg = ignite2.message().withAsync();
    assertTrue(msg.isAsync());
    assertFalse(ignite2.message().isAsync());
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);
    final String topic = "topic";
    UUID id = msg.remoteListen(topic, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt.incrementAndGet();
            return true;
        }
    });
    Assert.assertNull(id);
    IgniteFuture<UUID> starFut = msg.future();
    Assert.assertNotNull(starFut);
    U.sleep(500);
    Assert.assertFalse(starFut.isDone());
    lsnr.stopBlockCustomEvents();
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    id = starFut.get();
    Assert.assertNotNull(id);
    Assert.assertTrue(starFut.isDone());
    lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);
    message(ignite1.cluster().forRemotes()).send(topic, "msg1");
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return msgCnt.get() > 0;
        }
    }, 5000);
    assertEquals(1, msgCnt.get());
    msg.stopRemoteListen(id);
    IgniteFuture<?> stopFut = msg.future();
    Assert.assertNotNull(stopFut);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    U.sleep(500);
    Assert.assertFalse(stopFut.isDone());
    lsnr.stopBlockCustomEvents();
    stopFut.get();
    Assert.assertTrue(stopFut.isDone());
    message(ignite1.cluster().forRemotes()).send(topic, "msg2");
    U.sleep(1000);
    assertEquals(1, msgCnt.get());
}
Also used : IOException(java.io.IOException) PA(org.apache.ignite.internal.util.typedef.PA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteMessaging(org.apache.ignite.IgniteMessaging) DiscoverySpiTestListener(org.apache.ignite.internal.DiscoverySpiTestListener) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteMessaging (org.apache.ignite.IgniteMessaging)12 UUID (java.util.UUID)7 Ignite (org.apache.ignite.Ignite)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)3 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 Externalizable (java.io.Externalizable)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 AccessControlException (java.security.AccessControlException)1 Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1