public long removeCounter(final long registrationId) { final long correlationId = toDriverCommandBuffer.nextCorrelationId(); removeMessage .registrationId(registrationId) .correlationId(correlationId); if (!toDriverCommandBuffer.write(REMOVE_COUNTER, buffer, 0, RemoveMessageFlyweight.length())) { throw new AeronException("could not write remove counter command"); } return correlationId; }
public int receive() { return toDriverCommands.read(this, Configuration.COMMAND_DRAIN_LIMIT); }
public long timeOfLastDriverKeepaliveMs() { return toDriverCommandBuffer.consumerHeartbeatTime(); }
private void checkForBlockedToDriverCommands(final long nowNs) { final long consumerPosition = toDriverCommands.consumerPosition(); if (consumerPosition == lastConsumerCommandPosition) { if (toDriverCommands.producerPosition() > consumerPosition && ((timeOfLastToDriverPositionChangeNs + clientLivenessTimeoutNs) - nowNs < 0)) { if (toDriverCommands.unblock()) { ctx.systemCounters().get(UNBLOCKED_COMMANDS).incrementOrdered(); } } } else { timeOfLastToDriverPositionChangeNs = nowNs; lastConsumerCommandPosition = consumerPosition; } }
public void clientClose() { correlatedMessage.correlationId(Aeron.NULL_VALUE); toDriverCommandBuffer.write(CLIENT_CLOSE, buffer, 0, CorrelatedMessageFlyweight.LENGTH); } }
/** * Generate the next correlation id that is unique for the connected Media Driver. * <p> * This is useful generating correlation identifiers for pairing requests with responses in a clients own * application protocol. * <p> * This method is thread safe and will work across processes that all use the same media driver. * * @return next correlation id that is unique for the Media Driver. */ public long nextCorrelationId() { if (1 == isClosed) { throw new AeronException("client is closed"); } return commandBuffer.nextCorrelationId(); }
timeOfLastTimerCheckNs = nowNs; timeOfLastToDriverPositionChangeNs = nowNs; lastConsumerCommandPosition = toDriverCommands.consumerPosition();
public void logFrameOut(final ByteBuffer buffer, final InetSocketAddress dstAddress) { if (IS_FRAME_OUT_ENABLED) { final MutableDirectBuffer encodedBuffer = ENCODING_BUFFER.get(); final int encodedLength = EventEncoder.encode( encodedBuffer, buffer, buffer.position(), buffer.remaining(), dstAddress); ringBuffer.write(EventCode.FRAME_OUT.id(), encodedBuffer, 0, encodedLength); } }
ringBuffer.nextCorrelationId(); assertThat(ringBuffer.nextCorrelationId(), is((long)(reps * numThreads)));
private void checkForBlockedToDriverCommands(final long nowNs) { final long consumerPosition = toDriverCommands.consumerPosition(); if (consumerPosition == lastConsumerCommandPosition) { if (toDriverCommands.producerPosition() > consumerPosition && ((timeOfLastToDriverPositionChangeNs + clientLivenessTimeoutNs) - nowNs < 0)) { if (toDriverCommands.unblock()) { ctx.systemCounters().get(UNBLOCKED_COMMANDS).incrementOrdered(); } } } else { timeOfLastToDriverPositionChangeNs = nowNs; lastConsumerCommandPosition = consumerPosition; } }
timeOfLastTimerCheckNs = nowNs; timeOfLastToDriverPositionChangeNs = nowNs; lastConsumerCommandPosition = toDriverCommands.consumerPosition();
public long removeSubscription(final long registrationId) { final long correlationId = toDriverCommandBuffer.nextCorrelationId(); removeMessage .registrationId(registrationId) .correlationId(correlationId); if (!toDriverCommandBuffer.write(REMOVE_SUBSCRIPTION, buffer, 0, RemoveMessageFlyweight.length())) { throw new AeronException("could not write remove subscription message"); } return correlationId; }
private void logString(final EventCode code, final String value) { final MutableDirectBuffer encodedBuffer = ENCODING_BUFFER.get(); final int encodingLength = EventEncoder.encode(encodedBuffer, value); ringBuffer.write(code.id(), encodedBuffer, 0, encodingLength); } }
@Test public void shouldTimeoutNetworkPublicationWithSpy() { final long clientId = fromClientCommands.nextCorrelationId(); final DriverProxy spyDriverProxy = new DriverProxy(fromClientCommands, clientId); driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1); final long subId = spyDriverProxy.addSubscription(spyForChannel(CHANNEL_4000), STREAM_ID_1); driverConductor.doWork(); final ArgumentCaptor<NetworkPublication> captor = ArgumentCaptor.forClass(NetworkPublication.class); verify(senderProxy, times(1)).newNetworkPublication(captor.capture()); final NetworkPublication publication = captor.getValue(); doWorkUntil(() -> (CLIENT_LIVENESS_TIMEOUT_NS / 2) - nanoClock.nanoTime() <= 0); spyDriverProxy.sendClientKeepalive(); doWorkUntil(() -> (CLIENT_LIVENESS_TIMEOUT_NS + 1000) - nanoClock.nanoTime() <= 0); spyDriverProxy.sendClientKeepalive(); doWorkUntil(() -> (CLIENT_LIVENESS_TIMEOUT_NS * 2) - nanoClock.nanoTime() <= 0); verify(mockClientProxy).onUnavailableImage( eq(networkPublicationCorrelationId(publication)), eq(subId), eq(STREAM_ID_1), anyString()); }
private void assertReadsOneMessage(final MessageHandler handler) { final int messageCount = conductorBuffer.read(handler); assertThat(messageCount, is(1)); } }
private void checkForBlockedToDriverCommands(final long nowNs) { final long consumerPosition = toDriverCommands.consumerPosition(); if (consumerPosition == lastConsumerCommandPosition) { if (toDriverCommands.producerPosition() > consumerPosition && ((timeOfLastToDriverPositionChangeNs + clientLivenessTimeoutNs) - nowNs < 0)) { if (toDriverCommands.unblock()) { ctx.systemCounters().get(UNBLOCKED_COMMANDS).incrementOrdered(); } } } else { timeOfLastToDriverPositionChangeNs = nowNs; lastConsumerCommandPosition = consumerPosition; } }
private void heartbeatAndCheckTimers(final long nowNs) { final long nowMs = cachedEpochClock.time(); toDriverCommands.consumerHeartbeatTime(nowMs); checkManagedResources(clients, nowNs, nowMs); checkManagedResources(publicationLinks, nowNs, nowMs); checkManagedResources(networkPublications, nowNs, nowMs); checkManagedResources(subscriptionLinks, nowNs, nowMs); checkManagedResources(publicationImages, nowNs, nowMs); checkManagedResources(ipcPublications, nowNs, nowMs); checkManagedResources(counterLinks, nowNs, nowMs); }
timeOfLastTimerCheckNs = nowNs; timeOfLastToDriverPositionChangeNs = nowNs; lastConsumerCommandPosition = toDriverCommands.consumerPosition();
public long removePublication(final long registrationId) { final long correlationId = toDriverCommandBuffer.nextCorrelationId(); removeMessage .registrationId(registrationId) .correlationId(correlationId); if (!toDriverCommandBuffer.write(REMOVE_PUBLICATION, buffer, 0, RemoveMessageFlyweight.length())) { throw new AeronException("could not write remove publication command"); } return correlationId; }
public void logFrameIn( final DirectBuffer buffer, final int offset, final int length, final InetSocketAddress dstAddress) { if (IS_FRAME_IN_ENABLED) { final MutableDirectBuffer encodedBuffer = ENCODING_BUFFER.get(); final int encodedLength = EventEncoder.encode(encodedBuffer, buffer, offset, length, dstAddress); ringBuffer.write(EventCode.FRAME_IN.id(), encodedBuffer, 0, encodedLength); } }