use of io.aeron.driver.uri.AeronUri 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);
}
}
use of io.aeron.driver.uri.AeronUri in project Aeron by real-logic.
the class DriverConductor method onAddNetworkPublication.
void onAddNetworkPublication(final String channel, final int streamId, final long registrationId, final long clientId, final boolean isExclusive) {
final UdpChannel udpChannel = UdpChannel.parse(channel);
final AeronUri aeronUri = udpChannel.aeronUri();
final int mtuLength = getMtuLength(aeronUri, context.mtuLength());
final int termLength = getTermBufferLength(aeronUri, context.publicationTermBufferLength());
final SendChannelEndpoint channelEndpoint = getOrCreateSendChannelEndpoint(udpChannel);
NetworkPublication publication = null;
if (!isExclusive) {
publication = findPublication(networkPublications, streamId, channelEndpoint);
}
if (null == publication) {
final int sessionId = nextSessionId++;
final int initialTermId = BitUtil.generateRandomisedId();
final RetransmitHandler retransmitHandler = new RetransmitHandler(nanoClock, context.systemCounters(), RETRANSMIT_UNICAST_DELAY_GENERATOR, RETRANSMIT_UNICAST_LINGER_GENERATOR);
final FlowControl flowControl = udpChannel.isMulticast() || udpChannel.hasExplicitControl() ? context.multicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId) : context.unicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId);
publication = new NetworkPublication(registrationId, channelEndpoint, nanoClock, toDriverCommands::consumerHeartbeatTime, newNetworkPublicationLog(sessionId, streamId, initialTermId, udpChannel, registrationId, termLength), PublisherLimit.allocate(countersManager, registrationId, sessionId, streamId, channel), SenderPos.allocate(countersManager, registrationId, sessionId, streamId, channel), SenderLimit.allocate(countersManager, registrationId, sessionId, streamId, channel), sessionId, streamId, initialTermId, mtuLength, context.systemCounters(), flowControl, retransmitHandler, networkPublicationThreadLocals, publicationUnblockTimeoutNs, isExclusive);
channelEndpoint.incRef();
networkPublications.add(publication);
senderProxy.newNetworkPublication(publication);
linkSpies(subscriptionLinks, publication);
} else if (publication.mtuLength() != mtuLength) {
throw new IllegalStateException("Existing publication has different MTU length: existing=" + publication.mtuLength() + " requested=" + mtuLength);
}
publicationLinks.add(new PublicationLink(registrationId, publication, getOrAddClient(clientId)));
clientProxy.onPublicationReady(registrationId, streamId, publication.sessionId(), publication.rawLog().fileName(), publication.publisherLimitId(), isExclusive);
}
use of io.aeron.driver.uri.AeronUri in project Aeron by real-logic.
the class DriverConductor method onRemoveDestination.
void onRemoveDestination(final long registrationId, final String destinationChannel, final long correlationId) {
SendChannelEndpoint sendChannelEndpoint = null;
for (int i = 0, size = networkPublications.size(); i < size; i++) {
final NetworkPublication publication = networkPublications.get(i);
if (registrationId == publication.registrationId()) {
sendChannelEndpoint = publication.channelEndpoint();
break;
}
}
if (null == sendChannelEndpoint) {
throw new ControlProtocolException(UNKNOWN_PUBLICATION, "Unknown publication: " + registrationId);
}
sendChannelEndpoint.validateAllowsManualControl();
final AeronUri aeronUri = AeronUri.parse(destinationChannel);
final InetSocketAddress dstAddress = UdpChannel.destinationAddress(aeronUri);
senderProxy.removeDestination(sendChannelEndpoint, dstAddress);
clientProxy.operationSucceeded(correlationId);
}
use of io.aeron.driver.uri.AeronUri in project Aeron by real-logic.
the class DriverConductor method onAddDestination.
void onAddDestination(final long registrationId, final String destinationChannel, final long correlationId) {
SendChannelEndpoint sendChannelEndpoint = null;
for (int i = 0, size = networkPublications.size(); i < size; i++) {
final NetworkPublication publication = networkPublications.get(i);
if (registrationId == publication.registrationId()) {
sendChannelEndpoint = publication.channelEndpoint();
break;
}
}
if (null == sendChannelEndpoint) {
throw new ControlProtocolException(UNKNOWN_PUBLICATION, "Unknown publication: " + registrationId);
}
sendChannelEndpoint.validateAllowsManualControl();
final AeronUri aeronUri = AeronUri.parse(destinationChannel);
final InetSocketAddress dstAddress = UdpChannel.destinationAddress(aeronUri);
senderProxy.addDestination(sendChannelEndpoint, dstAddress);
clientProxy.operationSucceeded(correlationId);
}
Aggregations