Search in sources :

Example 1 with AeronException

use of io.aeron.exceptions.AeronException in project Aeron by real-logic.

the class ConsensusModuleContextCloseTests method ownsAeronClient.

@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();
}
Also used : InOrder(org.mockito.InOrder) AeronException(io.aeron.exceptions.AeronException) Test(org.junit.jupiter.api.Test)

Example 2 with AeronException

use of io.aeron.exceptions.AeronException in project Aeron by real-logic.

the class FileStoreLogFactory method checkStorage.

private void checkStorage(final long logLength) {
    if (checkStorage) {
        final long usableSpace = getUsableSpace();
        if (usableSpace < logLength) {
            throw new AeronException("insufficient usable storage for new log of length=" + logLength + " in " + fileStore);
        }
        if (usableSpace <= lowStorageWarningThreshold) {
            final String msg = "space is running low: threshold=" + lowStorageWarningThreshold + " usable=" + usableSpace + " in " + fileStore;
            errorHandler.onError(new AeronException(msg, AeronException.Category.WARN));
        }
    }
}
Also used : AeronException(io.aeron.exceptions.AeronException)

Example 3 with AeronException

use of io.aeron.exceptions.AeronException in project Aeron by real-logic.

the class UdpChannelTransport method updateEndpoint.

/**
 * 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);
    }
}
Also used : AeronException(io.aeron.exceptions.AeronException) IOException(java.io.IOException) AeronException(io.aeron.exceptions.AeronException) PortUnreachableException(java.net.PortUnreachableException)

Example 4 with AeronException

use of io.aeron.exceptions.AeronException in project Aeron by real-logic.

the class DriverTool method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
public static void main(final String[] args) {
    boolean printPidOnly = false;
    boolean terminateDriver = false;
    if (0 != args.length) {
        checkForHelp(args);
        if (args[0].equals("pid")) {
            printPidOnly = true;
        } else if (args[0].equals("terminate")) {
            terminateDriver = true;
        }
    }
    final File cncFile = CommonContext.newDefaultCncFile();
    final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
    final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));
    checkVersion(cncVersion);
    final ManyToOneRingBuffer toDriver = new ManyToOneRingBuffer(createToDriverBuffer(cncByteBuffer, cncMetaData));
    if (printPidOnly) {
        System.out.println(pid(cncMetaData));
    } else if (terminateDriver) {
        final DriverProxy driverProxy = new DriverProxy(toDriver, toDriver.nextCorrelationId());
        if (!driverProxy.terminateDriver(null, 0, 0)) {
            throw new AeronException("could not send termination request.");
        }
    } else {
        System.out.println("Command `n Control file: " + cncFile);
        System.out.format("Version: %d, PID: %d%n", cncVersion, pid(cncMetaData));
        printDateActivityAndStartTimestamps(startTimestampMs(cncMetaData), toDriver.consumerHeartbeatTime());
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) AeronException(io.aeron.exceptions.AeronException) DriverProxy(io.aeron.DriverProxy) File(java.io.File)

Example 5 with AeronException

use of io.aeron.exceptions.AeronException in project aeron by real-logic.

the class Aeron method waitForFileMapping.

@SuppressWarnings("try")
private static MappedByteBuffer waitForFileMapping(final File file, final EpochClock clock, final long deadlineMs) {
    while (true) {
        while (!file.exists() || file.length() < CncFileDescriptor.META_DATA_LENGTH) {
            if (clock.time() > deadlineMs) {
                throw new DriverTimeoutException("CnC file not created: " + file.getAbsolutePath());
            }
            sleep(Configuration.IDLE_SLEEP_MS);
        }
        try (FileChannel fileChannel = FileChannel.open(file.toPath(), READ, WRITE)) {
            final long fileSize = fileChannel.size();
            if (fileSize < CncFileDescriptor.META_DATA_LENGTH) {
                if (clock.time() > deadlineMs) {
                    throw new DriverTimeoutException("CnC file is created but not populated");
                }
                fileChannel.close();
                sleep(Configuration.IDLE_SLEEP_MS);
                continue;
            }
            return fileChannel.map(READ_WRITE, 0, fileSize);
        } catch (final NoSuchFileException ignore) {
        } catch (final IOException ex) {
            throw new AeronException("cannot open CnC file", ex);
        }
    }
}
Also used : AeronException(io.aeron.exceptions.AeronException) FileChannel(java.nio.channels.FileChannel) DriverTimeoutException(io.aeron.exceptions.DriverTimeoutException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Aggregations

AeronException (io.aeron.exceptions.AeronException)12 IOException (java.io.IOException)6 DriverProxy (io.aeron.DriverProxy)2 DriverTimeoutException (io.aeron.exceptions.DriverTimeoutException)2 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 PortUnreachableException (java.net.PortUnreachableException)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 DirectBuffer (org.agrona.DirectBuffer)2 ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)2 Test (org.junit.jupiter.api.Test)2 InOrder (org.mockito.InOrder)2