Search in sources :

Example 1 with SleepingMillisIdleStrategy

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

the class ArchiveReplayLoadTest method trackRecordingProgress.

private void trackRecordingProgress(final Subscription recordingEvents, final CountDownLatch recordingStopped) {
    final Thread t = new Thread(() -> {
        try {
            recordedLength = 0;
            final IdleStrategy idleStrategy = new SleepingMillisIdleStrategy(1);
            final RecordingEventsPoller poller = new RecordingEventsPoller(recordingEvents);
            while (0 == expectedRecordingLength || recordedLength < expectedRecordingLength) {
                idleStrategy.reset();
                while (poller.poll() <= 0 && !poller.isPollComplete()) {
                    idleStrategy.idle();
                }
                switch(poller.templateId()) {
                    case RecordingStartedDecoder.TEMPLATE_ID:
                        {
                            final long startPosition = poller.recordingStartPosition();
                            recordingId = poller.recordingId();
                            if (0L != startPosition) {
                                throw new IllegalStateException("expected=0 actual=" + startPosition);
                            }
                            printf("Recording started %d %n", recordingId);
                            break;
                        }
                    case RecordingProgressDecoder.TEMPLATE_ID:
                        {
                            recordedLength = poller.recordingPosition() - poller.recordingStartPosition();
                            printf("Recording progress %d %n", recordedLength);
                            break;
                        }
                }
            }
        } catch (final Throwable throwable) {
            trackerError = throwable;
        } finally {
            recordingStopped.countDown();
        }
    });
    t.setDaemon(true);
    t.start();
}
Also used : SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy) RecordingEventsPoller(io.aeron.archive.client.RecordingEventsPoller) IdleStrategy(org.agrona.concurrent.IdleStrategy) SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy)

Example 2 with SleepingMillisIdleStrategy

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

the class EventLogAgent method agent.

@SuppressWarnings("Indendation")
private static void agent(final boolean shouldRedefine, final Instrumentation instrumentation) {
    if (EventConfiguration.ENABLED_EVENT_CODES == 0) {
        return;
    }
    EventLogAgent.instrumentation = instrumentation;
    readerAgentRunner = new AgentRunner(new SleepingMillisIdleStrategy(SLEEP_PERIOD_MS), Throwable::printStackTrace, null, EVENT_LOG_READER_AGENT);
    logTransformer = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED)).with(LISTENER).disableClassFormatChanges().with(shouldRedefine ? AgentBuilder.RedefinitionStrategy.RETRANSFORMATION : AgentBuilder.RedefinitionStrategy.DISABLED).type(nameEndsWith("DriverConductor")).transform((builder, typeDescription, classLoader, javaModule) -> builder.visit(to(CleanupInterceptor.CleanupImage.class).on(named("cleanupImage"))).visit(to(CleanupInterceptor.CleanupPublication.class).on(named("cleanupPublication"))).visit(to(CleanupInterceptor.CleanupSubscriptionLink.class).on(named("cleanupSubscriptionLink")))).type(nameEndsWith("ClientCommandAdapter")).transform((builder, typeDescription, classLoader, javaModule) -> builder.visit(to(CmdInterceptor.class).on(named("onMessage")))).type(nameEndsWith("ClientProxy")).transform((builder, typeDescription, classLoader, javaModule) -> builder.visit(to(CmdInterceptor.class).on(named("transmit")))).type(nameEndsWith("SenderProxy")).transform((builder, typeDescription, classLoader, javaModule) -> builder.visit(to(ChannelEndpointInterceptor.SenderProxyInterceptor.RegisterSendChannelEndpoint.class).on(named("registerSendChannelEndpoint"))).visit(to(ChannelEndpointInterceptor.SenderProxyInterceptor.CloseSendChannelEndpoint.class).on(named("closeSendChannelEndpoint")))).type(nameEndsWith("ReceiverProxy")).transform((builder, typeDescription, classLoader, javaModule) -> builder.visit(to(ChannelEndpointInterceptor.ReceiverProxyInterceptor.RegisterReceiveChannelEndpoint.class).on(named("registerReceiveChannelEndpoint"))).visit(to(ChannelEndpointInterceptor.ReceiverProxyInterceptor.CloseReceiveChannelEndpoint.class).on(named("closeReceiveChannelEndpoint")))).type(inheritsAnnotation(EventLog.class)).transform((builder, typeDescription, classLoader, javaModule) -> builder.visit(to(ChannelEndpointInterceptor.SendChannelEndpointInterceptor.Presend.class).on(named("presend"))).visit(to(ChannelEndpointInterceptor.ReceiveChannelEndpointInterceptor.SendTo.class).on(named("sendTo"))).visit(to(ChannelEndpointInterceptor.SendChannelEndpointInterceptor.OnStatusMessage.class).on(named("onStatusMessage"))).visit(to(ChannelEndpointInterceptor.SendChannelEndpointInterceptor.OnNakMessage.class).on(named("onNakMessage"))).visit(to(ChannelEndpointInterceptor.SendChannelEndpointInterceptor.OnRttMeasurement.class).on(named("onRttMeasurement"))).visit(to(ChannelEndpointInterceptor.ReceiveChannelEndpointInterceptor.OnDataPacket.class).on(named("onDataPacket"))).visit(to(ChannelEndpointInterceptor.ReceiveChannelEndpointInterceptor.OnSetupMessage.class).on(named("onSetupMessage"))).visit(to(ChannelEndpointInterceptor.ReceiveChannelEndpointInterceptor.OnRttMeasurement.class).on(named("onRttMeasurement")))).installOn(instrumentation);
    final Thread thread = new Thread(readerAgentRunner);
    thread.setName("event log reader");
    thread.setDaemon(true);
    thread.start();
}
Also used : SleepingMillisIdleStrategy(org.agrona.concurrent.SleepingMillisIdleStrategy) ByteBuddy(net.bytebuddy.ByteBuddy) AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) AgentRunner(org.agrona.concurrent.AgentRunner)

Example 3 with SleepingMillisIdleStrategy

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

the class FileReceiver method main.

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(IoUtil.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 ignore = MediaDriver.launch();
        Aeron aeron = Aeron.connect();
        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 4 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)

Example 5 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)

Aggregations

SleepingMillisIdleStrategy (org.agrona.concurrent.SleepingMillisIdleStrategy)6 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 ByteBuddy (net.bytebuddy.ByteBuddy)2 AgentBuilder (net.bytebuddy.agent.builder.AgentBuilder)2 AgentRunner (org.agrona.concurrent.AgentRunner)2 RecordingEventsPoller (io.aeron.archive.client.RecordingEventsPoller)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.jupiter.api.Test)1