use of io.aeron.driver.exceptions.InvalidChannelException in project Aeron by real-logic.
the class UdpChannel method parse.
/**
* Parse URI and create channel
*
* @param uriStr to parse
* @return created channel
*/
public static UdpChannel parse(final String uriStr) {
try {
final AeronUri aeronUri = AeronUri.parse(uriStr);
validateConfiguration(aeronUri);
final Context context = new Context().uriStr(uriStr).aeronUri(aeronUri);
InetSocketAddress endpointAddress = getEndpointAddress(aeronUri);
final InetSocketAddress explicitControlAddress = getExplicitControlAddress(aeronUri);
if (null == endpointAddress && null == explicitControlAddress) {
throw new IllegalArgumentException("Aeron URIs for UDP must specify an endpoint address and/or a control address");
}
if (null != endpointAddress && endpointAddress.isUnresolved()) {
throw new UnknownHostException("could not resolve endpoint address: " + endpointAddress);
}
if (null != explicitControlAddress && explicitControlAddress.isUnresolved()) {
throw new UnknownHostException("could not resolve control address: " + explicitControlAddress);
}
if (null == endpointAddress) {
// just control specified, a multi-destination-cast Publication, so wildcard the endpoint
endpointAddress = new InetSocketAddress("0.0.0.0", 0);
}
if (endpointAddress.getAddress().isMulticastAddress()) {
final InetSocketAddress controlAddress = getMulticastControlAddress(endpointAddress);
final InterfaceSearchAddress searchAddress = getInterfaceSearchAddress(aeronUri);
context.hasExplicitControl(false).localControlAddress(resolveToAddressOfInterface(findInterface(searchAddress), searchAddress)).remoteControlAddress(controlAddress).localDataAddress(resolveToAddressOfInterface(findInterface(searchAddress), searchAddress)).remoteDataAddress(endpointAddress).localInterface(findInterface(searchAddress)).multicastTtl(getMulticastTtl(aeronUri)).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalise(resolveToAddressOfInterface(findInterface(searchAddress), searchAddress), endpointAddress));
} else if (null != explicitControlAddress) {
context.hasExplicitControl(true).remoteControlAddress(endpointAddress).remoteDataAddress(endpointAddress).localControlAddress(explicitControlAddress).localDataAddress(explicitControlAddress).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalise(explicitControlAddress, endpointAddress));
} else {
final InterfaceSearchAddress searchAddress = getInterfaceSearchAddress(aeronUri);
final InetSocketAddress localAddress;
if (searchAddress.getInetAddress().isAnyLocalAddress()) {
localAddress = searchAddress.getAddress();
} else {
localAddress = resolveToAddressOfInterface(findInterface(searchAddress), searchAddress);
}
context.hasExplicitControl(false).remoteControlAddress(endpointAddress).remoteDataAddress(endpointAddress).localControlAddress(localAddress).localDataAddress(localAddress).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalise(localAddress, endpointAddress));
}
return new UdpChannel(context);
} catch (final Exception ex) {
throw new InvalidChannelException(ErrorCode.INVALID_CHANNEL, ex);
}
}
Aggregations