use of org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter in project ignite by apache.
the class ScheduleFutureImpl method schedule.
/**
* Sets execution task.
*
* @param task Execution task.
*/
void schedule(Callable<R> task) {
assert task != null;
assert this.task == null;
// Done future on this step means that there was error on init.
if (isDone())
return;
this.task = task;
((IgniteScheduleProcessor) ctx.schedule()).onScheduled(this);
if (delay > 0) {
// Schedule after delay.
ctx.timeout().addTimeoutObject(new GridTimeoutObjectAdapter(delay * 1000) {
@Override
public void onTimeout() {
assert id == null;
try {
id = sched.schedule(cron, run);
} catch (InvalidPatternException e) {
// This should never happen as we validated the pattern during parsing.
e.printStackTrace();
assert false : "Invalid scheduling pattern: " + cron;
}
}
});
} else {
assert id == null;
try {
id = sched.schedule(cron, run);
} catch (InvalidPatternException e) {
// This should never happen as we validated the pattern during parsing.
e.printStackTrace();
assert false : "Invalid scheduling pattern: " + cron;
}
}
}
use of org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter in project ignite by apache.
the class TcpCommunicationHandshakeTimeoutTest method testSocketForcedClosedBecauseSlowReadFromSocket.
/**
* 1. Cluster from three nodes.
* 2. Waiting when communication connection goes idle.
* 4. Configure the delay during the communication connection handshake.
* 5. Force establishing of new connection from node2 to node1 from timeout object processor thread
* (it use compute in this test).
* 6. Expected: The frozen attempt of handshake would be successfully handled and a new connection
* would be established.
*
* @throws Exception If fail.
*/
@Test
public void testSocketForcedClosedBecauseSlowReadFromSocket() throws Exception {
// given: Two ordinary nodes.
startGrid(0);
IgniteEx g1 = startGrid(1);
// and: One more node which communication connection can be delayed by demand.
AtomicBoolean delayHandshakeUntilSocketClosed = new AtomicBoolean();
IgniteEx g2 = startGrid(2, new DependencyResolver() {
@Override
public <T> T resolve(T instance) {
if (instance instanceof TcpHandshakeExecutor) {
TcpHandshakeExecutor gridNioServer = (TcpHandshakeExecutor) instance;
return (T) new DelaydTcpHandshakeExecutor(gridNioServer, delayHandshakeUntilSocketClosed);
}
return instance;
}
});
awaitPartitionMapExchange();
AtomicBoolean result = new AtomicBoolean(false);
// Wait for connections go idle.
doSleep(1000);
// when: Initiate communication connection from timeout object processor thread.
g2.context().timeout().addTimeoutObject(new GridTimeoutObjectAdapter(0) {
@Override
public void onTimeout() {
delayHandshakeUntilSocketClosed.set(true);
g2.compute(g2.cluster().forNodes(Arrays.asList(g1.localNode()))).withNoFailover().call(() -> true);
result.set(true);
}
});
// then: Despite the first attempt of handshake would be frozen the compute should be handled well eventually.
assertTrue("Compute should be successfully handled.", waitForCondition(result::get, 20_000));
}
Aggregations