Beispiel #1
0
        /// <summary>
        /// Writes the specified stream to this multi-stream store.
        /// </summary>
        /// <typeparam name="T">The type of messages in the stream.</typeparam>
        /// <param name="source">The source stream to write.</param>
        /// <param name="name">The name of the persisted stream.</param>
        /// <param name="deliveryPolicy">An optional delivery policy.</param>
        public void Write <T>(Emitter <T> source, string name, DeliveryPolicy deliveryPolicy = null)
        {
            // add another input to the merger to hook up the serializer to
            // and check for duplicate names in the process
            var mergeInput = this.merger.Add(name);

            // name the stream if it's not already named
            source.Name = source.Name ?? name;

            // tell the writer to write the serialized stream
            var metadata = this.writer.OpenStream(source.Id, name, typeof(T).AssemblyQualifiedName);

            // register this stream with the store catalog
            this.pipeline.ConfigurationStore.Set(Store.StreamMetadataNamespace, name, metadata);

            // hook up the serializer
            var serializer = new JsonSerializerComponent <T>(this.pipeline);

            serializer.PipeTo(mergeInput, DeliveryPolicy.Unlimited);
            source.PipeTo(serializer, deliveryPolicy);
        }
Beispiel #2
0
        /// <summary>
        /// Writes the specified stream to this multi-stream store.
        /// </summary>
        /// <typeparam name="T">The type of messages in the stream.</typeparam>
        /// <param name="source">The source stream to write.</param>
        /// <param name="name">The name of the persisted stream.</param>
        /// <param name="deliveryPolicy">An optional delivery policy.</param>
        public void Write <T>(Emitter <T> source, string name, DeliveryPolicy <T> deliveryPolicy = null)
        {
            // add another input to the merger to hook up the serializer to
            // and check for duplicate names in the process
            var mergeInput = this.merger.Add(name);

            // name the stream if it's not already named
            source.Name = source.Name ?? name;

            // tell the writer to write the serialized stream
            var metadata = this.writer.OpenStream(source.Id, name, typeof(T).AssemblyQualifiedName);

            // register this stream with the store catalog
            this.pipeline.ConfigurationStore.Set(Store.StreamMetadataNamespace, name, metadata);

            // hook up the serializer
            var serializer = new JsonSerializerComponent <T>(this.pipeline);

            // The merger input receiver will throttle the serializer as long as it is busy writing data.
            // This will cause messages to be queued or dropped at the serializer (per the user-supplied
            // deliveryPolicy) until the merger is able to service the next serialized data message.
            serializer.PipeTo(mergeInput, DeliveryPolicy.Throttle);
            source.PipeTo(serializer, deliveryPolicy);
        }