public void run() {

      int numBatchesProcessed = 0;
      while (!itemIDBatches.isEmpty()) {
        try {
          long[] itemIDBatch = itemIDBatches.take();

          List<SimilarItems> similarItemsOfBatch = Lists.newArrayListWithCapacity(itemIDBatch.Length);
          foreach (long itemID in itemIDBatch) {
            List<RecommendedItem> similarItems = getRecommender().mostSimilarItems(itemID, getSimilarItemsPerItem());

            similarItemsOfBatch.add(new SimilarItems(itemID, similarItems));
          }

          results.offer(similarItemsOfBatch);

          if (++numBatchesProcessed % 5 == 0) {
            log.info("worker {} processed {} batches", number, numBatchesProcessed);
          }

        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
      log.info("worker {} processed {} batches. done.", number, numBatchesProcessed);
      numActiveWorkers.decrementAndGet();
    }
Exemple #2
0
 public virtual void execute(JobHandlerConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, string tenantId)
 {
     if (exceptionsRemaining.decrementAndGet() >= 0)
     {
         throw new Exception("exception remaining: " + exceptionsRemaining);
     }
     LOG.info("no more exceptions to throw.");
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotStartOtherSamplingWhenSamplingAllTheIndexes()
        public virtual void ShouldNotStartOtherSamplingWhenSamplingAllTheIndexes()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger totalCount = new java.util.concurrent.atomic.AtomicInteger(0);
            AtomicInteger totalCount = new AtomicInteger(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger concurrentCount = new java.util.concurrent.atomic.AtomicInteger(0);
            AtomicInteger concurrentCount = new AtomicInteger(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch jobLatch = new org.neo4j.test.DoubleLatch();
            DoubleLatch jobLatch = new DoubleLatch();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch testLatch = new org.neo4j.test.DoubleLatch();
            DoubleLatch testLatch = new DoubleLatch();

            IndexSamplingJobFactory jobFactory = (_indexId, proxy) =>
            {
                if (!concurrentCount.compareAndSet(0, 1))
                {
                    throw new System.InvalidOperationException("count !== 0 on create");
                }
                totalCount.incrementAndGet();
                jobLatch.WaitForAllToStart();
                testLatch.StartAndWaitForAllToStart();
                jobLatch.WaitForAllToFinish();
                concurrentCount.decrementAndGet();
                testLatch.Finish();
                return(null);
            };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexSamplingController controller = new IndexSamplingController(samplingConfig, jobFactory, jobQueue, tracker, snapshotProvider, scheduler, always(true));
            IndexSamplingController controller = new IndexSamplingController(_samplingConfig, jobFactory, _jobQueue, _tracker, _snapshotProvider, _scheduler, Always(true));

            when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
            when(_indexProxy.State).thenReturn(ONLINE);

            // when running once
            (new Thread(RunController(controller, TRIGGER_REBUILD_UPDATED))).Start();

            jobLatch.StartAndWaitForAllToStart();
            testLatch.WaitForAllToStart();

            // then blocking on first job
            assertEquals(1, concurrentCount.get());

            // when running a second time
            controller.SampleIndexes(BACKGROUND_REBUILD_UPDATED);

            // then no concurrent job execution
            jobLatch.Finish();
            testLatch.WaitForAllToFinish();

            // and finally exactly one job has run to completion
            assertEquals(0, concurrentCount.get());
            assertEquals(1, totalCount.get());
        }
Exemple #4
0
        /* ---- many producers ---- */

        public override void Produce(T t)
        {
            _queue.add(t);
            int newSize = _size.incrementAndGet();

            if (newSize > _maxSize)
            {
                _queue.poll();
                _size.decrementAndGet();
            }
        }
Exemple #5
0
        public override void OperationComplete(ChannelFuture future)
        {
            if (!future.Done)
            {
                throw new ComException("This should not be possible because we waited for the future to be done");
            }

            if (!future.Success || future.Cancelled)
            {
                future.Channel.close();
            }
            _writeAheadCounter.decrementAndGet();
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("resource") @Override public void postProcessApplicationUndeploy(org.camunda.bpm.application.ProcessApplicationInterface processApplication)
        public virtual void postProcessApplicationUndeploy(ProcessApplicationInterface processApplication)
        {
            // some tests deploy multiple PAs. => only clean DB after last PA is undeployed
            // if the deployment fails for example during parsing the deployment counter was not incremented
            // so we have to check if the counter is already zero otherwise we go into the negative values
            // best example is TestWarDeploymentWithBrokenBpmnXml in integration-test-engine test suite
            if (counter.get() == 0 || counter.decrementAndGet() == 0)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.ProcessEngine defaultProcessEngine = org.camunda.bpm.BpmPlatform.getDefaultProcessEngine();
                ProcessEngine defaultProcessEngine = BpmPlatform.DefaultProcessEngine;
                try
                {
                    logger.log(Level.INFO, "=== Ensure Clean Database ===");
                    ManagementServiceImpl managementService = (ManagementServiceImpl)defaultProcessEngine.ManagementService;
                    PurgeReport           report            = managementService.purge();

                    if (report.Empty)
                    {
                        logger.log(Level.INFO, "Clean DB and cache.");
                    }
                    else
                    {
                        StringBuilder builder = new StringBuilder();

                        DatabasePurgeReport databasePurgeReport = report.DatabasePurgeReport;
                        if (!databasePurgeReport.Empty)
                        {
                            builder.Append(DATABASE_NOT_CLEAN).Append(databasePurgeReport.PurgeReportAsString);
                        }

                        CachePurgeReport cachePurgeReport = report.CachePurgeReport;
                        if (!cachePurgeReport.Empty)
                        {
                            builder.Append(CACHE_IS_NOT_CLEAN).Append(cachePurgeReport.PurgeReportAsString);
                        }
                        logger.log(Level.INFO, builder.ToString());
                    }
                }
                catch (Exception e)
                {
                    logger.log(Level.SEVERE, "Could not clean DB:", e);
                }
            }
        }
 private void CloseCall()
 {
     // rollback once the call finished or failed
     _openCalls.decrementAndGet();
 }
Exemple #8
0
 public void disable()
 {
     _count.decrementAndGet();
     fail();
 }
 public virtual int DecrementInterruptCounter()
 {
     return(_interruptCounter.decrementAndGet());
 }
Exemple #10
0
 protected internal override bool fetchNext()
 {
     return(_count.decrementAndGet() >= 0 && next(_count.get()));
 }