Search in sources :

Example 6 with AeronException

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

the class UdpChannelTransport method openDatagramChannel.

/**
 * Open the underlying channel for reading and writing.
 *
 * @param statusIndicator to set for {@link ChannelEndpointStatus} which could be
 *                        {@link ChannelEndpointStatus#ERRORED}.
 */
public void openDatagramChannel(final AtomicCounter statusIndicator) {
    try {
        sendDatagramChannel = DatagramChannel.open(udpChannel.protocolFamily());
        receiveDatagramChannel = sendDatagramChannel;
        if (udpChannel.isMulticast()) {
            if (null != connectAddress) {
                receiveDatagramChannel = DatagramChannel.open(udpChannel.protocolFamily());
            }
            receiveDatagramChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
            receiveDatagramChannel.bind(new InetSocketAddress(endPointAddress.getPort()));
            receiveDatagramChannel.join(endPointAddress.getAddress(), udpChannel.localInterface());
            sendDatagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_IF, udpChannel.localInterface());
            if (udpChannel.hasMulticastTtl()) {
                sendDatagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, udpChannel.multicastTtl());
                multicastTtl = sendDatagramChannel.getOption(StandardSocketOptions.IP_MULTICAST_TTL);
            } else if (context.socketMulticastTtl() != 0) {
                sendDatagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, context.socketMulticastTtl());
                multicastTtl = sendDatagramChannel.getOption(StandardSocketOptions.IP_MULTICAST_TTL);
            }
        } else {
            sendDatagramChannel.bind(bindAddress);
        }
        if (null != connectAddress) {
            sendDatagramChannel.connect(connectAddress);
        }
        if (0 != socketSndbufLength()) {
            sendDatagramChannel.setOption(SO_SNDBUF, socketSndbufLength());
        }
        if (0 != socketRcvbufLength()) {
            receiveDatagramChannel.setOption(SO_RCVBUF, socketRcvbufLength());
        }
        sendDatagramChannel.configureBlocking(false);
        receiveDatagramChannel.configureBlocking(false);
    } catch (final IOException ex) {
        if (null != statusIndicator) {
            statusIndicator.setOrdered(ChannelEndpointStatus.ERRORED);
        }
        CloseHelper.quietClose(sendDatagramChannel);
        if (receiveDatagramChannel != sendDatagramChannel) {
            CloseHelper.quietClose(receiveDatagramChannel);
        }
        sendDatagramChannel = null;
        receiveDatagramChannel = null;
        final String message = "channel error - " + ex.getMessage() + " (at " + ex.getStackTrace()[0].toString() + "): " + udpChannel.originalUriString();
        throw new AeronException(message, ex);
    }
}
Also used : AeronException(io.aeron.exceptions.AeronException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException)

Example 7 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 8 with AeronException

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

the class UdpChannelTransport method openDatagramChannel.

/**
 * Open the underlying channel for reading and writing.
 *
 * @param statusIndicator to set for {@link ChannelEndpointStatus} which could be
 *                        {@link ChannelEndpointStatus#ERRORED}.
 */
public void openDatagramChannel(final AtomicCounter statusIndicator) {
    try {
        sendDatagramChannel = DatagramChannel.open(udpChannel.protocolFamily());
        receiveDatagramChannel = sendDatagramChannel;
        if (udpChannel.isMulticast()) {
            if (null != connectAddress) {
                receiveDatagramChannel = DatagramChannel.open(udpChannel.protocolFamily());
            }
            receiveDatagramChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
            receiveDatagramChannel.bind(new InetSocketAddress(endPointAddress.getPort()));
            receiveDatagramChannel.join(endPointAddress.getAddress(), udpChannel.localInterface());
            sendDatagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_IF, udpChannel.localInterface());
            if (udpChannel.hasMulticastTtl()) {
                sendDatagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, udpChannel.multicastTtl());
                multicastTtl = sendDatagramChannel.getOption(StandardSocketOptions.IP_MULTICAST_TTL);
            } else if (context.socketMulticastTtl() != 0) {
                sendDatagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, context.socketMulticastTtl());
                multicastTtl = sendDatagramChannel.getOption(StandardSocketOptions.IP_MULTICAST_TTL);
            }
        } else {
            sendDatagramChannel.bind(bindAddress);
        }
        if (null != connectAddress) {
            sendDatagramChannel.connect(connectAddress);
        }
        if (0 != socketSndbufLength()) {
            sendDatagramChannel.setOption(SO_SNDBUF, socketSndbufLength());
        }
        if (0 != socketRcvbufLength()) {
            receiveDatagramChannel.setOption(SO_RCVBUF, socketRcvbufLength());
        }
        sendDatagramChannel.configureBlocking(false);
        receiveDatagramChannel.configureBlocking(false);
    } catch (final IOException ex) {
        if (null != statusIndicator) {
            statusIndicator.setOrdered(ChannelEndpointStatus.ERRORED);
        }
        CloseHelper.quietClose(sendDatagramChannel);
        if (receiveDatagramChannel != sendDatagramChannel) {
            CloseHelper.quietClose(receiveDatagramChannel);
        }
        sendDatagramChannel = null;
        receiveDatagramChannel = null;
        final String message = "channel error - " + ex.getMessage() + " (at " + ex.getStackTrace()[0].toString() + "): " + udpChannel.originalUriString();
        throw new AeronException(message, ex);
    }
}
Also used : AeronException(io.aeron.exceptions.AeronException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException)

Example 9 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)

Example 10 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)

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