Пример #1
0
        public EndEdgeFreeOutputPipe(EndEdgeFreeOutputStreamable <TKey, TPayload> stream, IStreamObserver <TKey, TPayload> observer)
            : base(stream, observer)
        {
            this.pool          = MemoryManager.GetMemoryPool <TKey, TPayload>(stream.Properties.IsColumnar);
            this.errorMessages = stream.ErrorMessages;

            var compoundEqualityExpr = EqualityComparerExtensions.GetCompoundEqualityComparerExpression <ActiveEvent, long, TKey, TPayload>(
                e => e.End, EqualityComparerExpression <long> .Default, e => e.Key, stream.Properties.KeyEqualityComparer, e => e.Payload, stream.Properties.PayloadEqualityComparer);
            var equals      = compoundEqualityExpr.GetEqualsExpr().Compile();
            var getHashCode = compoundEqualityExpr.GetGetHashCodeExpr().Compile();

            var generator = compoundEqualityExpr.CreateFastDictionary2Generator <ActiveEvent, int>(1, equals, getHashCode, stream.Properties.QueryContainer);

            this.dictPool = new DataStructurePool <FastDictionary2 <ActiveEvent, int> >(() => generator.Invoke());

            this.pool.Get(out this.output);
            this.output.Allocate();

            this.eventMap     = new SortedDictionary <long, FastDictionary2 <ActiveEvent, int> >();
            this.lastSyncTime = StreamEvent.MinSyncTime;
            this.lastCti      = StreamEvent.MinSyncTime;
        }
        /// <summary>
        /// Generate a batch class definition to be used as a EndEdgeFreeOutputStreamable pipe.
        /// Compile the definition, dynamically load the assembly containing it, and return the Type representing the
        /// union pipe class.
        /// </summary>
        /// <typeparam name="TKey">The key type for both sides.</typeparam>
        /// <typeparam name="TPayload">The payload type.</typeparam>
        /// <returns>
        /// A type that is defined to be a subtype of UnaryPipe&lt;<typeparamref name="TKey"/>,<typeparamref name="TPayload"/>, <typeparamref name="TPayload"/>&gt;.
        /// </returns>
        internal static Tuple <Type, string> Generate <TKey, TPayload>(
            EndEdgeFreeOutputStreamable <TKey, TPayload> stream)
        {
            Contract.Requires(stream != null);
            Contract.Ensures(Contract.Result <Tuple <Type, string> >() == null || typeof(UnaryPipe <TKey, TPayload, TPayload>).GetTypeInfo().IsAssignableFrom(Contract.Result <Tuple <Type, string> >().Item1));

            var template = new EndEdgeFreeOutputTemplate(
                $"GeneratedEndEdgeFreeOutput_{EndEdgeFreeOutputTemplateSequenceNumber++}",
                typeof(TKey), typeof(TPayload));

            template.ActiveEventType = typeof(TPayload).GetTypeInfo().IsValueType ? template.TPayload : "Active_Event";

            #region Key Equals
            var keyComparer = stream.Properties.KeyEqualityComparer.GetEqualsExpr();
            template.keyEquals =
                (left, right) =>
                keyComparer.Inline(left, right);
            #endregion

            #region Key Hash Function
            var keyHashFunction = stream.Properties.KeyEqualityComparer.GetGetHashCodeExpr();
            template.keyHashFunction = (e => keyHashFunction.Inline(e));
            #endregion

            #region Payload Equals
            var payloadComparer = stream.Properties.PayloadEqualityComparer.GetEqualsExpr();
            template.payloadEquals = (left, right) => payloadComparer.Inline(left, right);
            #endregion

            #region Payload Hash Function
            var payloadHashFunction = stream.Properties.PayloadEqualityComparer.GetGetHashCodeExpr();
            template.payloadHashFunction = (aa) => payloadHashFunction.Inline(aa);
            #endregion

            return(template.Generate <TKey, TPayload>(typeof(IStreamable <,>), typeof(FastDictionaryGenerator2)));
        }