internal ClientConductor(Aeron.Context ctx) { _ctx = ctx; _clientLock = ctx.ClientLock(); _epochClock = ctx.EpochClock(); _nanoClock = ctx.NanoClock(); _errorHandler = ctx.ErrorHandler(); _counterValuesBuffer = ctx.CountersValuesBuffer(); _driverProxy = ctx.DriverProxy(); _logBuffersFactory = ctx.LogBuffersFactory(); _imageMapMode = ctx.ImageMapMode(); _keepAliveIntervalNs = ctx.KeepAliveInterval(); _driverTimeoutMs = ctx.DriverTimeoutMs(); _driverTimeoutNs = _driverTimeoutMs * 1000000; _interServiceTimeoutNs = ctx.InterServiceTimeout(); _publicationConnectionTimeoutMs = ctx.PublicationConnectionTimeout(); _driverListener = new DriverListenerAdapter(ctx.ToClientBuffer(), this); _driverAgentInvoker = ctx.DriverAgentInvoker(); long nowNs = _nanoClock.NanoTime(); _timeOfLastKeepaliveNs = nowNs; _timeOfLastCheckResourcesNs = nowNs; _timeOfLastWorkNs = nowNs; }
internal ClusteredServiceAgent(ClusteredServiceContainer.Context ctx) { this.ctx = ctx; headerVector = new DirectBufferVector(headerBuffer, 0, headerBuffer.Capacity); abortHandler = Abort; archiveCtx = ctx.ArchiveContext(); aeron = ctx.Aeron(); aeronAgentInvoker = ctx.Aeron().ConductorAgentInvoker; service = ctx.ClusteredService(); idleStrategy = ctx.IdleStrategy(); serviceId = ctx.ServiceId(); epochClock = ctx.EpochClock(); markFile = ctx.MarkFile(); var channel = ctx.ServiceControlChannel(); _consensusModuleProxy = new ConsensusModuleProxy(aeron.AddPublication(channel, ctx.ConsensusModuleStreamId())); _serviceAdapter = new ServiceAdapter(aeron.AddSubscription(channel, ctx.ServiceStreamId()), this); _sessionMessageHeaderEncoder.WrapAndApplyHeader(headerBuffer, 0, new MessageHeaderEncoder()); aeron.AddCloseHandler(abortHandler); }
/// <summary> /// Connect to an archive on its control interface providing the response stream details. /// </summary> /// <param name="responseChannel"> for the control message responses. </param> /// <param name="responseStreamId"> for the control message responses. </param> /// <param name="correlationId"> for this request. </param> /// <param name="aeronClientInvoker"> for aeron client conductor thread. </param> /// <returns> true if successfully offered otherwise false. </returns> public bool Connect(string responseChannel, int responseStreamId, long correlationId, AgentInvoker aeronClientInvoker) { connectRequestEncoder .WrapAndApplyHeader(buffer, 0, messageHeaderEncoder) .CorrelationId(correlationId) .ResponseStreamId(responseStreamId) .Version(AeronArchive.Configuration.SEMANTIC_VERSION) .ResponseChannel(responseChannel); return(OfferWithTimeout(connectRequestEncoder.EncodedLength(), aeronClientInvoker)); }
internal ClientConductor(Aeron.Context ctx, Aeron aeron) { _ctx = ctx; _aeron = aeron; _clientLock = ctx.ClientLock(); _epochClock = ctx.EpochClock(); _nanoClock = ctx.NanoClock(); _awaitingIdleStrategy = ctx.AwaitingIdleStrategy(); _driverProxy = ctx.DriverProxy(); _logBuffersFactory = ctx.LogBuffersFactory(); _keepAliveIntervalNs = ctx.KeepAliveIntervalNs(); _driverTimeoutMs = ctx.DriverTimeoutMs(); _driverTimeoutNs = _driverTimeoutMs * 1000000; _interServiceTimeoutNs = ctx.InterServiceTimeoutNs(); _defaultAvailableImageHandler = ctx.AvailableImageHandler(); _defaultUnavailableImageHandler = ctx.UnavailableImageHandler(); _driverEventsAdapter = new DriverEventsAdapter(ctx.ToClientBuffer(), ctx.ClientId(), this, _asyncCommandIdSet); _driverAgentInvoker = ctx.DriverAgentInvoker(); _counterValuesBuffer = ctx.CountersValuesBuffer(); _countersReader = new CountersReader(ctx.CountersMetaDataBuffer(), ctx.CountersValuesBuffer(), Encoding.ASCII); if (null != ctx.AvailableCounterHandler()) { _availableCounterHandlers.Add(ctx.AvailableCounterHandler()); } if (null != ctx.UnavailableCounterHandler()) { _unavailableCounterHandlers.Add(ctx.UnavailableCounterHandler()); } if (null != ctx.CloseHandler()) { _closeHandlers.Add(ctx.CloseHandler()); } long nowNs = _nanoClock.NanoTime(); _timeOfLastKeepAliveNs = nowNs; _timeOfLastServiceNs = nowNs; }
private bool OfferWithTimeout(int length, AgentInvoker aeronClientInvoker) { retryIdleStrategy.Reset(); long deadlineNs = nanoClock.NanoTime() + connectTimeoutNs; while (true) { long result; if ((result = publication.Offer(buffer, 0, MessageHeaderEncoder.ENCODED_LENGTH + length)) > 0) { return(true); } if (null != aeronClientInvoker) { aeronClientInvoker.Invoke(); } if (result == Publication.CLOSED) { throw new System.InvalidOperationException("connection to the archive has been closed"); } if (result == Publication.MAX_POSITION_EXCEEDED) { throw new System.InvalidOperationException("publication failed due to max position being reached"); } if (nanoClock.NanoTime() > deadlineNs) { return(false); } retryIdleStrategy.Idle(); } }
/// <summary> /// Connect to an archive on its control interface providing the response stream details. /// </summary> /// <param name="responseChannel"> for the control message responses. </param> /// <param name="responseStreamId"> for the control message responses. </param> /// <param name="correlationId"> for this request. </param> /// <param name="aeronClientInvoker"> for aeron client conductor thread. </param> /// <returns> true if successfully offered otherwise false. </returns> public virtual bool Connect(string responseChannel, int responseStreamId, long correlationId, AgentInvoker aeronClientInvoker) { connectRequestEncoder .WrapAndApplyHeader(buffer, 0, messageHeaderEncoder) .CorrelationId(correlationId) .ResponseStreamId(responseStreamId) .ResponseChannel(responseChannel); return(OfferWithTimeout(connectRequestEncoder.EncodedLength(), aeronClientInvoker)); }
public SnapshotTaker(Publication publication, IIdleStrategy idleStrategy, AgentInvoker aeronClientInvoker) { this.publication = publication; this.idleStrategy = idleStrategy; this.aeronClientInvoker = aeronClientInvoker; }
internal ServiceSnapshotTaker(Publication publication, IIdleStrategy idleStrategy, AgentInvoker aeronClientInvoker) : base(publication, idleStrategy, aeronClientInvoker) { }