Search in sources :

Example 6 with GridTimeoutObjectAdapter

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;
        }
    }
}
Also used : InvalidPatternException(it.sauronsoftware.cron4j.InvalidPatternException) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter)

Example 7 with GridTimeoutObjectAdapter

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TcpHandshakeExecutor(org.apache.ignite.spi.communication.tcp.internal.TcpHandshakeExecutor) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridTimeoutObjectAdapter (org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter)7 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2