Search in sources :

Example 6 with SleepingMillisIdleStrategy

use of org.agrona.concurrent.SleepingMillisIdleStrategy in project Aeron by real-logic.

the class NameReResolutionTest method shouldReportErrorOnReResolveFailure.

@SlowTest
@Test
@InterruptAfter(20)
void shouldReportErrorOnReResolveFailure() throws IOException {
    systemTestWatcher.ignoreErrorsMatching((s) -> s.contains("Unable to resolve host"));
    buffer.putInt(0, 1);
    subscription = client.addSubscription(FIRST_SUBSCRIPTION_URI, STREAM_ID);
    publication = client.addPublication(PUBLICATION_WITH_ERROR_URI, STREAM_ID);
    final long initialErrorCount = client.countersReader().getCounterValue(SystemCounterDescriptor.ERRORS.id());
    while (!subscription.isConnected()) {
        Tests.yieldingIdle("No connect to first subscription");
    }
    while (publication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        Tests.yieldingIdle("No message offer to first subscription");
    }
    while (subscription.poll(handler, 1) <= 0) {
        Tests.yieldingIdle("No message received on first subscription");
    }
    subscription.close();
    assertTrue(updateNameResolutionStatus(countersReader, ENDPOINT_WITH_ERROR_NAME, USE_RE_RESOLUTION_HOST));
    // wait for disconnect to ensure we stay in lock step
    while (publication.isConnected()) {
        Tests.sleep(10);
    }
    Tests.awaitCounterDelta(client.countersReader(), SystemCounterDescriptor.ERRORS.id(), initialErrorCount, 1);
    final Matcher<String> exceptionMessageMatcher = containsString("endpoint=" + ENDPOINT_WITH_ERROR_NAME);
    SystemTests.waitForErrorToOccur(client.context().aeronDirectoryName(), exceptionMessageMatcher, new SleepingMillisIdleStrategy(100));
}
Also used : SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.jupiter.api.Test)

Example 7 with SleepingMillisIdleStrategy

use of org.agrona.concurrent.SleepingMillisIdleStrategy in project aeron by real-logic.

the class FileReceiver method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
public static void main(final String[] args) {
    final File storageDir;
    if (args.length > 1) {
        storageDir = new File(args[0]);
        if (!storageDir.isDirectory()) {
            System.out.println(args[0] + " is not a directory");
            System.exit(1);
        }
    } else {
        storageDir = new File(SystemUtil.tmpDirName());
    }
    System.out.println("Files stored to " + storageDir.getAbsolutePath());
    final IdleStrategy idleStrategy = new SleepingMillisIdleStrategy(1);
    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));
    try (MediaDriver mediaDriver = MediaDriver.launch();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
        System.out.println("Receiving from " + CHANNEL + " on stream id " + STREAM_ID);
        final FileReceiver fileReceiver = new FileReceiver(storageDir, subscription);
        while (running.get()) {
            idleStrategy.idle(fileReceiver.doWork());
        }
    }
}
Also used : SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) MediaDriver(io.aeron.driver.MediaDriver) Subscription(io.aeron.Subscription) File(java.io.File) Aeron(io.aeron.Aeron)

Example 8 with SleepingMillisIdleStrategy

use of org.agrona.concurrent.SleepingMillisIdleStrategy in project aeron by real-logic.

the class AgentBuilderListener method startLogging.

private static synchronized void startLogging(final AgentBuilder.RedefinitionStrategy redefinitionStrategy, final Instrumentation instrumentation, final EnumMap<ConfigOption, String> configOptions) {
    if (null != logTransformer) {
        throw new IllegalStateException("agent already instrumented");
    }
    EventConfiguration.init(configOptions.get(ENABLED_DRIVER_EVENT_CODES), configOptions.get(DISABLED_DRIVER_EVENT_CODES), configOptions.get(ENABLED_ARCHIVE_EVENT_CODES), configOptions.get(DISABLED_ARCHIVE_EVENT_CODES), configOptions.get(ENABLED_CLUSTER_EVENT_CODES), configOptions.get(DISABLED_CLUSTER_EVENT_CODES));
    if (DRIVER_EVENT_CODES.isEmpty() && ARCHIVE_EVENT_CODES.isEmpty() && CLUSTER_EVENT_CODES.isEmpty()) {
        return;
    }
    EventLogAgent.instrumentation = instrumentation;
    readerAgentRunner = new AgentRunner(new SleepingMillisIdleStrategy(SLEEP_PERIOD_MS), Throwable::printStackTrace, null, newReaderAgent(configOptions));
    AgentBuilder agentBuilder = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED)).disableClassFormatChanges().with(new AgentBuilderListener()).with(redefinitionStrategy);
    agentBuilder = addDriverInstrumentation(agentBuilder);
    agentBuilder = addArchiveInstrumentation(agentBuilder);
    agentBuilder = addClusterInstrumentation(agentBuilder);
    logTransformer = agentBuilder.installOn(instrumentation);
    thread = new Thread(readerAgentRunner);
    thread.setName("event-log-reader");
    thread.setDaemon(true);
    thread.start();
}
Also used : SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy) AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) AgentRunner(org.agrona.concurrent.AgentRunner) ByteBuddy(net.bytebuddy.ByteBuddy)

Aggregations

SleepingMillisIdleStrategy (org.agrona.concurrent.SleepingMillisIdleStrategy)8 ByteBuddy (net.bytebuddy.ByteBuddy)3 AgentBuilder (net.bytebuddy.agent.builder.AgentBuilder)3 AgentRunner (org.agrona.concurrent.AgentRunner)3 IdleStrategy (org.agrona.concurrent.IdleStrategy)3 Aeron (io.aeron.Aeron)2 Subscription (io.aeron.Subscription)2 MediaDriver (io.aeron.driver.MediaDriver)2 File (java.io.File)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.jupiter.api.Test)2 RecordingEventsPoller (io.aeron.archive.client.RecordingEventsPoller)1