use of io.aeron.ChannelUri in project Aeron by real-logic.
the class DriverConductor method onRemoveSendDestination.
void onRemoveSendDestination(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 ChannelUri channelUri = ChannelUri.parse(destinationChannel);
final InetSocketAddress dstAddress = UdpChannel.destinationAddress(channelUri, nameResolver);
senderProxy.removeDestination(sendChannelEndpoint, channelUri, dstAddress);
clientProxy.operationSucceeded(correlationId);
}
use of io.aeron.ChannelUri in project Aeron by real-logic.
the class DriverConductor method onAddIpcPublication.
void onAddIpcPublication(final String channel, final int streamId, final long correlationId, final long clientId, final boolean isExclusive) {
IpcPublication publication = null;
final ChannelUri channelUri = ChannelUri.parse(channel);
final PublicationParams params = getPublicationParams(channelUri, ctx, this, true);
if (!isExclusive) {
publication = findSharedIpcPublication(ipcPublications, streamId);
}
boolean isNewPublication = false;
if (null == publication) {
if (params.hasSessionId) {
checkForSessionClash(params.sessionId, streamId, IPC_MEDIA, channel);
}
validateMtuForMaxMessage(params, channel);
publication = addIpcPublication(correlationId, clientId, streamId, channel, isExclusive, params);
isNewPublication = true;
} else {
confirmMatch(channelUri, params, publication.rawLog(), publication.sessionId(), publication.channel(), publication.initialTermId(), publication.startingTermId(), publication.startingTermOffset());
}
publicationLinks.add(new PublicationLink(correlationId, getOrAddClient(clientId), publication));
clientProxy.onPublicationReady(correlationId, publication.registrationId(), streamId, publication.sessionId(), publication.rawLog().fileName(), publication.publisherLimitId(), ChannelEndpointStatus.NO_ID_ALLOCATED, isExclusive);
if (isNewPublication) {
linkIpcSubscriptions(publication);
}
}
use of io.aeron.ChannelUri in project Aeron by real-logic.
the class DriverConductor method onAddNetworkPublication.
void onAddNetworkPublication(final String channel, final int streamId, final long correlationId, final long clientId, final boolean isExclusive) {
final UdpChannel udpChannel = UdpChannel.parse(channel, nameResolver);
final ChannelUri channelUri = udpChannel.channelUri();
final PublicationParams params = getPublicationParams(channelUri, ctx, this, false);
validateEndpointForPublication(udpChannel);
validateMtuForMaxMessage(params, channel);
final SendChannelEndpoint channelEndpoint = getOrCreateSendChannelEndpoint(params, udpChannel, correlationId);
NetworkPublication publication = null;
if (!isExclusive) {
publication = findPublication(networkPublications, streamId, channelEndpoint);
}
boolean isNewPublication = false;
if (null == publication) {
if (params.hasSessionId) {
checkForSessionClash(params.sessionId, streamId, udpChannel.canonicalForm(), channel);
}
publication = newNetworkPublication(correlationId, clientId, streamId, channel, udpChannel, channelEndpoint, params, isExclusive);
isNewPublication = true;
} else {
confirmMatch(channelUri, params, publication.rawLog(), publication.sessionId(), publication.channel(), publication.initialTermId(), publication.startingTermId(), publication.startingTermOffset());
validateSpiesSimulateConnection(params, publication.spiesSimulateConnection(), channel, publication.channel());
}
publicationLinks.add(new PublicationLink(correlationId, getOrAddClient(clientId), publication));
clientProxy.onPublicationReady(correlationId, publication.registrationId(), streamId, publication.sessionId(), publication.rawLog().fileName(), publication.publisherLimitId(), channelEndpoint.statusIndicatorCounterId(), isExclusive);
if (isNewPublication) {
linkSpies(subscriptionLinks, publication);
}
}
use of io.aeron.ChannelUri in project aeron by real-logic.
the class UdpChannel method parse.
/**
* Parse channel URI and create a {@link UdpChannel}.
*
* @param channelUriString to parse.
* @param nameResolver to use for resolving names.
* @param isDestination to identify if it is a destination within a channel.
* @return a new {@link UdpChannel} as the result of parsing.
* @throws InvalidChannelException if an error occurs.
*/
@SuppressWarnings("MethodLength")
public static UdpChannel parse(final String channelUriString, final NameResolver nameResolver, final boolean isDestination) {
try {
final ChannelUri channelUri = ChannelUri.parse(channelUriString);
validateConfiguration(channelUri);
InetSocketAddress endpointAddress = getEndpointAddress(channelUri, nameResolver);
final InetSocketAddress controlAddress = getExplicitControlAddress(channelUri, nameResolver);
final String tagIdStr = channelUri.channelTag();
final String controlMode = channelUri.get(CommonContext.MDC_CONTROL_MODE_PARAM_NAME);
final boolean isManualControlMode = CommonContext.MDC_CONTROL_MODE_MANUAL.equals(controlMode);
final boolean isDynamicControlMode = CommonContext.MDC_CONTROL_MODE_DYNAMIC.equals(controlMode);
final int socketRcvbufLength = parseBufferLength(channelUri, CommonContext.SOCKET_RCVBUF_PARAM_NAME);
final int socketSndbufLength = parseBufferLength(channelUri, CommonContext.SOCKET_SNDBUF_PARAM_NAME);
final int receiverWindowLength = parseBufferLength(channelUri, CommonContext.RECEIVER_WINDOW_LENGTH_PARAM_NAME);
final boolean requiresAdditionalSuffix = !isDestination && (null == endpointAddress && null == controlAddress || (null != endpointAddress && endpointAddress.getPort() == 0) || (null != controlAddress && controlAddress.getPort() == 0));
final boolean hasNoDistinguishingCharacteristic = null == endpointAddress && null == controlAddress && null == tagIdStr;
if (isDynamicControlMode && null == controlAddress) {
throw new IllegalArgumentException("explicit control expected with dynamic control mode: " + channelUriString);
}
if (hasNoDistinguishingCharacteristic && !isManualControlMode) {
throw new IllegalArgumentException("URIs for UDP must specify an endpoint, control, tags, or control-mode=manual: " + channelUriString);
}
if (null != endpointAddress && endpointAddress.isUnresolved()) {
throw new UnknownHostException("could not resolve endpoint address: " + endpointAddress);
}
if (null != controlAddress && controlAddress.isUnresolved()) {
throw new UnknownHostException("could not resolve control address: " + controlAddress);
}
boolean hasExplicitEndpoint = true;
if (null == endpointAddress) {
hasExplicitEndpoint = false;
endpointAddress = null != controlAddress && controlAddress.getAddress() instanceof Inet6Address ? ANY_IPV6 : ANY_IPV4;
}
final Context context = new Context().uriStr(channelUriString).channelUri(channelUri).isManualControlMode(isManualControlMode).isDynamicControlMode(isDynamicControlMode).hasExplicitEndpoint(hasExplicitEndpoint).hasNoDistinguishingCharacteristic(hasNoDistinguishingCharacteristic).socketRcvbufLength(socketRcvbufLength).socketSndbufLength(socketSndbufLength).receiverWindowLength(receiverWindowLength);
if (null != tagIdStr) {
context.hasTagId(true).tagId(Long.parseLong(tagIdStr));
}
if (endpointAddress.getAddress().isMulticastAddress()) {
final InterfaceSearchAddress searchAddress = getInterfaceSearchAddress(channelUri);
final NetworkInterface localInterface = findInterface(searchAddress);
final InetSocketAddress resolvedAddress = resolveToAddressOfInterface(localInterface, searchAddress);
context.isMulticast(true).localControlAddress(resolvedAddress).remoteControlAddress(getMulticastControlAddress(endpointAddress)).localDataAddress(resolvedAddress).remoteDataAddress(endpointAddress).localInterface(localInterface).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalise(null, resolvedAddress, null, endpointAddress));
final String ttlValue = channelUri.get(CommonContext.TTL_PARAM_NAME);
if (null != ttlValue) {
context.hasMulticastTtl(true).multicastTtl(Integer.parseInt(ttlValue));
}
} else if (null != controlAddress) {
final String controlVal = channelUri.get(CommonContext.MDC_CONTROL_PARAM_NAME);
final String endpointVal = channelUri.get(CommonContext.ENDPOINT_PARAM_NAME);
String suffix = "";
if (requiresAdditionalSuffix) {
suffix = null != tagIdStr ? "#" + tagIdStr : "-" + UNIQUE_CANONICAL_FORM_VALUE.getAndAdd(1);
}
final String canonicalForm = canonicalise(controlVal, controlAddress, endpointVal, endpointAddress) + suffix;
context.hasExplicitControl(true).remoteControlAddress(endpointAddress).remoteDataAddress(endpointAddress).localControlAddress(controlAddress).localDataAddress(controlAddress).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalForm);
} else {
final InterfaceSearchAddress searchAddress = getInterfaceSearchAddress(channelUri);
final InetSocketAddress localAddress = searchAddress.getInetAddress().isAnyLocalAddress() ? searchAddress.getAddress() : resolveToAddressOfInterface(findInterface(searchAddress), searchAddress);
final String endpointVal = channelUri.get(CommonContext.ENDPOINT_PARAM_NAME);
String suffix = "";
if (requiresAdditionalSuffix) {
suffix = (null != tagIdStr) ? "#" + tagIdStr : ("-" + UNIQUE_CANONICAL_FORM_VALUE.getAndAdd(1));
}
context.remoteControlAddress(endpointAddress).remoteDataAddress(endpointAddress).localControlAddress(localAddress).localDataAddress(localAddress).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalise(null, localAddress, endpointVal, endpointAddress) + suffix);
}
context.channelReceiveTimestampOffset(parseTimestampOffset(channelUri, CHANNEL_RECEIVE_TIMESTAMP_OFFSET_PARAM_NAME));
context.channelSendTimestampOffset(parseTimestampOffset(channelUri, CHANNEL_SEND_TIMESTAMP_OFFSET_PARAM_NAME));
return new UdpChannel(context);
} catch (final Exception ex) {
throw new InvalidChannelException(ex);
}
}
use of io.aeron.ChannelUri in project aeron by real-logic.
the class DriverConductor method onAddSendDestination.
void onAddSendDestination(final long registrationId, final String destinationChannel, final long correlationId) {
final ChannelUri channelUri = ChannelUri.parse(destinationChannel);
validateDestinationUri(channelUri, destinationChannel);
validateSendDestinationUri(channelUri, destinationChannel);
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 InetSocketAddress dstAddress = UdpChannel.destinationAddress(channelUri, nameResolver);
senderProxy.addDestination(sendChannelEndpoint, channelUri, dstAddress);
clientProxy.operationSucceeded(correlationId);
}
Aggregations