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);
}
}
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();
}
}
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);
}
Aggregations