Search in sources :

Example 26 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project aeron by real-logic.

the class ReplicationSession method replay.

private int replay() {
    int workCount = 0;
    if (NULL_VALUE == activeCorrelationId) {
        final String resolvedEndpoint = recordingSubscription.resolvedEndpoint();
        if (null == resolvedEndpoint) {
            if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
                throw new TimeoutException("failed to resolve subscription endpoint: channel=" + recordingSubscription.channel());
            }
            return workCount;
        }
        final ChannelUri channelUri = ChannelUri.parse(replicationChannel);
        channelUri.put(CommonContext.SESSION_ID_PARAM_NAME, Integer.toString(replaySessionId));
        final String endpoint = channelUri.get(CommonContext.ENDPOINT_PARAM_NAME);
        if (null != endpoint && endpoint.endsWith(":0")) {
            final int i = resolvedEndpoint.lastIndexOf(':');
            channelUri.put(CommonContext.ENDPOINT_PARAM_NAME, endpoint.substring(0, endpoint.length() - 2) + resolvedEndpoint.substring(i));
        }
        if (null != liveDestination) {
            channelUri.put(CommonContext.LINGER_PARAM_NAME, "0");
            channelUri.put(CommonContext.EOS_PARAM_NAME, "false");
        }
        final long correlationId = aeron.nextCorrelationId();
        if (srcArchive.archiveProxy().replay(srcRecordingId, replayPosition, NULL_POSITION == dstStopPosition ? AeronArchive.NULL_LENGTH : dstStopPosition - replayPosition, channelUri.toString(), replayStreamId, correlationId, srcArchive.controlSessionId())) {
            workCount += trackAction(correlationId);
        } else if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
            throw new TimeoutException("failed to send replay request");
        }
    } else {
        final ControlResponsePoller poller = srcArchive.controlResponsePoller();
        workCount += poller.poll();
        if (hasResponse(poller)) {
            srcReplaySessionId = poller.relevantId();
            state(State.AWAIT_IMAGE);
        } else if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
            throw new TimeoutException("failed get acknowledgement of replay request to: " + replicationChannel);
        }
    }
    return workCount;
}
Also used : TimeoutException(io.aeron.exceptions.TimeoutException)

Example 27 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project aeron by real-logic.

the class ReplicationSession method awaitImage.

private int awaitImage() {
    int workCount = 0;
    image = recordingSubscription.imageBySessionId(replaySessionId);
    if (null != image) {
        state(null == liveDestination ? State.REPLICATE : State.CATCHUP);
        workCount += 1;
    } else if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
        throw new TimeoutException("failed get replay image for sessionId " + replaySessionId + " on channel " + recordingSubscription.channel());
    }
    return workCount;
}
Also used : TimeoutException(io.aeron.exceptions.TimeoutException)

Example 28 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project aeron by real-logic.

the class TestCluster method connectClient.

public AeronCluster connectClient(final AeronCluster.Context clientCtx) {
    final String aeronDirName = CommonContext.getAeronDirectoryName();
    if (null == clientMediaDriver) {
        dataCollector.add(Paths.get(aeronDirName));
        final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(false).aeronDirectoryName(aeronDirName).nameResolver(new RedirectingNameResolver(nodeNameMappings()));
        clientMediaDriver = MediaDriver.launch(ctx);
    }
    clientCtx.aeronDirectoryName(aeronDirName).isIngressExclusive(true).egressListener(egressListener).controlledEgressListener(controlledEgressListener).ingressEndpoints(staticClusterMemberEndpoints);
    try {
        CloseHelper.close(client);
        client = AeronCluster.connect(clientCtx.clone());
    } catch (final TimeoutException ex) {
        System.out.println("Warning: " + ex);
        CloseHelper.close(client);
        client = AeronCluster.connect(clientCtx);
    }
    return client;
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) TimeoutException(io.aeron.exceptions.TimeoutException)

Example 29 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project aeron by real-logic.

the class TestCluster method awaitServiceState.

public void awaitServiceState(final TestNode node, final Predicate<TestNode> predicate) {
    final EpochClock epochClock = client.context().aeron().context().epochClock();
    long keepAliveDeadlineMs = epochClock.time() + TimeUnit.SECONDS.toMillis(1);
    while (!predicate.test(node)) {
        Thread.yield();
        if (Thread.interrupted()) {
            throw new TimeoutException("timeout while awaiting condition");
        }
        final long nowMs = epochClock.time();
        if (nowMs > keepAliveDeadlineMs) {
            client.sendKeepAlive();
            keepAliveDeadlineMs = nowMs + TimeUnit.SECONDS.toMillis(1);
        }
    }
}
Also used : EpochClock(org.agrona.concurrent.EpochClock) TimeoutException(io.aeron.exceptions.TimeoutException)

Example 30 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project aeron by real-logic.

the class TestCluster method awaitServiceMessageCount.

public void awaitServiceMessageCount(final TestNode node, final int messageCount) {
    final TestNode.TestService service = node.service();
    final EpochClock epochClock = client.context().aeron().context().epochClock();
    long keepAliveDeadlineMs = epochClock.time() + TimeUnit.SECONDS.toMillis(1);
    long count;
    while ((count = service.messageCount()) < messageCount) {
        Thread.yield();
        if (Thread.interrupted()) {
            throw new TimeoutException("count=" + count + " awaiting=" + messageCount + " node=" + node);
        }
        if (service.hasReceivedUnexpectedMessage()) {
            fail("service received unexpected message");
        }
        final long nowMs = epochClock.time();
        if (nowMs > keepAliveDeadlineMs) {
            client.sendKeepAlive();
            keepAliveDeadlineMs = nowMs + TimeUnit.SECONDS.toMillis(1);
        }
    }
}
Also used : EpochClock(org.agrona.concurrent.EpochClock) TimeoutException(io.aeron.exceptions.TimeoutException)

Aggregations

TimeoutException (io.aeron.exceptions.TimeoutException)31 EpochClock (org.agrona.concurrent.EpochClock)4 ClusterException (io.aeron.cluster.client.ClusterException)2 MediaDriver (io.aeron.driver.MediaDriver)2 RedirectingNameResolver (io.aeron.test.driver.RedirectingNameResolver)2 AgentTerminationException (org.agrona.concurrent.AgentTerminationException)2 ReadableCounter (io.aeron.status.ReadableCounter)1