use of io.aeron.driver.media.SendChannelEndpoint in project Aeron by real-logic.
the class DriverConductor method getOrCreateSendChannelEndpoint.
private SendChannelEndpoint getOrCreateSendChannelEndpoint(final UdpChannel udpChannel) {
SendChannelEndpoint channelEndpoint = sendChannelEndpointByChannelMap.get(udpChannel.canonicalForm());
if (null == channelEndpoint) {
channelEndpoint = context.sendChannelEndpointSupplier().newInstance(udpChannel, SendChannelStatus.allocate(countersManager, udpChannel.originalUriString()), context);
sendChannelEndpointByChannelMap.put(udpChannel.canonicalForm(), channelEndpoint);
senderProxy.registerSendChannelEndpoint(channelEndpoint);
}
return channelEndpoint;
}
use of io.aeron.driver.media.SendChannelEndpoint in project Aeron by real-logic.
the class SenderTest method setUp.
@Before
public void setUp() throws Exception {
final SendChannelEndpoint mockSendChannelEndpoint = mock(SendChannelEndpoint.class);
when(mockSendChannelEndpoint.udpChannel()).thenReturn(udpChannel);
when(mockSendChannelEndpoint.send(any())).thenAnswer(saveByteBufferAnswer);
when(mockSystemCounters.get(any())).thenReturn(mock(AtomicCounter.class));
sender = new Sender(new MediaDriver.Context().controlTransportPoller(mockTransportPoller).systemCounters(mockSystemCounters).senderCommandQueue(senderCommandQueue).nanoClock(() -> currentTimestamp));
LogBufferDescriptor.initialiseTailWithTermId(rawLog.metaData(), 0, INITIAL_TERM_ID);
termAppenders = new TermAppender[PARTITION_COUNT];
for (int i = 0; i < PARTITION_COUNT; i++) {
termAppenders[i] = new TermAppender(rawLog.termBuffers()[i], rawLog.metaData(), i);
}
publication = new NetworkPublication(1, mockSendChannelEndpoint, () -> currentTimestamp, () -> currentTimestamp / (1_000_000L), rawLog, mock(Position.class), new AtomicLongPosition(), new AtomicLongPosition(), SESSION_ID, STREAM_ID, INITIAL_TERM_ID, MAX_FRAME_LENGTH, mockSystemCounters, flowControl, mockRetransmitHandler, new NetworkPublicationThreadLocals(), Configuration.PUBLICATION_UNBLOCK_TIMEOUT_NS, false);
senderCommandQueue.offer(new NewPublicationCmd(publication));
}
use of io.aeron.driver.media.SendChannelEndpoint 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.media.SendChannelEndpoint in project Aeron by real-logic.
the class DriverConductor method cleanupPublication.
void cleanupPublication(final NetworkPublication publication) {
if (publication.hasSpies()) {
clientProxy.onUnavailableImage(correlationId(publication.rawLog().metaData()), publication.streamId(), publication.channelEndpoint().originalUriString());
for (int i = 0, size = subscriptionLinks.size(); i < size; i++) {
subscriptionLinks.get(i).unlink(publication);
}
}
senderProxy.removeNetworkPublication(publication);
final SendChannelEndpoint channelEndpoint = publication.channelEndpoint();
if (channelEndpoint.shouldBeClosed()) {
channelEndpoint.closeStatusIndicator();
sendChannelEndpointByChannelMap.remove(channelEndpoint.udpChannel().canonicalForm());
senderProxy.closeSendChannelEndpoint(channelEndpoint);
}
}
use of io.aeron.driver.media.SendChannelEndpoint 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);
}
Aggregations