Ejemplo n.º 1
0
 /// <summary>
 ///     Ctor - use for the first and unused latch to indicate completion.
 /// </summary>
 /// <param name="factory">the latch factory</param>
 public InsertIntoLatchSpin(InsertIntoLatchFactory factory)
 {
     _factory = factory;
     _isCompleted = true;
     _earlier = null;
     _msecTimeout = 0;
 }
Ejemplo n.º 2
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="factory">the latch factory</param>
 /// <param name="earlier">the latch before this latch that this latch should be waiting for</param>
 /// <param name="msecTimeout">the timeout after which delivery occurs</param>
 /// <param name="payload">the payload is an event to deliver</param>
 public InsertIntoLatchSpin(
     InsertIntoLatchFactory factory,
     InsertIntoLatchSpin earlier,
     long msecTimeout,
     EventBean payload)
 {
     _factory = factory;
     _earlier = earlier;
     _msecTimeout = msecTimeout;
     _payload = payload;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Returns a new latch.
        ///     <para />
        ///     Need not be synchronized as there is one per statement and execution is during statement lock.
        /// </summary>
        /// <param name="payload">is the object returned by the await.</param>
        /// <returns>latch</returns>
        public object NewLatch(EventBean payload)
        {
            if (stateless) {
                return payload;
            }

            if (useSpin) {
                var nextLatch = new InsertIntoLatchSpin(this, currentLatchSpin, msecWait, payload);
                currentLatchSpin = nextLatch;
                return nextLatch;
            }
            else {
                var nextLatch = new InsertIntoLatchWait(currentLatchWait, msecWait, payload);
                currentLatchWait.Later = nextLatch;
                currentLatchWait = nextLatch;
                return nextLatch;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Ctor.
        /// </summary>
        /// <param name="name">the factory name</param>
        /// <param name="msecWait">the number of milliseconds latches will await maximally</param>
        /// <param name="locking">the blocking strategy to employ</param>
        /// <param name="timeSourceService">time source provider</param>
        /// <param name="stateless">indicator whether stateless</param>
        public InsertIntoLatchFactory(
            string name,
            bool stateless,
            int msecWait,
            Locking locking,
            TimeSourceService timeSourceService)
        {
            Name = name;
            this.msecWait = msecWait;
            TimeSourceService = timeSourceService;
            this.stateless = stateless;

            useSpin = locking == Locking.SPIN;

            // construct a completed latch as an initial root latch
            if (useSpin) {
                currentLatchSpin = new InsertIntoLatchSpin(this);
            }
            else {
                currentLatchWait = new InsertIntoLatchWait(this);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     Called to indicate that the latch completed and a later latch can start.
 /// </summary>
 public void Done()
 {
     _isCompleted = true;
     _earlier = null;
 }