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
* @return a new {@link UdpChannel}
* @throws InvalidChannelException if an error occurs.
*/
public static UdpChannel parse(final String channelUriString) {
try {
final ChannelUri channelUri = ChannelUri.parse(channelUriString);
validateConfiguration(channelUri);
InetSocketAddress endpointAddress = getEndpointAddress(channelUri);
final InetSocketAddress explicitControlAddress = getExplicitControlAddress(channelUri);
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);
}
final Context context = new Context().uriStr(channelUriString).channelUri(channelUri);
if (endpointAddress.getAddress().isMulticastAddress()) {
final InetSocketAddress controlAddress = getMulticastControlAddress(endpointAddress);
final InterfaceSearchAddress searchAddress = getInterfaceSearchAddress(channelUri);
final NetworkInterface localInterface = findInterface(searchAddress);
final InetSocketAddress resolvedAddress = resolveToAddressOfInterface(localInterface, searchAddress);
context.isMulticast(true).localControlAddress(resolvedAddress).remoteControlAddress(controlAddress).localDataAddress(resolvedAddress).remoteDataAddress(endpointAddress).localInterface(localInterface).multicastTtl(getMulticastTtl(channelUri)).protocolFamily(getProtocolFamily(endpointAddress.getAddress())).canonicalForm(canonicalise(resolvedAddress, 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(channelUri);
final InetSocketAddress localAddress = searchAddress.getInetAddress().isAnyLocalAddress() ? searchAddress.getAddress() : resolveToAddressOfInterface(findInterface(searchAddress), searchAddress);
context.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.ChannelUri in project aeron by real-logic.
the class MultiNodeTest method shouldBecomeFollowerStaticThreeNodeConfigWithElectionFromPreviousLog.
@Test(timeout = 10_000L)
public void shouldBecomeFollowerStaticThreeNodeConfigWithElectionFromPreviousLog() {
final long position = ConsensusModuleHarness.makeRecordingLog(10, 100, null, new ConsensusModule.Context());
final ClusteredService mockService = mock(ClusteredService.class);
final ConsensusModule.Context context = new ConsensusModule.Context().clusterMembers(THREE_NODE_MEMBERS).memberStatusChannel("aeron:udp?endpoint=localhost:9020").appointedLeaderId(1);
try (ConsensusModuleHarness harness = new ConsensusModuleHarness(context, mockService, mockMemberStatusListeners, false, true)) {
harness.memberStatusPublisher().requestVote(harness.memberStatusPublication(1), 1, 0, position, 1);
harness.awaitMemberStatusMessage(1);
verify(mockMemberStatusListeners[1]).onVote(1, 0, position, 1, 0, true);
final int logSessionId = 123456;
final ChannelUri channelUri = ChannelUri.parse(context.logChannel());
channelUri.put(CommonContext.ENDPOINT_PARAM_NAME, harness.member(0).logEndpoint());
channelUri.put(CommonContext.SESSION_ID_PARAM_NAME, Integer.toString(logSessionId));
final Publication logPublication = harness.aeron().addExclusivePublication(channelUri.toString(), context.logStreamId());
harness.memberStatusPublisher().commitPosition(harness.memberStatusPublication(1), position, 1, 1, logSessionId);
harness.awaitMemberStatusMessage(1);
verify(mockMemberStatusListeners[1]).onAppendedPosition(position, 1, 0);
harness.awaitServiceOnStart();
harness.awaitServiceOnMessageCounter(10);
verify(mockService, times(10)).onSessionMessage(anyLong(), anyLong(), anyLong(), any(), anyInt(), eq(100), any());
}
}
use of io.aeron.ChannelUri 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 ChannelUri channelUri = ChannelUri.parse(destinationChannel);
final InetSocketAddress dstAddress = UdpChannel.destinationAddress(channelUri);
senderProxy.removeDestination(sendChannelEndpoint, dstAddress);
clientProxy.operationSucceeded(correlationId);
}
use of io.aeron.ChannelUri in project aeron by real-logic.
the class DriverConductor method getOrAddIpcPublication.
private IpcPublication getOrAddIpcPublication(final long correlationId, final int streamId, final String channel, final boolean isExclusive) {
IpcPublication publication = null;
final ChannelUri channelUri = ChannelUri.parse(channel);
final PublicationParams params = getPublicationParams(context, channelUri, isExclusive, true);
if (!isExclusive) {
publication = findSharedIpcPublication(ipcPublications, streamId);
}
if (null == publication) {
if (params.hasSessionId) {
confirmSessionIdNotInUse(params.sessionId);
}
validateMtuForMaxMessage(params, isExclusive);
publication = addIpcPublication(correlationId, streamId, channel, isExclusive, params);
} else {
confirmMatch(channelUri, params, publication.rawLog(), publication.sessionId());
}
return publication;
}
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