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


Java Publication.offer方法代码示例

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


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

示例1: attemptErrorResponse

import io.aeron.Publication; //导入方法依赖的package包/类
void attemptErrorResponse(
    final long controlSessionId,
    final long correlationId,
    final String errorMessage,
    final Publication controlPublication)
{
    responseEncoder
        .wrapAndApplyHeader(buffer, 0, messageHeaderEncoder)
        .controlSessionId(controlSessionId)
        .correlationId(correlationId)
        .relevantId(0)
        .code(ControlResponseCode.ERROR)
        .errorMessage(null == errorMessage ? "" : errorMessage);

    final int length = HEADER_LENGTH + responseEncoder.encodedLength();

    for (int i = 0; i < 3; i++)
    {
        final long result = controlPublication.offer(buffer, 0, length);
        if (result > 0)
        {
            break;
        }
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:26,代码来源:ControlResponseProxy.java

示例2: run

import io.aeron.Publication; //导入方法依赖的package包/类
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,代码行数:36,代码来源:AeronPublisher.java

示例3: send

import io.aeron.Publication; //导入方法依赖的package包/类
private boolean send(final Publication controlPublication, final DirectBuffer buffer, final int length)
{
    for (int i = 0; i < 3; i++)
    {
        final long result = controlPublication.offer(buffer, 0, length);
        if (result > 0)
        {
            return true;
        }

        checkResult(controlPublication, result);
    }

    return false;
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:16,代码来源:ControlResponseProxy.java

示例4: offer

import io.aeron.Publication; //导入方法依赖的package包/类
/**
 * Non-blocking publish of a partial buffer containing a message plus session header to a cluster.
 * <p>
 * This version of the method will set the timestamp value in the header to zero.
 *
 * @param publication   to be offer to.
 * @param correlationId to be used to identify the message to the cluster.
 * @param buffer        containing message.
 * @param offset        offset in the buffer at which the encoded message begins.
 * @param length        in bytes of the encoded message.
 * @return the same as {@link Publication#offer(DirectBuffer, int, int)}.
 */
public long offer(
    final Publication publication,
    final long correlationId,
    final DirectBuffer buffer,
    final int offset,
    final int length)
{
    sessionHeaderEncoder.correlationId(correlationId);
    sessionHeaderEncoder.timestamp(0L);
    messageBuffer.reset(buffer, offset, length);

    return publication.offer(vectors, null);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:26,代码来源:SessionDecorator.java

示例5: pingHandler

import io.aeron.Publication; //导入方法依赖的package包/类
public static void pingHandler(
    final Publication pongPublication, final DirectBuffer buffer, final int offset, final int length)
{
    if (pongPublication.offer(buffer, offset, length) > 0L)
    {
        return;
    }

    PING_HANDLER_IDLE_STRATEGY.reset();

    while (pongPublication.offer(buffer, offset, length) < 0L)
    {
        PING_HANDLER_IDLE_STRATEGY.idle();
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:16,代码来源:Pong.java

示例6: roundTripMessages

import io.aeron.Publication; //导入方法依赖的package包/类
private static void roundTripMessages(
    final FragmentHandler fragmentHandler,
    final Publication pingPublication,
    final Subscription pongSubscription,
    final long numMessages)
{
    while (!pongSubscription.isConnected())
    {
        Thread.yield();
    }

    final Image image = pongSubscription.imageAtIndex(0);

    for (long i = 0; i < numMessages; i++)
    {
        long offeredPosition;

        do
        {
            ATOMIC_BUFFER.putLong(0, System.nanoTime());
        }
        while ((offeredPosition = pingPublication.offer(ATOMIC_BUFFER, 0, MESSAGE_LENGTH)) < 0L);

        PONG_HANDLER_IDLE_STRATEGY.reset();
        do
        {
            while (image.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT) <= 0)
            {
                PONG_HANDLER_IDLE_STRATEGY.idle();
            }
        }
        while (image.position() < offeredPosition);
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:35,代码来源:EmbeddedPingPong.java


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