本文整理汇总了Java中io.aeron.Publication.CLOSED属性的典型用法代码示例。如果您正苦于以下问题:Java Publication.CLOSED属性的具体用法?Java Publication.CLOSED怎么用?Java Publication.CLOSED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.aeron.Publication
的用法示例。
在下文中一共展示了Publication.CLOSED属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
private void send(final int length)
{
final int fullLength = MessageHeaderEncoder.ENCODED_LENGTH + length;
while (true)
{
// TODO: Under back pressure it should drop sends and then do an update on timeout to avoid tail loss.
final long result = recordingEventsPublication.offer(outboundBuffer, 0, fullLength);
if (result > 0 || result == Publication.NOT_CONNECTED)
{
idleStrategy.reset();
break;
}
if (result == Publication.CLOSED || result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException();
}
idleStrategy.idle();
}
}
示例2: onFragment
public boolean onFragment(final UnsafeBuffer buffer, final int offset, final int length)
{
if (state != State.REPLAY)
{
return false;
}
final int frameOffset = offset - DataHeaderFlyweight.HEADER_LENGTH;
final int frameType = frameType(buffer, frameOffset);
final long result = frameType == FrameDescriptor.PADDING_FRAME_TYPE ?
replayPublication.appendPadding(length) :
replayFrame(buffer, offset, length, frameOffset);
if (result > 0)
{
return true;
}
else if (result == Publication.CLOSED || result == Publication.NOT_CONNECTED)
{
closeOnError(null, "replay stream has been shutdown mid-replay");
}
return false;
}
示例3: offer
private boolean offer(final int length)
{
retryIdleStrategy.reset();
int attempts = retryAttempts;
while (true)
{
final long result;
if ((result = publication.offer(buffer, 0, MessageHeaderEncoder.ENCODED_LENGTH + length)) > 0)
{
return true;
}
if (result == Publication.CLOSED)
{
throw new IllegalStateException("Connection to the archive has been closed");
}
if (result == Publication.NOT_CONNECTED)
{
throw new IllegalStateException("Connection to the archive is no longer available");
}
if (result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException("Publication failed due to max position being reached");
}
if (--attempts <= 0)
{
return false;
}
retryIdleStrategy.idle();
}
}
示例4: offerWithTimeout
private boolean offerWithTimeout(final int length, final AgentInvoker aeronClientInvoker)
{
retryIdleStrategy.reset();
final long deadlineNs = nanoClock.nanoTime() + connectTimeoutNs;
while (true)
{
final long result;
if ((result = publication.offer(buffer, 0, MessageHeaderEncoder.ENCODED_LENGTH + length)) > 0)
{
return true;
}
if (null != aeronClientInvoker)
{
aeronClientInvoker.invoke();
}
if (result == Publication.CLOSED)
{
throw new IllegalStateException("Connection to the archive has been closed");
}
if (result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException("Publication failed due to max position being reached");
}
if (nanoClock.nanoTime() > deadlineNs)
{
return false;
}
retryIdleStrategy.idle();
}
}
示例5: checkResult
private static void checkResult(final Publication controlPublication, final long result)
{
if (result == Publication.NOT_CONNECTED ||
result == Publication.CLOSED ||
result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException("Response channel is down: " + controlPublication.channel());
}
}
示例6: checkResult
private static void checkResult(final long result)
{
if (result == Publication.CLOSED || result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException("Unexpected publication state: " + result);
}
}
示例7: checkResult
protected static void checkResult(final long result)
{
if (result == Publication.NOT_CONNECTED ||
result == Publication.CLOSED ||
result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException("Unexpected publication state: " + result);
}
}
示例8: checkResult
private static void checkResult(final long result)
{
if (result == Publication.NOT_CONNECTED ||
result == Publication.CLOSED ||
result == Publication.MAX_POSITION_EXCEEDED)
{
throw new IllegalStateException("Unexpected publication state: " + result);
}
}
示例9: 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");
}
示例10: 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.");
}
}