当前位置: 首页>>代码示例>>Java>>正文


Java Publication.ADMIN_ACTION属性代码示例

本文整理汇总了Java中io.aeron.Publication.ADMIN_ACTION属性的典型用法代码示例。如果您正苦于以下问题:Java Publication.ADMIN_ACTION属性的具体用法?Java Publication.ADMIN_ACTION怎么用?Java Publication.ADMIN_ACTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在io.aeron.Publication的用法示例。


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

示例1: run

private static void run(final Publication publication, final long messageCount, final long messagesPerSecond, final int marketDataDepth) throws InterruptedException {
    final NanoClock clock = new SystemNanoClock();
    final MutableMarketDataSnapshot snapshot = new MutableMarketDataSnapshot();
    final UnsafeBuffer unsafeBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(4096));
    final long periodNs = 1000000000/messagesPerSecond;
    Thread.sleep(2000);//make sure the subscriber is ready
    long cntAdmin = 0;
    long cntBackp = 0;
    long cnt = 0;
    final long t0 = clock.nanoTime();
    while (cnt < messageCount) {
        long tCur = clock.nanoTime();
        while (tCur - t0 < cnt * periodNs) {
            tCur = clock.nanoTime();
        }
        final MarketDataSnapshot newSnapshot = SerializerHelper.givenMarketDataSnapshot(snapshot.builder(), marketDataDepth, marketDataDepth);
        final int len = SerializerHelper.encode(unsafeBuffer, newSnapshot);
        long pubres;
        do {
            pubres = publication.offer(unsafeBuffer, 0, len);
            if (pubres < 0) {
                if (pubres == Publication.BACK_PRESSURED) {
                    cntBackp++;
                } else if (pubres == Publication.ADMIN_ACTION) {
                    cntAdmin++;
                } else {
                    throw new RuntimeException("publication failed with pubres=" + pubres);
                }
            }
        } while (pubres < 0);
        cnt++;
    }
    final long t1 = clock.nanoTime();
    System.out.println((t1 - t0) / 1000.0 + " us total publishing time (backp=" + cntBackp + ", admin=" + cntAdmin + ", cnt=" + cnt + ")");
}
 
开发者ID:terzerm,项目名称:fx-highway,代码行数:35,代码来源:AeronPublisher.java

示例2: sendBuffer

private void sendBuffer(DirectBuffer buffer) throws Exception {
    // Try to publish the buffer. 'offer' is a non-blocking call.
    // If it returns less than 0, the message was not sent, and the offer should be retried.
    long result;
    int tries = 0;
    while ((result = publication.offer(buffer, 0, buffer.capacity())) < 0L && tries < 5) {
        if (result == Publication.BACK_PRESSURED) {
            log.info("Offer failed due to back pressure");
        } else if (result == Publication.NOT_CONNECTED) {
            log.info("Offer failed because publisher is not connected to subscriber " + channel + " and stream "
                            + streamId);
        } else if (result == Publication.ADMIN_ACTION) {
            log.info("Offer failed because of an administration action in the system and channel" + channel
                            + " and stream " + streamId);
        } else if (result == Publication.CLOSED) {
            log.info("Offer failed publication is closed and channel" + channel + " and stream " + streamId);
        } else {
            log.info(" Offer failed due to unknown reason and channel" + channel + " and stream " + streamId);
        }



        Thread.sleep(publishRetryTimeOut);
        tries++;

    }

    if (tries >= 5 && result == 0)
        throw new IllegalStateException("Failed to send message");

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

示例3: main

public static void main(final String[] args) throws Exception
{
    // Allocate enough buffer size to hold maximum message length
    // The UnsafeBuffer class is part of the Agrona library and is used for efficient buffer management
    final UnsafeBuffer buffer = new UnsafeBuffer(BufferUtil.allocateDirectAligned(512, BitUtil.CACHE_LINE_LENGTH));

    // The channel (an endpoint identifier) to send the message to
    final String channel = "aeron:udp?endpoint=localhost:40123";

    // A unique identifier for a stream within a channel. Stream ID 0 is reserved
    // for internal use and should not be used by applications.
    final int streamId = 10;

    System.out.println("Publishing to " + channel + " on stream Id " + streamId);

    // Create a context, needed for client connection to media driver
    // A separate media driver process needs to be running prior to starting this application
    final Aeron.Context ctx = new Aeron.Context();

    // Create an Aeron instance with client-provided context configuration and connect to the
    // media driver, and create a Publication.  The Aeron and Publication classes implement
    // AutoCloseable, and will automatically clean up resources when this try block is finished.
    try (Aeron aeron = Aeron.connect(ctx);
        Publication publication = aeron.addPublication(channel, streamId))
    {
        final String message = "Hello World! ";
        final byte[] messageBytes = message.getBytes();
        buffer.putBytes(0, messageBytes);

        // Wait for 5 seconds to connect to a subscriber
        final long deadlineNs = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
        while (!publication.isConnected())
        {
            if (System.nanoTime() >= deadlineNs)
            {
                System.out.println("Failed to connect to subscriber");
                return;
            }

            Thread.sleep(1);
        }

        // Try to publish the buffer. 'offer' is a non-blocking call.
        // If it returns less than 0, the message was not sent, and the offer should be retried.
        final long result = publication.offer(buffer, 0, messageBytes.length);

        if (result < 0L)
        {
            if (result == Publication.BACK_PRESSURED)
            {
                System.out.println(" Offer failed due to back pressure");
            }
            else if (result == Publication.NOT_CONNECTED)
            {
                System.out.println(" Offer failed because publisher is not connected to subscriber");
            }
            else if (result == Publication.ADMIN_ACTION)
            {
                System.out.println("Offer failed because of an administration action in the system");
            }
            else if (result == Publication.CLOSED)
            {
                System.out.println("Offer failed publication is closed");
            }
            else if (result == Publication.MAX_POSITION_EXCEEDED)
            {
                System.out.println("Offer failed due to publication reaching max position");
            }
            else
            {
                System.out.println(" Offer failed due to unknown reason");
            }
        }
        else
        {
            System.out.println(" yay !!");
        }

        System.out.println("Done sending.");
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:81,代码来源:SimplePublisher.java


注:本文中的io.aeron.Publication.ADMIN_ACTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。