/// <summary> /// Writes the messages from the specified stream to the matching stream in this store. /// </summary> /// <typeparam name="TMessage">The type of messages in the stream.</typeparam> /// <param name="source">The source stream to write.</param> /// <param name="name">The name of the stream.</param> /// <param name="largeMessages">Indicates whether the stream contains large messages (typically >4k). If true, the messages will be written to the large message file.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Stream metadata.</returns> private PsiStreamMetadata WriteToStorage <TMessage>(Emitter <TMessage> source, string name, bool largeMessages = false, DeliveryPolicy <TMessage> deliveryPolicy = null) { // make sure we can serialize this type var handler = this.serializers.GetHandler <TMessage>(); // 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 var connector = new MessageConnector <TMessage>(source.Pipeline, this, null); // defaults to lossless delivery policy unless otherwise specified source.PipeTo(connector, deliveryPolicy ?? DeliveryPolicy.Unlimited); source.Name = connector.Out.Name = name; source.Closed += closeTime => this.writer.CloseStream(source.Id, closeTime); // tell the writer to write the serialized stream var meta = this.writer.OpenStream(source.Id, name, largeMessages, handler.Name); // register this stream with the store catalog this.pipeline.ConfigurationStore.Set(Exporter.StreamMetadataNamespace, name, meta); // hook up the serializer var serializer = new SerializerComponent <TMessage>(this, this.serializers); // The serializer and merger will act synchronously and throttle the connector for as long as // the merger is busy writing data. This will cause messages to be queued or dropped at the input // to the connector (per the user-supplied deliveryPolicy) until the merger is able to accept // the next serialized data message. serializer.PipeTo(mergeInput, allowWhileRunning: true, DeliveryPolicy.SynchronousOrThrottle); connector.PipeTo(serializer, allowWhileRunning: true, DeliveryPolicy.SynchronousOrThrottle); return(meta); }
/// <summary> /// Writes the messages from the specified stream to the matching storage stream in this 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 storage stream.</param> /// <param name="largeMessages">Indicates whether the stream contains large messages (typically >4k). If true, the messages will be written to the large message file.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> public void Write <T>(Emitter <T> source, string name, bool largeMessages = false, DeliveryPolicy deliveryPolicy = null) { // make sure we can serialize this type var handler = this.serializers.GetHandler <T>(); // 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 var connector = new MessageConnector <T>(source.Pipeline, this, null); source.PipeTo(connector); source.Name = source.Name ?? name; connector.Out.Name = name; // tell the writer to write the serialized stream var meta = this.writer.OpenStream(source.Id, name, largeMessages, handler.Name); // register this stream with the store catalog this.pipeline.ConfigurationStore.Set(Store.StreamMetadataNamespace, name, meta); // hook up the serializer var serializer = new SerializerComponent <T>(this, this.serializers); serializer.PipeTo(mergeInput, true, DeliveryPolicy.Unlimited); // allows connections in running pipelines connector.PipeTo(serializer, true, deliveryPolicy); }
/// <summary> /// Serializes the source stream, preserving the envelope. /// </summary> /// <typeparam name="T">The type of data to serialize</typeparam> /// <param name="source">The source stream generating the data to serialize</param> /// <param name="serializers">An optional collection of known types to use</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>A stream of Message{Message{BufferReader}}, where the inner Message object preserves the original envelope of the message received by this operator.</returns> public static IProducer <Message <BufferReader> > Serialize <T>(this IProducer <T> source, KnownSerializers serializers = null, DeliveryPolicy deliveryPolicy = null) { var serializer = new SerializerComponent <T>(source.Out.Pipeline, serializers ?? KnownSerializers.Default); source.PipeTo(serializer.In, deliveryPolicy); return(serializer.Out); }