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);
}
}
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());
}
}
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);
}
}
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);
}
}
}
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();
}
Aggregations