本文整理汇总了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;
}
}
}
示例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 + ")");
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
}