public PartitionedStitchPipe(StitchStreamable <TKey, TPayload> stream, IStreamObserver <TKey, TPayload> observer) : base(stream, observer) { this.getPartitionKey = GetPartitionExtractor <TPartitionKey, TKey>(); this.errorMessages = stream.ErrorMessages; this.outputCount = 0; this.pool = MemoryManager.GetMemoryPool <TKey, TPayload>(stream.Properties.IsColumnar); this.pool.Get(out this.batch); this.batch.Allocate(); var khpcomparer = EqualityComparerExtensions.GetCompoundEqualityComparerExpression <KHP, TKey, TPayload>( e => e.Key, stream.Properties.KeyEqualityComparer, e => e.Payload, stream.Properties.PayloadEqualityComparer); var equals = khpcomparer.GetEqualsExpr().Compile(); var getHashCode = khpcomparer.GetGetHashCodeExpr().Compile(); var generator1 = khpcomparer.CreateFastDictionary2Generator <KHP, List <ActiveEvent> >(1, equals, getHashCode, stream.Properties.QueryContainer); this.dictPool = new DataStructurePool <FastDictionary2 <KHP, List <ActiveEvent> > >(() => generator1.Invoke()); var generator2 = khpcomparer.CreateFastDictionary2Generator <KHP, int>(1, equals, getHashCode, stream.Properties.QueryContainer); this.CurrentTimeOpenEventBufferGenerator = () => generator2.Invoke(); var generator3 = khpcomparer.CreateFastDictionary2Generator <KHP, List <ActiveEventExt> >(1, equals, getHashCode, stream.Properties.QueryContainer); this.OpenEventsGenerator = () => generator3.Invoke(); }
/// <summary> /// Generate a batch class definition to be used as a Stitch pipe. /// Compile the definition, dynamically load the assembly containing it, and return the Type representing the /// Stitch 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<<typeparamref name="TKey"/>,<typeparamref name="TPayload"/>, <typeparamref name="TPayload"/>>. /// </returns> internal static Tuple <Type, string> Generate <TKey, TPayload>( StitchStreamable <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 StitchTemplate( string.Format("GeneratedStitch_{0}", StitchSequenceNumber++), typeof(TKey), typeof(TPayload)); #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 { template.ActiveEventType = typeof(TPayload).GetTypeInfo().IsValueType ? template.TPayload : "Active_Event"; 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 = (payload) => payloadHashFunction.Inline(payload); } #endregion return(template.Generate <TKey, TPayload>(typeof(IStreamable <,>), typeof(FastDictionaryGenerator2))); }