io.aeron.exceptions.AeronException Java Examples

The following examples show how to use io.aeron.exceptions.AeronException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileStoreLogFactory.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void checkStorage(final long logLength)
{
    if (checkStorage)
    {
        final long usableSpace = getUsableSpace();

        if (usableSpace <= lowStorageWarningThreshold)
        {
            System.out.format("Warning: space is running low in %s threshold=%,d usable=%,d%n",
                fileStore, lowStorageWarningThreshold, usableSpace);
        }

        if (usableSpace < logLength)
        {
            throw new AeronException(
                "insufficient usable storage for new log of length=" + logLength + " in " + fileStore);
        }
    }
}
 
Example #2
Source File: Tests.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static Subscription reAddSubscription(final Aeron aeron, final String channel, final int streamId)
{
    // In cases where a subscription is added immediately after closing one it is possible that
    // the second one can fail, so retry in that case.
    while (true)
    {
        try
        {
            return aeron.addSubscription(channel, streamId);
        }
        catch (final RegistrationException ex)
        {
            if (ex.category() != AeronException.Category.WARN)
            {
                throw ex;
            }

            yieldingWait(ex.getMessage());
        }
    }
}
 
Example #3
Source File: ReentrantClientTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldThrowWhenReentering()
{
    final MutableReference<Throwable> expectedException = new MutableReference<>();
    final ErrorHandler errorHandler = expectedException::set;

    try (Aeron aeron = Aeron.connect(new Aeron.Context().errorHandler(errorHandler)))
    {
        final String channel = CommonContext.IPC_CHANNEL;
        final AvailableImageHandler mockHandler = mock(AvailableImageHandler.class);
        doAnswer((invocation) -> aeron.addSubscription(channel, 3))
            .when(mockHandler).onAvailableImage(any(Image.class));

        final Subscription sub = aeron.addSubscription(channel, 1001, mockHandler, null);
        final Publication pub = aeron.addPublication(channel, 1001);

        verify(mockHandler, timeout(5000L)).onAvailableImage(any(Image.class));

        pub.close();
        sub.close();

        assertThat(expectedException.get(), instanceOf(AeronException.class));
    }
}
 
Example #4
Source File: ControlResponseProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
private static void checkResult(final ControlSession session, final long result)
{
    if (result == Publication.NOT_CONNECTED)
    {
        session.abort();
        throw new ArchiveException(
            "response publication is not connected: " + session, AeronException.Category.WARN);
    }

    if (result == Publication.CLOSED)
    {
        session.abort();
        throw new ArchiveException("response publication is closed: " + session);
    }

    if (result == Publication.MAX_POSITION_EXCEEDED)
    {
        session.abort();
        throw new ArchiveException("response publication at max position: " + session);
    }
}
 
Example #5
Source File: ArchiveTool.java    From aeron with Apache License 2.0 6 votes vote down vote up
static void checksumRecording(
    final PrintStream out,
    final File archiveDir,
    final long recordingId,
    final boolean allFiles,
    final Checksum checksum,
    final EpochClock epochClock)
{
    try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock))
    {
        final CatalogEntryProcessor catalogEntryProcessor =
            (headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) ->
            {
                final ByteBuffer buffer = ByteBuffer.allocateDirect(
                    align(descriptorDecoder.mtuLength(), CACHE_LINE_LENGTH));
                buffer.order(LITTLE_ENDIAN);
                checksum(buffer, out, archiveDir, allFiles, checksum, descriptorDecoder);
            };

        if (!catalog.forEntry(recordingId, catalogEntryProcessor))
        {
            throw new AeronException("no recording found with recordingId: " + recordingId);
        }
    }
}
 
Example #6
Source File: ArchiveTool.java    From aeron with Apache License 2.0 6 votes vote down vote up
static boolean verifyRecording(
    final PrintStream out,
    final File archiveDir,
    final long recordingId,
    final Set<VerifyOption> options,
    final Checksum checksum,
    final EpochClock epochClock,
    final ActionConfirmation<File> truncateFileOnPageStraddle)
{
    try (Catalog catalog = openCatalog(archiveDir, epochClock))
    {
        final MutableInteger errorCount = new MutableInteger();
        if (!catalog.forEntry(recordingId, createVerifyEntryProcessor(
            out, archiveDir, options, checksum, epochClock, errorCount, truncateFileOnPageStraddle)))
        {
            throw new AeronException("no recording found with recordingId: " + recordingId);
        }

        return errorCount.get() == 0;
    }
}
 
Example #7
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addDestination(final long registrationId, final String endpointChannel)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    destinationMessage
        .registrationCorrelationId(registrationId)
        .channel(endpointChannel)
        .correlationId(correlationId);

    if (!toDriverCommandBuffer.write(ADD_DESTINATION, buffer, 0, destinationMessage.length()))
    {
        throw new AeronException("could not write add destination command");
    }

    return correlationId;
}
 
Example #8
Source File: ConsensusModuleContextCloseTests.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
void ownsAeronClient() throws Exception
{
    context.ownsAeronClient(true);

    final AeronException ex = assertThrows(AeronException.class, context::close);

    assertSame(aeronException, ex);

    final InOrder inOrder = inOrder(countedErrorHandler, errorHandler, aeron);
    inOrder.verify(countedErrorHandler).onError(recodingLogException);
    inOrder.verify(countedErrorHandler).onError(markFileException);
    inOrder.verify((AutoCloseable)errorHandler).close();
    inOrder.verify(aeron).close();
    inOrder.verifyNoMoreInteractions();
}
 
Example #9
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addPublication(final String channel, final int streamId)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    publicationMessage.correlationId(correlationId);
    publicationMessage
        .streamId(streamId)
        .channel(channel);

    if (!toDriverCommandBuffer.write(ADD_PUBLICATION, buffer, 0, publicationMessage.length()))
    {
        throw new AeronException("could not write add publication command");
    }

    return correlationId;
}
 
Example #10
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addExclusivePublication(final String channel, final int streamId)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    publicationMessage.correlationId(correlationId);
    publicationMessage
        .streamId(streamId)
        .channel(channel);

    if (!toDriverCommandBuffer.write(ADD_EXCLUSIVE_PUBLICATION, buffer, 0, publicationMessage.length()))
    {
        throw new AeronException("could not write add exclusive publication command");
    }

    return correlationId;
}
 
Example #11
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addSubscription(final String channel, final int streamId)
{
    final long registrationId = Aeron.NULL_VALUE;
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    subscriptionMessage.correlationId(correlationId);
    subscriptionMessage
        .registrationCorrelationId(registrationId)
        .streamId(streamId)
        .channel(channel);

    if (!toDriverCommandBuffer.write(ADD_SUBSCRIPTION, buffer, 0, subscriptionMessage.length()))
    {
        throw new AeronException("could not write add subscription command");
    }

    return correlationId;
}
 
Example #12
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long removeDestination(final long registrationId, final String endpointChannel)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    destinationMessage
        .registrationCorrelationId(registrationId)
        .channel(endpointChannel)
        .correlationId(correlationId);

    if (!toDriverCommandBuffer.write(REMOVE_DESTINATION, buffer, 0, destinationMessage.length()))
    {
        throw new AeronException("could not write remove destination command");
    }

    return correlationId;
}
 
Example #13
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addRcvDestination(final long registrationId, final String endpointChannel)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    destinationMessage
        .registrationCorrelationId(registrationId)
        .channel(endpointChannel)
        .correlationId(correlationId);

    if (!toDriverCommandBuffer.write(ADD_RCV_DESTINATION, buffer, 0, destinationMessage.length()))
    {
        throw new AeronException("could not write add rcv destination command");
    }

    return correlationId;
}
 
Example #14
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long removeRcvDestination(final long registrationId, final String endpointChannel)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    destinationMessage
        .registrationCorrelationId(registrationId)
        .channel(endpointChannel)
        .correlationId(correlationId);

    if (!toDriverCommandBuffer.write(REMOVE_RCV_DESTINATION, buffer, 0, destinationMessage.length()))
    {
        throw new AeronException("could not write remove rcv destination command");
    }

    return correlationId;
}
 
Example #15
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addCounter(
    final int typeId,
    final DirectBuffer keyBuffer,
    final int keyOffset,
    final int keyLength,
    final DirectBuffer labelBuffer,
    final int labelOffset,
    final int labelLength)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    counterMessage
        .typeId(typeId)
        .keyBuffer(keyBuffer, keyOffset, keyLength)
        .labelBuffer(labelBuffer, labelOffset, labelLength)
        .correlationId(correlationId);

    if (!toDriverCommandBuffer.write(ADD_COUNTER, buffer, 0, counterMessage.length()))
    {
        throw new AeronException("could not write add counter command");
    }

    return correlationId;
}
 
Example #16
Source File: DriverProxy.java    From aeron with Apache License 2.0 6 votes vote down vote up
public long addCounter(final int typeId, final String label)
{
    final long correlationId = toDriverCommandBuffer.nextCorrelationId();

    counterMessage
        .typeId(typeId)
        .keyBuffer(null, 0, 0)
        .label(label)
        .correlationId(correlationId);

    if (!toDriverCommandBuffer.write(ADD_COUNTER, buffer, 0, counterMessage.length()))
    {
        throw new AeronException("could not write add counter command");
    }

    return correlationId;
}
 
Example #17
Source File: StatusMessageFlyweight.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * The group tag (if present) from the Status Message.
 *
 * @return the group tag value or 0 if not present.
 */
public long groupTag()
{
    final int frameLength = frameLength();

    if (frameLength > HEADER_LENGTH)
    {
        if (frameLength > (HEADER_LENGTH + SIZE_OF_LONG))
        {
            throw new AeronException(
                "SM has longer application specific feedback (" + (frameLength - HEADER_LENGTH) + ") than gtag");
        }

        return getLongUnaligned(GROUP_TAG_FIELD_OFFSET);
    }

    return 0;
}
 
Example #18
Source File: CncFileReader.java    From aeron with Apache License 2.0 6 votes vote down vote up
private CncFileReader(final MappedByteBuffer cncByteBuffer)
{
    this.cncByteBuffer = cncByteBuffer;

    final DirectBuffer cncMetaDataBuffer = createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaDataBuffer.getInt(cncVersionOffset(0));

    try
    {
        checkVersion(cncVersion);
    }
    catch (final AeronException e)
    {
        IoUtil.unmap(cncByteBuffer);
        throw e;
    }

    this.cncVersion = cncVersion;
    this.cncSemanticVersion = SemanticVersion.toString(cncVersion);

    this.toDriverBuffer = CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer);

    this.countersReader = new CountersReader(
        createCountersMetaDataBuffer(cncByteBuffer, cncMetaDataBuffer),
        createCountersValuesBuffer(cncByteBuffer, cncMetaDataBuffer));
}
 
Example #19
Source File: ReceiveChannelEndpoint.java    From aeron with Apache License 2.0 6 votes vote down vote up
public void indicateActive()
{
    final long currentStatus = statusIndicator.get();
    if (currentStatus != ChannelEndpointStatus.INITIALIZING)
    {
        throw new AeronException(
            "channel cannot be registered unless INITIALISING: status=" + status(currentStatus));
    }

    if (null == multiRcvDestination)
    {
        final String bindAddressAndPort = bindAddressAndPort();
        statusIndicator.appendToLabel(bindAddressAndPort);
        updateLocalSocketAddress(bindAddressAndPort);
    }

    statusIndicator.setOrdered(ChannelEndpointStatus.ACTIVE);
}
 
Example #20
Source File: Subscription.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Asynchronously remove a previously added destination from a multi-destination Subscription.
 * <p>
 * Errors will be delivered asynchronously to the {@link Aeron.Context#errorHandler()}. Completion can be
 * tracked by passing the returned correlation id to {@link Aeron#isCommandActive(long)}.
 *
 * @param endpointChannel for the destination to remove.
 * @return the correlationId for the command.
 */
public long asyncRemoveDestination(final String endpointChannel)
{
    if (isClosed)
    {
        throw new AeronException("Subscription is closed");
    }

    return conductor.asyncRemoveRcvDestination(registrationId, endpointChannel);
}
 
Example #21
Source File: UdpChannelTransport.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Endpoint has moved to a new address. Handle this.
 *
 * @param newAddress      to send data to.
 * @param statusIndicator for the channel
 */
public void updateEndpoint(final InetSocketAddress newAddress, final AtomicCounter statusIndicator)
{
    try
    {
        if (null != sendDatagramChannel)
        {
            sendDatagramChannel.disconnect();
            sendDatagramChannel.connect(newAddress);
            connectAddress = newAddress;

            if (null != statusIndicator)
            {
                statusIndicator.setOrdered(ChannelEndpointStatus.ACTIVE);
            }
        }
    }
    catch (final Exception ex)
    {
        if (null != statusIndicator)
        {
            statusIndicator.setOrdered(ChannelEndpointStatus.ERRORED);
        }

        final String message = "re-resolve endpoint channel error - " + ex.getMessage() +
            " (at " + ex.getStackTrace()[0].toString() + "): " + udpChannel.originalUriString();

        throw new AeronException(message, ex);
    }
}
 
Example #22
Source File: Publication.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Asynchronously remove a previously added destination from a multi-destination-cast Publication.
 * <p>
 * Errors will be delivered asynchronously to the {@link Aeron.Context#errorHandler()}. Completion can be
 * tracked by passing the returned correlation id to {@link Aeron#isCommandActive(long)}.
 *
 * @param endpointChannel for the destination to remove.
 * @return the correlationId for the command.
 */
public long asyncRemoveDestination(final String endpointChannel)
{
    if (isClosed)
    {
        throw new AeronException("Publication is closed");
    }

    return conductor.asyncRemoveDestination(registrationId, endpointChannel);
}
 
Example #23
Source File: TermAppenderTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDetectInvalidTerm()
{
    final int length = 128;
    final int srcOffset = 0;
    final UnsafeBuffer buffer = new UnsafeBuffer(new byte[length]);

    logMetaDataBuffer.putLong(TERM_TAIL_COUNTER_OFFSET, packTail(TERM_ID + 1, 0));

    assertThrows(AeronException.class, () ->
        termAppender.appendUnfragmentedMessage(headerWriter, buffer, srcOffset, length, RVS, TERM_ID));
}
 
Example #24
Source File: Publication.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Asynchronously add a destination manually to a multi-destination-cast Publication.
 * <p>
 * Errors will be delivered asynchronously to the {@link Aeron.Context#errorHandler()}. Completion can be
 * tracked by passing the returned correlation id to {@link Aeron#isCommandActive(long)}.
 *
 * @param endpointChannel for the destination to add.
 * @return the correlationId for the command.
 */
public long asyncAddDestination(final String endpointChannel)
{
    if (isClosed)
    {
        throw new AeronException("Publication is closed");
    }

    return conductor.asyncAddDestination(registrationId, endpointChannel);
}
 
Example #25
Source File: Publication.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a previously added destination manually from a multi-destination-cast Publication.
 *
 * @param endpointChannel for the destination to remove.
 */
public void removeDestination(final String endpointChannel)
{
    if (isClosed)
    {
        throw new AeronException("Publication is closed");
    }

    conductor.removeDestination(originalRegistrationId, endpointChannel);
}
 
Example #26
Source File: Publication.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Add a destination manually to a multi-destination-cast Publication.
 *
 * @param endpointChannel for the destination to add.
 */
public void addDestination(final String endpointChannel)
{
    if (isClosed)
    {
        throw new AeronException("Publication is closed");
    }

    conductor.addDestination(originalRegistrationId, endpointChannel);
}
 
Example #27
Source File: Counter.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a read-write view of an existing counter.
 *
 * @param countersReader for getting access to the buffers.
 * @param registrationId assigned by the driver for the counter or {@link Aeron#NULL_VALUE} if not known.
 * @param counterId      for the counter to be viewed.
 * @throws AeronException if the id has for the counter has not been allocated.
 */
public Counter(final CountersReader countersReader, final long registrationId, final int counterId)
{
    super(countersReader.valuesBuffer(), counterId);

    if (countersReader.getCounterState(counterId) != CountersReader.RECORD_ALLOCATED)
    {
        throw new AeronException("Counter id is not allocated: " + counterId);
    }

    this.registrationId = registrationId;
    this.clientConductor = null;
}
 
Example #28
Source File: CncFileDescriptor.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Check the version of the CnC file is compatible with application.
 *
 * @param cncVersion of the CnC file.
 * @throws AeronException if the major versions are not compatible.
 */
public static void checkVersion(final int cncVersion)
{
    if (SemanticVersion.major(CNC_VERSION) != SemanticVersion.major(cncVersion))
    {
        throw new AeronException("CnC version not compatible:" +
            " app=" + SemanticVersion.toString(CNC_VERSION) +
            " file=" + SemanticVersion.toString(cncVersion));
    }
}
 
Example #29
Source File: LogPublisher.java    From aeron with Apache License 2.0 5 votes vote down vote up
private static void checkResult(final long result)
{
    if (result == Publication.NOT_CONNECTED ||
        result == Publication.CLOSED ||
        result == Publication.MAX_POSITION_EXCEEDED)
    {
        throw new AeronException("unexpected publication state: " + result);
    }
}
 
Example #30
Source File: Aeron.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link CountersReader} for the Aeron media driver counters.
 *
 * @return new {@link CountersReader} for the Aeron media driver in use.
 */
public CountersReader countersReader()
{
    if (1 == isClosed)
    {
        throw new AeronException("client is closed");
    }

    return conductor.countersReader();
}