• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java BusySpinIdleStrategy类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.agrona.concurrent.BusySpinIdleStrategy的典型用法代码示例。如果您正苦于以下问题:Java BusySpinIdleStrategy类的具体用法?Java BusySpinIdleStrategy怎么用?Java BusySpinIdleStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

BusySpinIdleStrategy类属于org.agrona.concurrent包,在下文中一共展示了BusySpinIdleStrategy类的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: run

点赞 3

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Override
public void run()
{
    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
    final UnsafeBuffer buffer = new UnsafeBuffer(DirectBufferAllocator.allocateCacheAligned(MESSAGE_LENGTH));

    for (int messageNumber = 1; messageNumber <= numMessages; messageNumber++)
    {
        final long timestamp = System.nanoTime();

        buffer.putInt(0, messageNumber);
        buffer.putLong(4, timestamp);

        while (!inputRingBuffer.write(MessageTypes.APPLICATION_MSG_ID, buffer, 0, MESSAGE_LENGTH))
        {
            idleStrategy.idle(0);
        }
    }
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:20,
代码来源:JournalTest.java

示例2: main

点赞 3

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
  MediaDriver.loadPropertiesFiles(args);

  setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
  setProperty("aeron.mtu.length", "16384");
  setProperty("aeron.socket.so_sndbuf", "2097152");
  setProperty("aeron.socket.so_rcvbuf", "2097152");
  setProperty("aeron.rcv.initial.window.length", "2097152");

  final MediaDriver.Context ctx = new MediaDriver.Context()
      .threadingMode(ThreadingMode.DEDICATED)
      .dirsDeleteOnStart(true)
      .termBufferSparseFile(false)
      .conductorIdleStrategy(new BusySpinIdleStrategy())
      .receiverIdleStrategy(new BusySpinIdleStrategy())
      .senderIdleStrategy(new BusySpinIdleStrategy());

  try (MediaDriver ignored = MediaDriver.launch(ctx)) {
    new SigIntBarrier().await();

  }
}
 

开发者ID:benalexau,
项目名称:rpc-bench,
代码行数:24,
代码来源:LowLatencyMediaDriver.java

示例3: main

点赞 3

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
public static void main(final String[] args)
{
    loadPropertiesFiles(args);

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .termBufferSparseFile(false)
        .threadingMode(ThreadingMode.DEDICATED)
        .conductorIdleStrategy(new BusySpinIdleStrategy())
        .receiverIdleStrategy(new BusySpinIdleStrategy())
        .senderIdleStrategy(new BusySpinIdleStrategy());

    try (MediaDriver ignored = MediaDriver.launch(ctx))
    {
        new ShutdownSignalBarrier().await();

        System.out.println("Shutdown Driver...");
    }
}
 

开发者ID:real-logic,
项目名称:aeron,
代码行数:19,
代码来源:LowLatencyMediaDriver.java

示例4: getMediaDriverContext

点赞 3

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
/**
 * Get a media driver context
 * for sending ndarrays
 * based on a given length
 * where length is the length (number of elements)
 * in the ndarrays hat are being sent
 * @param length the length to based the ipc length
 * @return the media driver context based on the given length
 */
public static MediaDriver.Context getMediaDriverContext(int length) {
    //length of array * sizeof(float)
    int ipcLength = length * 16;
    //padding for NDArrayMessage
    ipcLength += 64;
    //must be a power of 2
    ipcLength *= 2;
    //ipc length must be positive power of 2
    while (!BitUtil.isPowerOfTwo(ipcLength))
        ipcLength += 2;
    // System.setProperty("aeron.term.buffer.size",String.valueOf(ipcLength));
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    /*  .ipcTermBufferLength(ipcLength)
                                      .publicationTermBufferLength(ipcLength)
                                      .maxTermBufferLength(ipcLength)*/
                                    .conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    return ctx;
}
 

开发者ID:deeplearning4j,
项目名称:nd4j,
代码行数:31,
代码来源:AeronUtil.java

示例5: main

点赞 3

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
    MediaDriver.loadPropertiesFiles(args);

    setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
    setProperty("aeron.mtu.length", "16384");
    setProperty("aeron.socket.so_sndbuf", "2097152");
    setProperty("aeron.socket.so_rcvbuf", "2097152");
    setProperty("aeron.rcv.initial.window.length", "2097152");

    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());

    try (MediaDriver ignored = MediaDriver.launch(ctx)) {
        new SigIntBarrier().await();

    }
}
 

开发者ID:deeplearning4j,
项目名称:nd4j,
代码行数:22,
代码来源:LowLatencyMediaDriver.java

示例6: shouldWriteLoadSnapshotMessage

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Test
public void shouldWriteLoadSnapshotMessage()
{
    snapshotMessage.writeLoadMessage(ringBuffer, new BusySpinIdleStrategy());

    int readBytes;
    do
    {
        readBytes = ringBuffer.read((msgTypeId, buffer, index, length) -> {
            assertTrue(msgTypeId == MessageTypes.ADMINISTRATIVE_MSG_ID);

            int bufferOffset = index;
            messageHeaderDecoder.wrap(buffer, bufferOffset);

            final int templateId = messageHeaderDecoder.templateId();
            assertTrue(templateId == LoadSnapshotDecoder.TEMPLATE_ID);

            final int actingBlockLength = messageHeaderDecoder.blockLength();
            final int actingVersion = messageHeaderDecoder.version();

            bufferOffset += messageHeaderDecoder.encodedLength();

            loadSnapshotDecoder.wrap(buffer, bufferOffset, actingBlockLength, actingVersion);

            final MMBHeaderTypeDecoder mmbHeader = loadSnapshotDecoder.mmbHeader();
            final short nodeId = mmbHeader.nodeId();

            assertTrue(nodeId == 0);
        });
    }
    while (readBytes == 0);
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:33,
代码来源:SnapshotMessageTest.java

示例7: shouldWriteSaveSnapshotMessage

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Test
public void shouldWriteSaveSnapshotMessage()
{
    snapshotMessage.writeSaveMessage(ringBuffer, new BusySpinIdleStrategy());

    int readBytes;
    do
    {
        readBytes = ringBuffer.read((msgTypeId, buffer, index, length) -> {
            assertTrue(msgTypeId == MessageTypes.ADMINISTRATIVE_MSG_ID);

            int bufferOffset = index;
            messageHeaderDecoder.wrap(buffer, bufferOffset);

            final int templateId = messageHeaderDecoder.templateId();
            assertTrue(templateId == SaveSnapshotDecoder.TEMPLATE_ID);

            final int actingBlockLength = messageHeaderDecoder.blockLength();
            final int actingVersion = messageHeaderDecoder.version();

            bufferOffset += messageHeaderDecoder.encodedLength();

            saveSnapshotDecoder.wrap(buffer, bufferOffset, actingBlockLength, actingVersion);

            final MMBHeaderTypeDecoder mmbHeader = saveSnapshotDecoder.mmbHeader();
            final short nodeId = mmbHeader.nodeId();

            assertTrue(nodeId == 0);
        });
    }
    while (readBytes == 0);
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:33,
代码来源:SnapshotMessageTest.java

示例8: shouldThrowExceptionWhenOutputMessageProcessorIsNull

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void shouldThrowExceptionWhenOutputMessageProcessorIsNull()
{
    try (final Helios helios = new Helios())
    {
        new ServiceReport(
            new InputMessageProcessor(ringBuffer, new BusySpinIdleStrategy(), 0, 0, helios.newIpcStream(0),
                null, "")
        ).addResponseProcessor(null);
    }
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:12,
代码来源:ServiceReportTest.java

示例9: PingGatewayHandler

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
PingGatewayHandler(final int gatewayId, final RingBufferPool ringBufferPool, final AeronStream gwOutputStream,
    final MessageHandler delegate)
{
    this.gatewayId = gatewayId;
    this.ringBufferPool = ringBufferPool;
    this.gwOutputStream = gwOutputStream;
    this.delegate = delegate;
    this.idleStrategy = new BusySpinIdleStrategy();
    //this.echoBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));

    outgoingDataMessage.allocate(ComponentType.Gateway, (short)gatewayId, MESSAGE_LENGTH);
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:13,
代码来源:HeliosTest.java

示例10: main

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
public static void main(final String... args) {
    final String aeronDirectoryName = args[0];
    final MediaDriver.Context ctx = new MediaDriver.Context()
            .threadingMode(ThreadingMode.DEDICATED)
            .conductorIdleStrategy(new BackoffIdleStrategy(1, 1, 1, 1))
            .receiverIdleStrategy(new BusySpinIdleStrategy())
            .senderIdleStrategy(new BusySpinIdleStrategy())
            .aeronDirectoryName(aeronDirectoryName);
    MediaDriver.launch(ctx);
    new SigIntBarrier().await();
    System.out.println("Shutdown media driver.");
}
 

开发者ID:terzerm,
项目名称:fx-highway,
代码行数:13,
代码来源:AeronMediaDriver.java

示例11: before

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Before
public void before() {
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    mediaDriver = MediaDriver.launchEmbedded(ctx);
    System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName());
    System.out.println("Launched media driver");
}
 

开发者ID:deeplearning4j,
项目名称:nd4j,
代码行数:12,
代码来源:AeronNDArrayResponseTest.java

示例12: main

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
    System.out.print("Starting Helios...");

    final HeliosContext context = new HeliosContext()
        //.setJournalEnabled(true)
        .setReadIdleStrategy(new BusySpinIdleStrategy())
        .setWriteIdleStrategy(new BusySpinIdleStrategy())
        .setSubscriberIdleStrategy(new BusySpinIdleStrategy())
        .setPublisherIdleStrategy(new BusySpinIdleStrategy());

    final HeliosDriver driver = new HeliosDriver(context);

    try(final Helios helios = new Helios(context, driver))
    {
        helios.errorHandler(EchoEmbedded::serviceError);

        System.out.print("done\nCreating Helios service...");

        final AeronStream svcInputStream = helios.newStream(SERVICE_INPUT_CHANNEL, SERVICE_INPUT_STREAM_ID);
        final AeronStream svcOutputStream = helios.newStream(SERVICE_OUTPUT_CHANNEL, SERVICE_OUTPUT_STREAM_ID);
        final Service<EchoServiceHandler> svc = helios.addService(EchoServiceHandler::new,
            EchoEmbedded::associationWithGatewayEstablished, EchoEmbedded::associationWithGatewayBroken,
            svcInputStream, svcOutputStream);

        System.out.print("done\nCreating Helios gateway...");

        final AeronStream gwInputStream = helios.newStream(GATEWAY_INPUT_CHANNEL, GATEWAY_INPUT_STREAM_ID);
        final AeronStream gwOutputStream = helios.newStream(GATEWAY_OUTPUT_CHANNEL, GATEWAY_OUTPUT_STREAM_ID);
        final Gateway<EchoGatewayHandler> gw = helios.addGateway(
            EchoEmbedded::associationWithServiceEstablished, EchoEmbedded::associationWithServiceBroken);
        final EchoGatewayHandler gwHandler = gw.addEndPoint(gwOutputStream, gwInputStream, EchoGatewayHandler::new);

        final ConsoleReporter reporter = new ConsoleReporter();

        System.out.println("done\nEchoEmbedded is now running.");

        helios.start();

        System.out.print("Waiting for Gateway to see association with Service...");

        GW_ASSOCIATION_LATCH.await();

        System.out.print("done\nWaiting for Service to see association with Gateway...");

        SVC_ASSOCIATION_LATCH.await();

        System.out.println("done");

        EchoGateway.runTest(gwHandler, () -> reporter.onReport(gw.report()));

        reporter.onReport(gw.report());
        reporter.onReport(svc.report());
    }

    System.out.println("EchoEmbedded is now terminated.");
    System.exit(0);
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:59,
代码来源:EchoEmbedded.java

示例13: main

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
    System.out.print("Starting Helios...");

    final HeliosContext context = new HeliosContext()
        //.setJournalEnabled(true)
        .setReadIdleStrategy(new BusySpinIdleStrategy())
        .setWriteIdleStrategy(new BusySpinIdleStrategy())
        .setSubscriberIdleStrategy(new BusySpinIdleStrategy())
        .setPublisherIdleStrategy(new BusySpinIdleStrategy());

    final HeliosDriver driver = new HeliosDriver(context);

    try(final Helios helios = new Helios(context, driver))
    {
        helios.errorHandler(EchoEmbeddedIpc::serviceError);

        System.out.print("done\nCreating Helios service...");

        final AeronStream ipcInputStream = helios.newIpcStream(SERVICE_INPUT_STREAM_ID);
        final AeronStream ipcOutputStream = helios.newIpcStream(SERVICE_OUTPUT_STREAM_ID);
        final Service<EchoServiceHandler> svc = helios.addService(EchoServiceHandler::new,
            EchoEmbeddedIpc::associationWithGatewayEstablished, EchoEmbeddedIpc::associationWithGatewayBroken,
            ipcInputStream, ipcOutputStream);

        System.out.print("done\nCreating Helios gateway...");

        final Gateway<EchoGatewayHandler> gw = helios.addGateway(
            EchoEmbeddedIpc::associationWithServiceEstablished, EchoEmbeddedIpc::associationWithServiceBroken);
        final EchoGatewayHandler gwHandler = gw.addEndPoint(ipcInputStream, ipcOutputStream, EchoGatewayHandler::new);

        final ConsoleReporter reporter = new ConsoleReporter();

        System.out.println("done\nEchoEmbedded is now running.");

        helios.start();

        System.out.print("Waiting for Gateway to see association with Service...");

        GW_ASSOCIATION_LATCH.await();

        System.out.print("done\nWaiting for Service to see association with Gateway...");

        SVC_ASSOCIATION_LATCH.await();

        System.out.println("done");

        EchoGateway.runTest(gwHandler, () -> reporter.onReport(gw.report()));

        reporter.onReport(gw.report());
        reporter.onReport(svc.report());
    }

    System.out.println("EchoEmbeddedIpc is now terminated.");
    System.exit(0);
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:57,
代码来源:EchoEmbeddedIpc.java

示例14: addEndPoint

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Override
public T addEndPoint(final AeronStream reqStream, final AeronStream rspStream, final GatewayHandlerFactory<T> factory)
{
    Objects.requireNonNull(reqStream, "reqStream");
    Objects.requireNonNull(rspStream, "rspStream");
    Objects.requireNonNull(factory, "factory");

    reqStream.componentType = ComponentType.Gateway;
    reqStream.componentId = gatewayId;

    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();

    final ByteBuffer outputBuffer = DirectBufferAllocator.allocateCacheAligned((16 * 1024) + TRAILER_LENGTH); // TODO: configure
    final RingBuffer outputRingBuffer = new OneToOneRingBuffer(new UnsafeBuffer(outputBuffer));

    ringBufferPool.addOutputRingBuffer(reqStream, outputRingBuffer);

    final int heartbeatInterval = helios.context().heartbeatInterval();
    final OutputMessageProcessor gwOutputProcessor =
        new OutputMessageProcessor(outputRingBuffer, reqStream, idleStrategy, heartbeatInterval, "gwOutputProcessor");

    gwOutputProcessorList.add(gwOutputProcessor);

    final ByteBuffer inputBuffer = DirectBufferAllocator.allocateCacheAligned((16 * 1024) + TRAILER_LENGTH); // TODO: configure
    final RingBuffer inputRingBuffer = new OneToOneRingBuffer(new UnsafeBuffer(inputBuffer));

    final T gatewayHandler = factory.createGatewayHandler(ringBufferPool);
    final RingBufferProcessor gatewayProcessor = new RingBufferProcessor<>(inputRingBuffer, gatewayHandler, new BusySpinIdleStrategy(), "gwProcessor");
    gatewayProcessorList.add(gatewayProcessor);

    final IdleStrategy pollIdleStrategy = helios.context().subscriberIdleStrategy();
    final int heartbeatLiveness = helios.context().heartbeatLiveness();
    final InputMessageProcessor gwInputProcessor =
        new InputMessageProcessor(inputRingBuffer, pollIdleStrategy, FRAME_COUNT_LIMIT, heartbeatLiveness,
            rspStream, this, "gwInputProcessor");

    gwInputProcessorList.add(gwInputProcessor);

    final long subscriptionId = gwInputProcessor.subscriptionId();
    helios.addGatewaySubscription(subscriptionId, this);

    report.addRequestProcessor(gwOutputProcessor);
    report.addResponseProcessor(gwInputProcessor);

    return gatewayHandler;
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:47,
代码来源:HeliosGateway.java

示例15: shouldThrowExceptionWhenRingBufferIsNullInLoad

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void shouldThrowExceptionWhenRingBufferIsNullInLoad()
{
    snapshotMessage.writeLoadMessage(null, new BusySpinIdleStrategy());
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:6,
代码来源:SnapshotMessageTest.java

示例16: shouldThrowExceptionWhenRingBufferIsNullInSave

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void shouldThrowExceptionWhenRingBufferIsNullInSave()
{
    snapshotMessage.writeSaveMessage(null, new BusySpinIdleStrategy());
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:6,
代码来源:SnapshotMessageTest.java

示例17: PingServiceHandler

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
PingServiceHandler(final RingBufferPool ringBufferPool)
{
    this.ringBufferPool = ringBufferPool;
    this.idleStrategy = new BusySpinIdleStrategy();
    this.gatewayId2StreamMap = new Int2ObjectHashMap<>();
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:7,
代码来源:HeliosTest.java

示例18: shouldThrowExceptionWhenTimerWheelIsNull

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void shouldThrowExceptionWhenTimerWheelIsNull()
{
    new TimerWheelWaitStrategy(null, new BusySpinIdleStrategy());
}
 

开发者ID:canepat,
项目名称:Helios,
代码行数:6,
代码来源:TimerWheelWaitStrategyTest.java

示例19: execute

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
private void execute() {
  final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
  while (running.get()) {
    idleStrategy.idle(subscription.poll(fragmentHandler, FRAGMENT_LIMIT));
  }
}
 

开发者ID:benalexau,
项目名称:rpc-bench,
代码行数:7,
代码来源:BenchServer.java

示例20: main

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
public static void main(final String[] args)
{
    final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;

    final Aeron.Context ctx = new Aeron.Context();
    if (EMBEDDED_MEDIA_DRIVER)
    {
        ctx.aeronDirectoryName(driver.aeronDirectoryName());
    }

    if (INFO_FLAG)
    {
        ctx.availableImageHandler(SamplesUtil::printAvailableImage);
        ctx.unavailableImageHandler(SamplesUtil::printUnavailableImage);
    }

    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();

    System.out.println("Subscribing Ping at " + PING_CHANNEL + " on stream Id " + PING_STREAM_ID);
    System.out.println("Publishing Pong at " + PONG_CHANNEL + " on stream Id " + PONG_STREAM_ID);

    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));

    try (Aeron aeron = Aeron.connect(ctx);
        Publication pongPublication = aeron.addPublication(PONG_CHANNEL, PONG_STREAM_ID);
        Subscription pingSubscription = aeron.addSubscription(PING_CHANNEL, PING_STREAM_ID))
    {
        final FragmentAssembler dataHandler = new FragmentAssembler(
            (buffer, offset, length, header) -> pingHandler(pongPublication, buffer, offset, length));

        while (running.get())
        {
            idleStrategy.idle(pingSubscription.poll(dataHandler, FRAME_COUNT_LIMIT));
        }

        System.out.println("Shutting down...");
    }

    CloseHelper.quietClose(driver);
}
 

开发者ID:real-logic,
项目名称:aeron,
代码行数:42,
代码来源:Pong.java

示例21: before

点赞 2

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
@BeforeClass
public static void before() throws Exception {
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());

    mediaDriver = MediaDriver.launchEmbedded(ctx);
    aeron = Aeron.connect(getContext());
    masterNode = new ParameterServerSubscriber(mediaDriver);
    masterNode.setAeron(aeron);
    int masterPort = 40223 + new java.util.Random().nextInt(13000);
    int masterStatusPort = masterPort - 2000;
    masterNode.run(new String[] {"-m", "true", "-p", String.valueOf(masterPort), "-h", "localhost", "-id", "11",
                    "-md", mediaDriver.aeronDirectoryName(), "-sp", String.valueOf(masterStatusPort), "-s", "2,2",
                    "-u", String.valueOf(1)

    });

    assertTrue(masterNode.isMaster());
    assertEquals(masterPort, masterNode.getPort());
    assertEquals("localhost", masterNode.getHost());
    assertEquals(11, masterNode.getStreamId());
    assertEquals(12, masterNode.getResponder().getStreamId());
    assertEquals(masterNode.getMasterArray(), Nd4j.create(new int[] {2, 2}));

    slaveNode = new ParameterServerSubscriber(mediaDriver);
    slaveNode.setAeron(aeron);
    int slavePort = masterPort + 100;
    int slaveStatusPort = slavePort - 2000;
    slaveNode.run(new String[] {"-p", String.valueOf(slavePort), "-h", "localhost", "-id", "10", "-pm",
                    masterNode.getSubscriber().connectionUrl(), "-md", mediaDriver.aeronDirectoryName(), "-sp",
                    String.valueOf(slaveStatusPort), "-u", String.valueOf(1)

    });

    assertFalse(slaveNode.isMaster());
    assertEquals(slavePort, slaveNode.getPort());
    assertEquals("localhost", slaveNode.getHost());
    assertEquals(10, slaveNode.getStreamId());

    int tries = 10;
    while (!masterNode.subscriberLaunched() && !slaveNode.subscriberLaunched() && tries < 10) {
        Thread.sleep(10000);
        tries++;
    }

    if (!masterNode.subscriberLaunched() && !slaveNode.subscriberLaunched()) {
        throw new IllegalStateException("Failed to start master and slave node");
    }

    log.info("Using media driver directory " + mediaDriver.aeronDirectoryName());
    log.info("Launched media driver");
}
 

开发者ID:deeplearning4j,
项目名称:nd4j,
代码行数:56,
代码来源:ParameterServerClientPartialTest.java

示例22: subscriberLoop

点赞 1

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
/**
 * Return a reusable, parametrised event loop that calls a default idler when no messages are received
 *
 * @param fragmentHandler to be called back for each message.
 * @param limit           passed to {@link Subscription#poll(FragmentHandler, int)}
 * @param running         indication for loop
 * @return loop function
 */
public static Consumer<Subscription> subscriberLoop(
    final FragmentHandler fragmentHandler, final int limit, final AtomicBoolean running)
{
    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();

    return subscriberLoop(fragmentHandler, SamplesUtil::printEndOfStreamImage, limit, running, idleStrategy);
}
 

开发者ID:real-logic,
项目名称:aeron,
代码行数:16,
代码来源:SamplesUtil.java

示例23: subscriberLoop

点赞 1

import org.agrona.concurrent.BusySpinIdleStrategy; //导入依赖的package包/类
/**
 * Return a reusable, parametrized
 * event loop that calls a
 * default idler
 * when no messages are received
 *
 * @param fragmentHandler to be called back for each message.
 * @param limit           passed to {@link Subscription#poll(FragmentHandler, int)}
 * @param running         indication for loop
 * @return loop function
 */
public static Consumer<Subscription> subscriberLoop(final FragmentHandler fragmentHandler, final int limit,
                final AtomicBoolean running, final AtomicBoolean launched) {
    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
    return subscriberLoop(fragmentHandler, limit, running, idleStrategy, launched);
}
 

开发者ID:deeplearning4j,
项目名称:nd4j,
代码行数:17,
代码来源:AeronUtil.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)