/// <summary> /// This is the main constructor. /// </summary> /// <param name="resourceTracker">The resource tracker.</param> /// <param name="client">The client to hold.</param> /// <param name="mappingChannelId">The mapping channel.param> /// <param name="maxAllowedPollWait">The maximum permitted poll length.</param> public ClientPriorityHolder(IResourceTracker resourceTracker , ClientHolder client , string mappingChannelId , IListenerClientPollAlgorithm priorityAlgorithm ) { if (client == null) { throw new ArgumentNullException("client"); } if (priorityAlgorithm == null) { throw new ArgumentNullException("algorithm"); } mPriorityAlgorithm = priorityAlgorithm; Client = client; mMappingChannel = mappingChannelId; //Create the metrics container to hold the calculations for poll priority and reservation amount. mMetrics = new ClientPriorityHolderMetrics(mPriorityAlgorithm , resourceTracker?.RegisterRequestRateLimiter(client.Name, client.ResourceProfiles) , client.Priority , client.Weighting ); mPriorityAlgorithm.InitialiseMetrics(mMetrics); }
/// <summary> /// Restore the previously claimed message body's payload via a <see cref="TrackingStream"/> stream if it has been /// claimed to disk while being processed, that is if current payload is either one of the <see /// cref="Schemas.Xml.Claim.Check"/> or <see cref="Schemas.Xml.Claim.CheckOut"/> token messages. Leave the message /// body's payload stream unaltered otherwise. /// </summary> /// <param name="message"> /// The <see cref="IBaseMessage"/> token message whose message body's payload stream is going to be restored to /// the payload that has been previously claimed. /// </param> /// <param name="resourceTracker"> /// Pipeline's <see cref="IResourceTracker"/> to which to register the restored message body stream for later /// cleanup. /// </param> /// <remarks> /// The <see cref="TrackingStream"/> that will replace the <paramref name="message"/> stream with its previously /// captured original payload, will have its <see cref="TrackingStream.CaptureDescriptor"/> point to the previously /// captured-to-disk body payload, thereby providing an opportunity for the <see cref="MessagingStep"/> to share /// that already captured payload without saving it to disk again. /// </remarks> public virtual void Redeem(IBaseMessage message, IResourceTracker resourceTracker) { var messageType = message.GetOrProbeMessageType(resourceTracker); if (messageType == typeof(Claim.Check).GetMetadata().MessageType || messageType == typeof(Claim.CheckOut).GetMetadata().MessageType) { var messageBodyCaptureDescriptor = message.BodyPart.AsMessageBodyCaptureDescriptor(); if (_logger.IsDebugEnabled) { _logger.DebugFormat("Performing redeem of claim check token '{0}'.", messageBodyCaptureDescriptor.Data); } // replace claim token with actual content message.BodyPart.SetDataStream( new TrackingStream(OpenClaim(messageBodyCaptureDescriptor.Data), messageBodyCaptureDescriptor), resourceTracker); } else if (messageType == typeof(Claim.CheckIn).GetMetadata().MessageType) { throw new InvalidOperationException( string.Format( "Invalid token message, {0} token is not expected to be redeemed.", typeof(Claim.CheckIn).GetMetadata().RootElementName)); } else { if (_logger.IsDebugEnabled) { _logger.Debug("Skipping redeem of claim check token; message body stream's payload is not a token."); } } }
public static string GetOrProbeMessageType(this IBaseMessage message, IResourceTracker resourceTracker) { var messageType = message.GetProperty(BtsProperties.MessageType); return(messageType.IsNullOrEmpty() ? message.ProbeMessageType(resourceTracker) : messageType); }
/// <summary> /// This method gets the list of clients for the relevant listeners. /// </summary> protected override void StartInternal() { mResourceTracker = SharedServices.GetService <IResourceTracker>(); if (mResourceTracker == null) { throw new ArgumentNullException("ResourceTracker cannot be retrieved."); } }
public CSVDumper(IResourceTracker irt, System.Collections.IComparer comparer) { m_comparer = comparer; m_arer = new System.Collections.ArrayList(); foreach (ResourceEventRecord rer in irt) { m_arer.Add(rer); } }
/// <summary> /// This method gets the list of clients for the relevant listeners. /// </summary> protected override void StartInternal() { //Get the resource tracker that will be used to reduce message in mResourceTracker = SharedServices.GetService <IResourceTracker>(); if (mResourceTracker == null) { throw new ArgumentNullException("ResourceTracker cannot be retrieved."); } }
public static string ProbeMessageType(this IBaseMessage message, IResourceTracker resourceTracker) { var markableForwardOnlyEventingReadStream = message.BodyPart.WrapOriginalDataStream( originalStream => originalStream.AsMarkable(), resourceTracker); var messageType = message.BodyPart.Data.EnsureMarkable().Probe().MessageType; markableForwardOnlyEventingReadStream.StopMarking(); return(messageType); }
/// <inheritdoc /> public InMemoryDeterministicSeedManager( IResourceTracker resourceTracker, ISigningHelper signingHelper, IAddressGenerator addressGenerator, IIotaRepository repository) : base(resourceTracker, signingHelper, addressGenerator, repository) { this.CurrentIndex = -1; this.References = new Dictionary <string, Seed>(); }
public IotaFhirRepository( IIotaRepository repository, IFhirTryteSerializer serializer, IResourceTracker resourceTracker, ISeedManager seedManager) { this.Serializer = serializer; this.ResourceTracker = resourceTracker; this.SeedManager = seedManager; this.ChannelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, repository); this.SubscriptionFactory = new MamChannelSubscriptionFactory(repository, CurlMamParser.Default, CurlMask.Default); }
protected DeterministicSeedManager( IResourceTracker resourceTracker, ISigningHelper signingHelper, IAddressGenerator addressGenerator, IIotaRepository repository) { this.ResourceTracker = resourceTracker; this.SigningHelper = signingHelper; this.AddressGenerator = addressGenerator; this.SubscriptionFactory = new MamChannelSubscriptionFactory(repository, CurlMamParser.Default, CurlMask.Default); this.ChannelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, repository); }
/// <inheritdoc /> public SeedManager( IResourceTracker resourceTracker, ISigningHelper signingHelper, IAddressGenerator addressGenerator, IIotaRepository repository, IEncryption encryption, string databaseFilename = "iotafhir.sqlite") : base(resourceTracker, signingHelper, addressGenerator, repository) { this.Encryption = encryption; this.ConnectionString = databaseFilename; this.Init(databaseFilename); }
public static string ProbeMessageType(this IBaseMessage message, IResourceTracker resourceTracker) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var markableForwardOnlyEventingReadStream = message.BodyPart.WrapOriginalDataStream( originalStream => originalStream.AsMarkable(), resourceTracker); var messageType = message.BodyPart.Data.Probe().MessageType; markableForwardOnlyEventingReadStream.StopMarking(); return(messageType); }
/// <summary> /// Replace the message body's payload stream with either a <see cref="Schemas.Xml.Claim.Check"/> or a <see /// cref="Schemas.Xml.Claim.CheckIn"/> token message if its content has been assessed to be saved to disk while /// being tracked (see <see cref="SetupMessageBodyCapture"/>). Leave the message body's payload stream unaltered /// otherwise. /// </summary> /// <param name="message"> /// The <see cref="IBaseMessage"/> whose message body's payload stream is going to be claimed and replace by a /// token message. /// </param> /// <param name="resourceTracker"> /// Pipeline's <see cref="IResourceTracker"/> to which to report the newly created message token stream. /// </param> /// <remarks> /// The <see cref="IBaseMessage"/>'s <see cref="IBaseMessageContext"/> is also updated with the message type of /// the token message that is put in place of the actual message body's payload. /// </remarks> public virtual void Claim(IBaseMessage message, IResourceTracker resourceTracker) { var trackingStream = message.BodyPart.GetOriginalDataStream() as TrackingStream; if (trackingStream == null) { if (_logger.IsDebugEnabled) { _logger.Debug("Skipping claim of message body stream's payload; BodyPart's OriginalDataStream is not a TrackingStream."); } } else if (trackingStream.CaptureDescriptor.CaptureMode != MessageBodyCaptureMode.Claimed) { if (_logger.IsDebugEnabled) { _logger.Debug("Skipping claim of message body stream's payload; CaptureDescriptor.CaptureMode is not MessageBodyCaptureMode.Claimed."); } } else { if (_logger.IsDebugEnabled) { _logger.DebugFormat("Performing claim of message body stream's payload '{0}'.", trackingStream.CaptureDescriptor.Data); } var claimedMessageType = message.GetProperty(BtsProperties.MessageType); DocumentSpec documentSpec; Stream tokenMessageStream; if (RequiresCheckInAndOut) { documentSpec = typeof(Claim.CheckIn).GetMetadata().DocumentSpec; tokenMessageStream = MessageFactory.CreateClaimCheckIn(claimedMessageType, trackingStream.CaptureDescriptor.Data).AsStream(); } else { documentSpec = typeof(Claim.Check).GetMetadata().DocumentSpec; tokenMessageStream = MessageFactory.CreateClaimCheck(claimedMessageType, trackingStream.CaptureDescriptor.Data).AsStream(); } // fix the message type before capturing the body stream so that it get captured while tracking MessagingStep message.Promote(BtsProperties.MessageType, documentSpec.DocType); message.Promote(BtsProperties.SchemaStrongName, documentSpec.DocSpecStrongName); // drain and capture body stream trackingStream.Capture(); // replace message body's payload with the token message stream message.BodyPart.SetDataStream(tokenMessageStream, resourceTracker); } }
/// <inheritdoc /> public SqlLiteDeterministicSeedManager( IResourceTracker resourceTracker, ISigningHelper signingHelper, IAddressGenerator addressGenerator, IIotaRepository repository, IEncryption encryption, IDbConnectionSupplier connectionSupplier = null, string databaseFilename = "iotafhir.sqlite") : base(resourceTracker, signingHelper, addressGenerator, repository) { this.Encryption = encryption; this.ConnectionSupplier = connectionSupplier ?? new DefaultDbConnectionSupplier(); this.ConnectionString = $"Data Source={databaseFilename};Version=3;"; DatabaseInitializer.InitFhirDatabase(this.ConnectionSupplier, databaseFilename); }
/// <summary> /// This constructor build up the poll collection and sets the correct poll priority. /// </summary> /// <param name="listeners"></param> /// <param name="resourceTracker"></param> /// <param name="algorithm"></param> /// <param name="iterationId"></param> public ClientPriorityCollection( List <IListener> listeners , IResourceTracker resourceTracker , IListenerClientPollAlgorithm algorithm , long iterationId ) { mPriorityAlgorithm = algorithm; mIteration = iterationId; Created = DateTime.UtcNow; //Get the list of active clients. mListenerClients = new Dictionary <Guid, ClientPriorityHolder>(); foreach (var listener in listeners) { if (listener.ListenerClients != null) { foreach (var client in listener.ListenerClients) { var holder = new ClientPriorityHolder(resourceTracker, client, listener.ListenerMappingChannelId, algorithm); mListenerClients.Add(holder.Id, holder); } } } //Get the supported levels. mListenerPollLevels = mListenerClients .Select((c) => c.Value.Priority) .Distinct() .OrderByDescending((i) => i) .ToArray(); mReprioritise = 0; //Finally create a poll chain for each individual priority level Reprioritise(); }
public IotaFhirRepository(IIotaRepository repository, IFhirTryteSerializer serializer, IResourceTracker resourceTracker) { this.Serializer = serializer; this.ResourceTracker = resourceTracker; this.ChannelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, repository); this.SubscriptionFactory = new MamChannelSubscriptionFactory(repository, CurlMamParser.Default, CurlMask.Default); this.ResultTimes = new List <TimeTrackingEntry>(); this.ReadTimes = new List <ReadTrackingEntry>(); }
/// <summary> /// Wraps this message part's original data stream in another stream returned by the <paramref name="wrapper"/> /// delegate. /// </summary> /// <param name="messagePart"> /// The part whose original data stream is wrapped. /// </param> /// <param name="wrapper"> /// A delegate, or stream factory, that returns the stream wrapping the original one. /// </param> /// <param name="tracker"> /// Pipeline's resource tracker to which to report the newly created wrapping stream. /// </param> /// <returns> /// The new wrapping <see cref="Stream"/> if it is not the same instance as the original one. The original <see /// cref="Stream"/> otherwise. /// </returns> public static T WrapOriginalDataStream <T>(this IBaseMessagePart messagePart, Func <Stream, T> wrapper, IResourceTracker tracker) where T : Stream { // TODO ?consider providing an overload when there is no IResourceTracker as this is necessary only for unmanaged objects/resources? if (messagePart == null) { throw new ArgumentNullException("messagePart"); } if (wrapper == null) { throw new ArgumentNullException("wrapper"); } if (tracker == null) { throw new ArgumentNullException("tracker"); } var originalDataStream = messagePart.GetOriginalDataStream(); if (originalDataStream == null) { return(null); } var wrappingStream = wrapper(originalDataStream); if (ReferenceEquals(originalDataStream, wrappingStream)) { return((T)originalDataStream); } if (_logger.IsDebugEnabled) { _logger.DebugFormat("Wrapping message part's original data stream in a '{0}' stream.", wrappingStream.GetType().FullName); } messagePart.SetDataStream(wrappingStream, tracker); return(wrappingStream); }
/// <summary> /// Replaces this <paramref name="messagePart"/>'s original data stream by another <paramref name="stream"/>. /// </summary> /// <param name="messagePart"> /// The part whose original data stream is replaced. /// </param> /// <param name="stream"> /// The replacement stream. /// </param> /// <param name="tracker"> /// Pipeline's resource tracker to which to report the newly created wrapping stream. /// </param> public static void SetDataStream(this IBaseMessagePart messagePart, Stream stream, IResourceTracker tracker) { // TODO ?consider providing an overload when there is no IResourceTracker as this is necessary only for unmanaged objects/resources? not really necessary as one could use Data setter, but it'd be consistent/balanced API if (messagePart == null) { throw new ArgumentNullException("messagePart"); } if (stream == null) { throw new ArgumentNullException("stream"); } if (tracker == null) { throw new ArgumentNullException("tracker"); } messagePart.Data = stream; tracker.AddResource(stream); }
public RandomSeedManager(IResourceTracker resourceTracker) { this.ResourceTracker = resourceTracker; this.References = new Dictionary <string, Seed>(); }
/// <summary> /// Wraps this message part's original data stream in another stream returned by the <paramref name="wrapper"/> /// delegate. /// </summary> /// <param name="messagePart"> /// The part whose original data stream is wrapped. /// </param> /// <param name="wrapper"> /// A delegate, or stream factory, that returns the stream wrapping the original one. /// </param> /// <param name="tracker"> /// Pipeline's resource tracker to which to report the newly created wrapping stream. /// </param> /// <returns> /// The new wrapping <see cref="Stream"/> if it is not the same instance as the original one. The original <see /// cref="Stream"/> otherwise. /// </returns> public static T WrapOriginalDataStream <T>(this IBaseMessagePart messagePart, Func <Stream, T> wrapper, IResourceTracker tracker) where T : Stream { if (messagePart == null) { throw new ArgumentNullException(nameof(messagePart)); } if (wrapper == null) { throw new ArgumentNullException(nameof(wrapper)); } if (tracker == null) { throw new ArgumentNullException(nameof(tracker)); } var originalDataStream = messagePart.GetOriginalDataStream(); if (originalDataStream == null) { return(null); } var wrappingStream = wrapper(originalDataStream); if (ReferenceEquals(originalDataStream, wrappingStream)) { return((T)originalDataStream); } if (_logger.IsDebugEnabled) { _logger.DebugFormat("Wrapping message part's original data stream in a '{0}' stream.", wrappingStream.GetType().FullName); } messagePart.SetDataStream(wrappingStream, tracker); return(wrappingStream); }
/// <summary> /// Replaces this <paramref name="messagePart"/>'s original data stream by another <paramref name="stream"/>. /// </summary> /// <param name="messagePart"> /// The part whose original data stream is replaced. /// </param> /// <param name="stream"> /// The replacement stream. /// </param> /// <param name="tracker"> /// Pipeline's resource tracker to which to report the newly created wrapping stream. /// </param> public static void SetDataStream(this IBaseMessagePart messagePart, Stream stream, IResourceTracker tracker) { if (messagePart == null) { throw new ArgumentNullException(nameof(messagePart)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (tracker == null) { throw new ArgumentNullException(nameof(tracker)); } messagePart.Data = stream; tracker.AddResource(stream); }