Search in sources :

Example 46 with Subscription

use of io.aeron.Subscription 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 47 with Subscription

use of io.aeron.Subscription in project Aeron by real-logic.

the class IngressAdapter method close.

public void close() {
    final Subscription subscription = this.subscription;
    this.subscription = null;
    fragmentAssembler.clear();
    if (null != subscription) {
        subscription.close();
    }
}
Also used : Subscription(io.aeron.Subscription)

Aggregations

Subscription (io.aeron.Subscription)47 Aeron (io.aeron.Aeron)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 Publication (io.aeron.Publication)14 MediaDriver (io.aeron.driver.MediaDriver)14 FragmentAssembler (io.aeron.FragmentAssembler)12 IdleStrategy (org.agrona.concurrent.IdleStrategy)11 FragmentHandler (io.aeron.logbuffer.FragmentHandler)10 ContinueBarrier (org.agrona.console.ContinueBarrier)8 ExecutorService (java.util.concurrent.ExecutorService)5 BackoffIdleStrategy (org.agrona.concurrent.BackoffIdleStrategy)5 TimeUnit (java.util.concurrent.TimeUnit)4 SigInt (org.agrona.concurrent.SigInt)3 Test (org.junit.jupiter.api.Test)3 ExclusivePublication (io.aeron.ExclusivePublication)2 AeronArchive (io.aeron.archive.client.AeronArchive)2 Context (io.aeron.archive.client.AeronArchive.Context)2 io.aeron.logbuffer (io.aeron.logbuffer)2 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2