Search in sources :

Example 81 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class IgniteProcessProxy method close.

/**
 * {@inheritDoc}
 */
@Override
public void close() throws IgniteException {
    if (locJvmGrid != null) {
        final CountDownLatch rmtNodeStoppedLatch = new CountDownLatch(1);
        locJvmGrid.events().localListen(new IgnitePredicateX<Event>() {

            @Override
            public boolean applyx(Event e) {
                if (((DiscoveryEvent) e).eventNode().id().equals(id)) {
                    rmtNodeStoppedLatch.countDown();
                    return false;
                }
                return true;
            }
        }, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED);
        compute().run(new StopGridTask(localJvmGrid().name(), true));
        try {
            assert U.await(rmtNodeStoppedLatch, 15, TimeUnit.SECONDS) : "NodeId=" + id;
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteException(e);
        }
    }
    try {
        getProcess().kill();
    } catch (Exception e) {
        X.printerr("Could not kill process after close.", e);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) PluginNotFoundException(org.apache.ignite.plugin.PluginNotFoundException)

Example 82 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class GridEventConsumeSelfTest method testApiAsync.

/**
 * @throws Exception If failed.
 */
public void testApiAsync() throws Exception {
    IgniteEvents evt = grid(0).events();
    try {
        evt.stopRemoteListenAsync(null).get();
    } catch (NullPointerException ignored) {
    // No-op.
    }
    evt.stopRemoteListenAsync(UUID.randomUUID()).get();
    UUID consumeId = null;
    try {
        consumeId = evt.remoteListenAsync(new P2<UUID, DiscoveryEvent>() {

            @Override
            public boolean apply(UUID uuid, DiscoveryEvent evt) {
                return false;
            }
        }, new P1<DiscoveryEvent>() {

            @Override
            public boolean apply(DiscoveryEvent e) {
                return false;
            }
        }, EVTS_DISCOVERY).get();
        assertNotNull(consumeId);
    } finally {
        evt.stopRemoteListenAsync(consumeId).get();
    }
    try {
        consumeId = evt.remoteListenAsync(new P2<UUID, DiscoveryEvent>() {

            @Override
            public boolean apply(UUID uuid, DiscoveryEvent evt) {
                return false;
            }
        }, new P1<DiscoveryEvent>() {

            @Override
            public boolean apply(DiscoveryEvent e) {
                return false;
            }
        }).get();
        assertNotNull(consumeId);
    } finally {
        evt.stopRemoteListenAsync(consumeId).get();
    }
    try {
        consumeId = evt.remoteListenAsync(new P2<UUID, Event>() {

            @Override
            public boolean apply(UUID uuid, Event evt) {
                return false;
            }
        }, new P1<Event>() {

            @Override
            public boolean apply(Event e) {
                return false;
            }
        }).get();
        assertNotNull(consumeId);
    } finally {
        evt.stopRemoteListenAsync(consumeId).get();
    }
}
Also used : IgniteEvents(org.apache.ignite.IgniteEvents) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) UUID(java.util.UUID)

Example 83 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class GridEventConsumeSelfTest method testMasterNodeLeave.

/**
 * @throws Exception If failed.
 */
public void testMasterNodeLeave() throws Exception {
    final CountDownLatch latch = new CountDownLatch(GRID_CNT);
    Ignite g = startGrid("anotherGrid");
    try {
        final UUID nodeId = g.cluster().localNode().id();
        for (int i = 0; i < GRID_CNT; i++) {
            grid(i).events().localListen(new IgnitePredicate<Event>() {

                @Override
                public boolean apply(Event evt) {
                    if (nodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
                        latch.countDown();
                    return true;
                }
            }, EVT_NODE_LEFT, EVT_NODE_FAILED);
        }
        g.events().remoteListen(null, new P1<Event>() {

            @Override
            public boolean apply(Event evt) {
                return true;
            }
        }, EVTS_ALL);
    } finally {
        stopGrid("anotherGrid");
    }
    assert latch.await(3000, MILLISECONDS);
}
Also used : DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)83 Event (org.apache.ignite.events.Event)54 UUID (java.util.UUID)39 ClusterNode (org.apache.ignite.cluster.ClusterNode)32 CountDownLatch (java.util.concurrent.CountDownLatch)24 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)24 Ignite (org.apache.ignite.Ignite)23 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)11 List (java.util.List)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 JobEvent (org.apache.ignite.events.JobEvent)8 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)7 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)7 IgniteException (org.apache.ignite.IgniteException)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)6