Esempio n. 1
0
        /// <summary>
        /// Creates a deep clone of the given object.
        /// The method will clone into an unused target instance obtained from the specified recycler.
        /// The caller should return the clone to the recycler when done.
        /// </summary>
        /// <typeparam name="T">The type of object to clone</typeparam>
        /// <param name="instance">The instance to clone</param>
        /// <param name="recycler">An object recycling cache.</param>
        /// <returns>The deep-clone</returns>
        public static T DeepClone <T>(this T instance, IRecyclingPool <T> recycler)
        {
            T result = (recycler == null) ? default(T) : recycler.Get();

            Serializer.Clone(instance, ref result, new SerializationContext());
            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeliveryQueue{T}"/> class.
 /// </summary>
 /// <param name="pipeline">Pipeline to which this delivery queue belongs.</param>
 /// <param name="element">PipelineElement to which the receiver owning this delivery queue belongs.</param>
 /// <param name="receiver">Receiver to which this delivery queue belongs.</param>
 /// <param name="policy">The delivery policy dictating message queuing and delivery behavior.</param>
 /// <param name="cloner">The recycling pool to recycle dropped messages to.</param>
 public DeliveryQueue(Pipeline pipeline, PipelineElement element, IReceiver receiver, DeliveryPolicy policy, IRecyclingPool <T> cloner)
 {
     this.pipeline = pipeline;
     this.element  = element;
     this.receiver = receiver;
     this.policy   = policy;
     this.cloner   = cloner;
     this.queue    = new Queue <Message <T> >(policy.InitialQueueSize);
 }
Esempio n. 3
0
 internal Receiver(object owner, Action <Message <T> > onReceived, SynchronizationLock context, Pipeline pipeline, bool enforceIsolation = false)
 {
     this.scheduler        = pipeline.Scheduler;
     this.onReceived       = PipelineElement.TrackStateObjectOnContext <Message <T> >(onReceived, owner, pipeline);
     this.owner            = owner;
     this.syncContext      = context;
     this.enforceIsolation = enforceIsolation;
     this.cloner           = RecyclingPool.Create <T>();
     this.pipeline         = pipeline;
 }
Esempio n. 4
0
        internal Receiver(object owner, Action <Message <T> > onReceived, SynchronizationLock context, Pipeline pipeline, bool enforceIsolation = false)
        {
            this.scheduler        = pipeline.Scheduler;
            this.onReceived       = onReceived;
            this.owner            = owner;
            this.syncContext      = context;
            this.enforceIsolation = enforceIsolation;
            this.cloner           = RecyclingPool.Create <T>();
#if DEBUG
            this.debugTrace = new StackTrace(true);
#endif
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeliveryQueue{T}"/> class.
 /// </summary>
 /// <param name="policy">The delivery policy dictating message queuing and delivery behavior.</param>
 /// <param name="cloner">The recycling pool to recycle dropped messages to.</param>
 public DeliveryQueue(DeliveryPolicy <T> policy, IRecyclingPool <T> cloner)
 {
     this.policy = policy;
     this.cloner = cloner;
     this.queue  = new Queue <Message <T> >(policy.InitialQueueSize);
 }