Beispiel #1
0
        /// <summary>Increment the reference count.</summary>
        /// <exception cref="ClosedChannelException">If the status is closed.</exception>
        public virtual void Reference()
        {
            int curBits = status.IncrementAndGet();

            if ((curBits & StatusClosedMask) != 0)
            {
                status.DecrementAndGet();
                throw new ClosedChannelException();
            }
        }
Beispiel #2
0
        public bool TryAcquire()
        {
            int count = UsedCount.IncrementAndGet();

            if (count > Count)
            {
                UsedCount.DecrementAndGet();
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Expert: decreases the refCount of this TaxonomyReader instance. If the
        /// refCount drops to 0 this taxonomy reader is closed.
        /// </summary>
        public void DecRef()
        {
            EnsureOpen();
            int rc = refCount.DecrementAndGet();

            if (rc == 0)
            {
                bool success = false;
                try
                {
                    DoClose();
                    closed  = true;
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        // Put reference back on failure
                        refCount.IncrementAndGet();
                    }
                }
            }
            else if (rc < 0)
            {
                throw new ThreadStateException("too many decRef calls: refCount is " + rc + " after decrement");
            }
        }
Beispiel #4
0
        public void test02()
        {
            var a = new AtomicInteger(1);

            Assert.AreEqual(0, a.DecrementAndGet());
            Assert.AreEqual(0, a.Value);
        }
Beispiel #5
0
 public override void Run()
 {
     try
     {
         long ramSize = 0;
         while (PendingDocs.DecrementAndGet() > -1)
         {
             Document doc = Docs.NextDoc();
             Writer.AddDocument(doc);
             long newRamSize = Writer.RamSizeInBytes();
             if (newRamSize != ramSize)
             {
                 ramSize = newRamSize;
             }
             if (DoRandomCommit)
             {
                 if (Rarely())
                 {
                     Writer.Commit();
                 }
             }
         }
         Writer.Commit();
     }
     catch (Exception ex)
     {
         Console.WriteLine("FAILED exc:");
         Console.WriteLine(ex.StackTrace);
         throw new Exception(ex.Message, ex);
     }
 }
            public override void Run()
            {
                Random random = Random();

                while (numCats.DecrementAndGet() > 0)
                {
                    try
                    {
                        int        value = random.Next(range);
                        FacetLabel cp    = new FacetLabel(Convert.ToString(value / 1000), Convert.ToString(value / 10000), Convert.ToString(value / 100000), Convert.ToString(value));
                        int        ord   = tw.AddCategory(cp);
                        Assert.True(tw.GetParent(ord) != -1, "invalid parent for ordinal " + ord + ", category " + cp);
                        string l1 = FacetsConfig.PathToString(cp.Components, 1);
                        string l2 = FacetsConfig.PathToString(cp.Components, 2);
                        string l3 = FacetsConfig.PathToString(cp.Components, 3);
                        string l4 = FacetsConfig.PathToString(cp.Components, 4);
                        values[l1] = l1;
                        values[l2] = l2;
                        values[l3] = l3;
                        values[l4] = l4;
                    }
                    catch (IOException e)
                    {
                        throw new Exception(e.Message, e);
                    }
                }
            }
Beispiel #7
0
            internal virtual Future <int> SubmitRecycle(byte[] array)
            {
                count.DecrementAndGet();
                Future <int> f = pool.Submit(new _Callable_487(this, array));

                return(f);
            }
Beispiel #8
0
 /// <summary>Notify the monitor a worker is finished.</summary>
 /// <remarks>Notify the monitor a worker is finished.</remarks>
 public virtual void EndWorker()
 {
     if (workers.DecrementAndGet() == 0)
     {
         process.Release();
     }
 }
Beispiel #9
0
            public override void Run()
            {
                Random random = Random();

                while (numDocs.DecrementAndGet() > 0)
                {
                    try
                    {
                        Document doc     = new Document();
                        int      numCats = random.Next(3) + 1; // 1-3
                        while (numCats-- > 0)
                        {
                            FacetField ff = NewCategory();
                            doc.Add(ff);

                            FacetLabel label = new FacetLabel(ff.dim, ff.path);
                            // add all prefixes to values
                            int level = label.Length;
                            while (level > 0)
                            {
                                string s = FacetsConfig.PathToString(label.Components, level);
                                values[s] = s;
                                --level;
                            }
                        }
                        iw.AddDocument(config.Build(tw, doc));
                    }
                    catch (IOException e)
                    {
                        throw new Exception(e.Message, e);
                    }
                }
            }
 internal void MarkCommandDone(ExecutionResult executionResult, IHystrixCommandKey commandKey, IHystrixThreadPoolKey threadPoolKey, bool executionStarted)
 {
     HystrixThreadEventStream.GetInstance().ExecutionDone(executionResult, commandKey, threadPoolKey);
     if (executionStarted)
     {
         _concurrentExecutionCount.DecrementAndGet();
     }
 }
Beispiel #11
0
 /**
  * 关闭数据库
  */
 public void closeDatabase()
 {
     if (mOpenCounter.DecrementAndGet() == 0)
     {
         // Closing database
         mDatabase.Close();
     }
 }
Beispiel #12
0
        protected void onAcknowledge(Acknowledgement acknowledgement)
        {
            try
            {
                waitForAckLatch.Get().CountDown();
                waitForSeqAckLatch.Get().CountDown();

                CongestionControl cc = session.getCongestionControl();
                long rtt             = acknowledgement.getRoundTripTime();
                if (rtt > 0)
                {
                    long rttVar = acknowledgement.getRoundTripTimeVar();
                    cc.setRTT(rtt, rttVar);
                    statistics.setRTT(rtt, rttVar);
                }
                long rate = acknowledgement.getPacketReceiveRate();
                if (rate > 0)
                {
                    long linkCapacity = acknowledgement.getEstimatedLinkCapacity();
                    cc.updatePacketArrivalRate(rate, linkCapacity);
                    statistics.setPacketArrivalRate(cc.getPacketArrivalRate(), cc.getEstimatedLinkCapacity());
                }

                long ackNumber = acknowledgement.getAckNumber();
                cc.onACK(ackNumber);
                statistics.setCongestionWindowSize((long)cc.getCongestionWindowSize());
                //need to remove all sequence numbers up the ack number from the sendBuffer
                bool removed = false;
                for (long s = lastAckSequenceNumber; s < ackNumber; s++)
                {
                    lock (sendLock)
                    {
                        removed = sendBuffer.Remove(s);
                    }
                    if (removed)
                    {
                        unacknowledged.DecrementAndGet();
                    }
                }
                lastAckSequenceNumber = (int)Math.Max(lastAckSequenceNumber, ackNumber);
                //send ACK2 packet to the receiver
                sendAck2(ackNumber);
                statistics.incNumberOfACKReceived();
                if (storeStatistics)
                {
                    statistics.storeParameters();
                }
            }
            catch (Exception ex)
            {
                Log.Write(this.ToString(), ex);
            }
        }
Beispiel #13
0
            public override void Run()
            {
                Random random = Random();

                while (numCats.DecrementAndGet() > 0)
                {
                    string cat = Convert.ToString(random.Next(range));
                    try
                    {
                        tw.AddCategory(new FacetLabel("a", cat));
                    }
                    catch (IOException e)
                    {
                        throw new Exception(e.Message, e);
                    }
                }
            }
Beispiel #14
0
 public virtual void AddComplete(int rc, LedgerHandle handle, long entryId, object
                                 ctx)
 {
     lock (this)
     {
         outstandingRequests.DecrementAndGet();
         if (!transmitResult.CompareAndSet(BKException.Code.Ok, rc))
         {
             Log.Warn("Tried to set transmit result to (" + rc + ") \"" + BKException.GetMessage
                          (rc) + "\"" + " but is already (" + transmitResult.Get() + ") \"" + BKException.
                      GetMessage(transmitResult.Get()) + "\"");
         }
         CountDownLatch l = syncLatch;
         if (l != null)
         {
             l.CountDown();
         }
     }
 }
Beispiel #15
0
 internal void DecRef()
 {
     if (@ref.DecrementAndGet() == 0)
     {
         Exception th = null;
         try
         {
             IOUtils.Close(termVectorsLocal, fieldsReaderLocal, normsLocal, Fields, TermVectorsReaderOrig, FieldsReaderOrig, CfsReader, NormsProducer);
         }
         catch (Exception throwable)
         {
             th = throwable;
         }
         finally
         {
             NotifyCoreClosedListeners(th);
         }
     }
 }
Beispiel #16
0
 public override void Run()
 {
     while (true)
     {
         IList <T> inputs = null;
         try
         {
             // Wait for notification to start the merge...
             lock (pendingToBeMerged)
             {
                 while (pendingToBeMerged.Count <= 0)
                 {
                     Sharpen.Runtime.Wait(pendingToBeMerged);
                 }
                 // Pickup the inputs to merge.
                 inputs = pendingToBeMerged.RemoveFirst();
             }
             // Merge
             Merge(inputs);
         }
         catch (Exception)
         {
             numPending.Set(0);
             return;
         }
         catch (Exception t)
         {
             numPending.Set(0);
             reporter.ReportException(t);
             return;
         }
         finally
         {
             lock (this)
             {
                 numPending.DecrementAndGet();
                 Sharpen.Runtime.NotifyAll(this);
             }
         }
     }
 }
Beispiel #17
0
        /// <summary>
        /// Expert: decreases the refCount of this IndexReader
        /// instance.  If the refCount drops to 0, then this
        /// reader is closed.  If an exception is hit, the refCount
        /// is unchanged.
        /// </summary>
        /// <exception cref="IOException"> in case an IOException occurs in  doClose()
        /// </exception>
        /// <seealso cref= #incRef </seealso>
        public void DecRef()
        {
            // only check refcount here (don't call ensureOpen()), so we can
            // still close the reader if it was made invalid by a child:
            if (refCount.Get() <= 0)
            {
                throw new AlreadyClosedException("this IndexReader is closed");
            }

            int rc = refCount.DecrementAndGet();

            if (rc == 0)
            {
                Closed = true;
                Exception throwable = null;
                try
                {
                    DoClose();
                }
                catch (Exception th)
                {
                    throwable = th;
                }
                finally
                {
                    try
                    {
                        ReportCloseToParentReaders();
                    }
                    finally
                    {
                        NotifyReaderClosedListeners(throwable);
                    }
                }
            }
            else if (rc < 0)
            {
                throw new InvalidOperationException("too many decRef calls: refCount is " + rc + " after decrement");
            }
        }
Beispiel #18
0
            protected internal override void DoMerge(MergePolicy.OneMerge merge)
            {
                try
                {
                    // Stall all incoming merges until we see
                    // maxMergeCount:
                    int count = RunningMergeCount.IncrementAndGet();
                    try
                    {
                        Assert.IsTrue(count <= MaxMergeCount, "count=" + count + " vs maxMergeCount=" + MaxMergeCount);
                        EnoughMergesWaiting.Signal();

                        // Stall this merge until we see exactly
                        // maxMergeCount merges waiting
                        while (true)
                        {
                            // wait for 10 milliseconds
                            if (EnoughMergesWaiting.Wait(new TimeSpan(0, 0, 0, 0, 10)) || Failed.Get())
                            {
                                break;
                            }
                        }
                        // Then sleep a bit to give a chance for the bug
                        // (too many pending merges) to appear:
                        Thread.Sleep(20);
                        base.DoMerge(merge);
                    }
                    finally
                    {
                        RunningMergeCount.DecrementAndGet();
                    }
                }
                catch (Exception t)
                {
                    Failed.Set(true);
                    Writer.MergeFinish(merge);
                    throw new Exception(t.Message, t);
                }
            }
Beispiel #19
0
            public override void Run()
            {
                try
                {
                    while (Operations.Get() > 0)
                    {
                        int oper = rand.Next(100);

                        if (oper < CommitPercent)
                        {
                            if (NumCommitting.IncrementAndGet() <= MaxConcurrentCommits)
                            {
                                IDictionary <int, long> newCommittedModel;
                                long            version;
                                DirectoryReader oldReader;

                                lock (OuterInstance)
                                {
                                    newCommittedModel = new Dictionary <int, long>(OuterInstance.Model); // take a snapshot
                                    version           = OuterInstance.SnapshotCount++;
                                    oldReader         = OuterInstance.Reader;
                                    oldReader.IncRef(); // increment the reference since we will use this for reopening
                                }

                                DirectoryReader newReader;
                                if (rand.Next(100) < SoftCommitPercent)
                                {
                                    // assertU(h.Commit("softCommit","true"));
                                    if (Random().NextBoolean())
                                    {
                                        if (VERBOSE)
                                        {
                                            Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": call writer.getReader");
                                        }
                                        newReader = Writer.GetReader(true);
                                    }
                                    else
                                    {
                                        if (VERBOSE)
                                        {
                                            Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": reopen reader=" + oldReader + " version=" + version);
                                        }
                                        newReader = DirectoryReader.OpenIfChanged(oldReader, Writer.w, true);
                                    }
                                }
                                else
                                {
                                    // assertU(commit());
                                    if (VERBOSE)
                                    {
                                        Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": commit+reopen reader=" + oldReader + " version=" + version);
                                    }
                                    Writer.Commit();
                                    if (VERBOSE)
                                    {
                                        Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": now reopen after commit");
                                    }
                                    newReader = DirectoryReader.OpenIfChanged(oldReader);
                                }

                                // Code below assumes newReader comes w/
                                // extra ref:
                                if (newReader == null)
                                {
                                    oldReader.IncRef();
                                    newReader = oldReader;
                                }

                                oldReader.DecRef();

                                lock (OuterInstance)
                                {
                                    // install the new reader if it's newest (and check the current version since another reader may have already been installed)
                                    //System.out.println(Thread.currentThread().getName() + ": newVersion=" + newReader.getVersion());
                                    Debug.Assert(newReader.RefCount > 0);
                                    Debug.Assert(OuterInstance.Reader.RefCount > 0);
                                    if (newReader.Version > OuterInstance.Reader.Version)
                                    {
                                        if (VERBOSE)
                                        {
                                            Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": install new reader=" + newReader);
                                        }
                                        OuterInstance.Reader.DecRef();
                                        OuterInstance.Reader = newReader;

                                        // Silly: forces fieldInfos to be
                                        // loaded so we don't hit IOE on later
                                        // reader.toString
                                        newReader.ToString();

                                        // install this snapshot only if it's newer than the current one
                                        if (version >= OuterInstance.CommittedModelClock)
                                        {
                                            if (VERBOSE)
                                            {
                                                Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": install new model version=" + version);
                                            }
                                            OuterInstance.CommittedModel      = newCommittedModel;
                                            OuterInstance.CommittedModelClock = version;
                                        }
                                        else
                                        {
                                            if (VERBOSE)
                                            {
                                                Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": skip install new model version=" + version);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // if the same reader, don't decRef.
                                        if (VERBOSE)
                                        {
                                            Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": skip install new reader=" + newReader);
                                        }
                                        newReader.DecRef();
                                    }
                                }
                            }
                            NumCommitting.DecrementAndGet();
                        }
                        else
                        {
                            int    id   = rand.Next(Ndocs);
                            object sync = OuterInstance.SyncArr[id];

                            // set the lastId before we actually change it sometimes to try and
                            // uncover more race conditions between writing and reading
                            bool before = Random().NextBoolean();
                            if (before)
                            {
                                OuterInstance.LastId = id;
                            }

                            // We can't concurrently update the same document and retain our invariants of increasing values
                            // since we can't guarantee what order the updates will be executed.
                            lock (sync)
                            {
                                long val     = OuterInstance.Model[id];
                                long nextVal = Math.Abs(val) + 1;

                                if (oper < CommitPercent + DeletePercent)
                                {
                                    // assertU("<delete><id>" + id + "</id></delete>");

                                    // add tombstone first
                                    if (Tombstones)
                                    {
                                        Document d = new Document();
                                        d.Add(OuterInstance.NewStringField("id", "-" + Convert.ToString(id), Documents.Field.Store.YES));
                                        d.Add(OuterInstance.NewField(OuterInstance.Field, Convert.ToString(nextVal), StoredOnlyType));
                                        Writer.UpdateDocument(new Term("id", "-" + Convert.ToString(id)), d);
                                    }

                                    if (VERBOSE)
                                    {
                                        Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": term delDocs id:" + id + " nextVal=" + nextVal);
                                    }
                                    Writer.DeleteDocuments(new Term("id", Convert.ToString(id)));
                                    OuterInstance.Model[id] = -nextVal;
                                }
                                else if (oper < CommitPercent + DeletePercent + DeleteByQueryPercent)
                                {
                                    //assertU("<delete><query>id:" + id + "</query></delete>");

                                    // add tombstone first
                                    if (Tombstones)
                                    {
                                        Document d = new Document();
                                        d.Add(OuterInstance.NewStringField("id", "-" + Convert.ToString(id), Documents.Field.Store.YES));
                                        d.Add(OuterInstance.NewField(OuterInstance.Field, Convert.ToString(nextVal), StoredOnlyType));
                                        Writer.UpdateDocument(new Term("id", "-" + Convert.ToString(id)), d);
                                    }

                                    if (VERBOSE)
                                    {
                                        Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": query delDocs id:" + id + " nextVal=" + nextVal);
                                    }
                                    Writer.DeleteDocuments(new TermQuery(new Term("id", Convert.ToString(id))));
                                    OuterInstance.Model[id] = -nextVal;
                                }
                                else
                                {
                                    // assertU(adoc("id",Integer.toString(id), field, Long.toString(nextVal)));
                                    Document d = new Document();
                                    d.Add(OuterInstance.NewStringField("id", Convert.ToString(id), Documents.Field.Store.YES));
                                    d.Add(OuterInstance.NewField(OuterInstance.Field, Convert.ToString(nextVal), StoredOnlyType));
                                    if (VERBOSE)
                                    {
                                        Console.WriteLine("TEST: " + Thread.CurrentThread.Name + ": u id:" + id + " val=" + nextVal);
                                    }
                                    Writer.UpdateDocument(new Term("id", Convert.ToString(id)), d);
                                    if (Tombstones)
                                    {
                                        // remove tombstone after new addition (this should be optional?)
                                        Writer.DeleteDocuments(new Term("id", "-" + Convert.ToString(id)));
                                    }
                                    OuterInstance.Model[id] = nextVal;
                                }
                            }

                            if (!before)
                            {
                                OuterInstance.LastId = id;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(Thread.CurrentThread.Name + ": FAILED: unexpected exception");
                    Console.WriteLine(e.StackTrace);
                    throw new Exception(e.Message, e);
                }
            }
Beispiel #20
0
        public virtual void DecRef()
        {
            int rc = RefCount_Renamed.DecrementAndGet();

            Debug.Assert(rc >= 0);
        }
Beispiel #21
0
 public Address WithHighId(string name) => new Address(highId.DecrementAndGet(), name);
Beispiel #22
0
 public void DecrementConcurrentExecutionCount()
 {
     concurrentExecutionCount.DecrementAndGet();
 }
Beispiel #23
0
 private void Increment()
 {
     _consumeCount.IncrementAndGet();
     _remaining.DecrementAndGet();
 }
Beispiel #24
0
        public void DecreaseRequestCount(string requestIdentity)
        {
            AtomicInteger counter = RequestCounters.GetOrAdd(requestIdentity, id => new AtomicInteger());

            counter.DecrementAndGet();
        }
 public void OnClose(IndexReader reader)
 {
     Count.DecrementAndGet();
 }
Beispiel #26
0
 /// <exception cref="System.IO.IOException"/>
 public override void ReleaseFileSystem(FileSystem fs)
 {
     unmanagedFileSystems.DecrementAndGet();
     CloseFileSystem(fs);
 }
 /// <summary>
 /// 服务并发量自减
 /// </summary>
 internal void DecrementConcurrentExecutionCount()
 {
     serviceConcurrentExecutionCount.DecrementAndGet();
 }
Beispiel #28
0
 /// <summary>decrements and returns pending predecessor task count</summary>
 public virtual int DecrementAndGetPendingPredecessorTasks()
 {
     return(numberOfPendingPredecessorTasks.DecrementAndGet());
 }
Beispiel #29
0
 internal static int DecrementGlobalConcurrentThreads()
 {
     return(_concurrentThreadsExecuting.DecrementAndGet());
 }
 public void MarkThreadCompletion()
 {
     _concurrentExecutionCount.DecrementAndGet();
 }