Search in sources :

Example 1 with InterfaceSearchAddress

use of io.aeron.driver.uri.InterfaceSearchAddress 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);
    }
}
Also used : InvalidChannelException(io.aeron.driver.exceptions.InvalidChannelException) AeronUri(io.aeron.driver.uri.AeronUri) InterfaceSearchAddress(io.aeron.driver.uri.InterfaceSearchAddress) InvalidChannelException(io.aeron.driver.exceptions.InvalidChannelException)

Aggregations

InvalidChannelException (io.aeron.driver.exceptions.InvalidChannelException)1 AeronUri (io.aeron.driver.uri.AeronUri)1 InterfaceSearchAddress (io.aeron.driver.uri.InterfaceSearchAddress)1