コード例 #1
1
 public WatcherAnonymousInnerClassHelper(CuratorZookeeperClient outerInstance, CountDownLatch latch)
 {
     this.outerInstance = outerInstance;
     this.latch = latch;
 }
コード例 #2
0
        private void SignalInterruptionProcessingComplete()
        {
            CountDownLatch cdl = this.transportInterruptionProcessingComplete;

            if (cdl.Remaining == 0)
            {
                if (Tracer.IsDebugEnabled)
                {
                    Tracer.Debug("transportInterruptionProcessingComplete for: " + this.info.ConnectionId);
                }

                this.transportInterruptionProcessingComplete = null;

                FailoverTransport failoverTransport = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport;
                if (failoverTransport != null)
                {
                    failoverTransport.ConnectionInterruptProcessingComplete(this.info.ConnectionId);
                    if (Tracer.IsDebugEnabled)
                    {
                        Tracer.Debug("notified failover transport (" + failoverTransport +
                                     ") of interruption completion for: " + this.info.ConnectionId);
                    }
                }
            }
        }
コード例 #3
0
        public void TestBlockingMultipleRunnable()
        {
            // declare
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "SourceOne -> outstream<SomeType> {}" +
                "SourceTwo -> outstream<SomeType> {}" +
                "Future(outstream) {}");

            // instantiate
            var latchOne = new CountDownLatch(1);
            var latchTwo = new CountDownLatch(1);
            IDictionary <String, Object> ops = new Dictionary <String, Object>();

            ops.Put(
                "SourceOne", new DefaultSupportSourceOp(
                    new Object[]
            {
                latchOne, new Object[]
                {
                    1
                }
            }));
            ops.Put(
                "SourceTwo", new DefaultSupportSourceOp(
                    new Object[]
            {
                latchTwo, new Object[]
                {
                    1
                }
            }));
            var future = new DefaultSupportCaptureOp(2);

            ops["Future"] = future;

            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            try
            {
                dfOne.Run();
                Assert.Fail();
            }
            catch (UnsupportedOperationException ex)
            {
                Assert.AreEqual(
                    "The data flow 'MyDataFlowOne' has zero or multiple sources and requires the use of the start method instead",
                    ex.Message);
            }

            latchTwo.CountDown();
            dfOne.Start();
            latchOne.CountDown();
            dfOne.Join();

            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(2, future.GetAndReset().Count);
        }
コード例 #4
0
ファイル: TaskContinuation.cs プロジェクト: slagusev/api
 public void Dispose()
 {
     lock (this)
     {
         evt = null;
     }
 }
コード例 #5
0
        /// <exception cref="System.Exception"></exception>
        public virtual void FailingTestChangeTrackerContinuous()
        {
            CountDownLatch      changeTrackerFinishedSignal = new CountDownLatch(1);
            CountDownLatch      changeReceivedSignal        = new CountDownLatch(1);
            Uri                 testURL = GetReplicationURL();
            ChangeTrackerClient client  = new _ChangeTrackerClient_72(changeTrackerFinishedSignal
                                                                      , changeReceivedSignal);
            ChangeTracker changeTracker = new ChangeTracker(testURL, ChangeTracker.ChangeTrackerMode
                                                            .Continuous, false, 0, client);

            changeTracker.Start();
            try
            {
                bool success = changeReceivedSignal.Await(300, TimeUnit.Seconds);
                NUnit.Framework.Assert.IsTrue(success);
            }
            catch (Exception e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
            }
            changeTracker.Stop();
            try
            {
                bool success = changeTrackerFinishedSignal.Await(300, TimeUnit.Seconds);
                NUnit.Framework.Assert.IsTrue(success);
            }
            catch (Exception e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
            }
        }
コード例 #6
0
        protected void OnTransportInterrupted(ITransport sender)
        {
            Tracer.Debug("Transport has been Interrupted.");

            this.transportInterruptionProcessingComplete = new CountDownLatch(dispatchers.Count);
            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("transport interrupted, dispatchers: " + dispatchers.Count);
            }

            foreach (Session session in this.sessions)
            {
                session.ClearMessagesInProgress();
            }

            if (this.ConnectionInterruptedListener != null && !this.closing)
            {
                try
                {
                    this.ConnectionInterruptedListener();
                }
                catch
                {
                }
            }
        }
コード例 #7
0
 public void TestPerformance() {
    CountDownLatch simpleDateFormatGate = new CountDownLatch(CONCURRENCY);
    CountDownLatch simpleDateFormatFinisher = new CountDownLatch(CONCURRENCY);
    AtomicLong simpleDateFormatCount = new AtomicLong();
    for(int i = 0; i < CONCURRENCY; i++) {
       new ThRead(new SimpleDateFormatTask(simpleDateFormatFinisher, simpleDateFormatGate, simpleDateFormatCount, FORMAT)).start();
    }
    simpleDateFormatFinisher.await();
    CountDownLatch synchronizedGate = new CountDownLatch(CONCURRENCY);
    CountDownLatch synchronizedFinisher = new CountDownLatch(CONCURRENCY);
    AtomicLong synchronizedCount = new AtomicLong();
    SimpleDateFormat format = new SimpleDateFormat(FORMAT);
    for(int i = 0; i < CONCURRENCY; i++) {
       new ThRead(new SynchronizedTask(synchronizedFinisher, synchronizedGate, synchronizedCount, format)).start();
    }
    synchronizedFinisher.await();
    CountDownLatch formatterGate = new CountDownLatch(CONCURRENCY);
    CountDownLatch formatterFinisher = new CountDownLatch(CONCURRENCY);
    AtomicLong formatterCount = new AtomicLong();
    DateFormatter formatter = new DateFormatter(FORMAT, CONCURRENCY);
    for(int i = 0; i < CONCURRENCY; i++) {
       new ThRead(new FormatterTask(formatterFinisher, formatterGate, formatterCount, formatter)).start();
    }
    formatterFinisher.await();
    System.err.printf("pool: %s, new: %s, synchronized: %s", formatterCount.get(),  simpleDateFormatCount.get(), synchronizedCount.get());
    //assertTrue(formatterCount.get() < simpleDateFormatCount.get());
    //assertTrue(formatterCount.get() < synchronizedCount.get()); // Synchronized is faster?
 }
コード例 #8
0
        /// <summary>
        /// Should be called from NetTxSession when created to check if any TX
        /// data is stored for recovery and whether the Broker has matching info
        /// stored.  If an Transaction is found that belongs to this client and is
        /// still alive on the Broker it will be recovered, otherwise the stored
        /// data should be cleared.
        /// </summary>
        public void InitializeDtcTxContext()
        {
            // initialize the logger with the current Resource Manager Id
            RecoveryLogger.Initialize(ResourceManagerId);

            KeyValuePair <XATransactionId, byte[]>[] localRecoverables = RecoveryLogger.GetRecoverables();
            if (localRecoverables.Length == 0)
            {
                Tracer.Debug("Did not detect any open DTC transaction records on disk.");
                // No local data so anything stored on the broker can't be recovered here.
                return;
            }

            XATransactionId[] recoverables = TryRecoverBrokerTXIds();
            if (recoverables.Length == 0)
            {
                Tracer.Debug("Did not detect any recoverable transactions at Broker.");
                // Broker has no recoverable data so nothing to do here, delete the
                // old recovery log as its stale.
                RecoveryLogger.Purge();
                return;
            }

            List <KeyValuePair <XATransactionId, byte[]> > matches = new List <KeyValuePair <XATransactionId, byte[]> >();

            foreach (XATransactionId recoverable in recoverables)
            {
                foreach (KeyValuePair <XATransactionId, byte[]> entry in localRecoverables)
                {
                    if (entry.Key.Equals(recoverable))
                    {
                        Tracer.DebugFormat("Found a matching TX on Broker to stored Id: {0} reenlisting.", entry.Key);
                        matches.Add(entry);
                    }
                }
            }

            if (matches.Count != 0)
            {
                this.recoveryComplete = new CountDownLatch(matches.Count);

                foreach (KeyValuePair <XATransactionId, byte[]> recoverable in matches)
                {
                    this.transactionId = recoverable.Key;
                    Tracer.Info("Reenlisting recovered TX with Id: " + this.transactionId);
                    this.currentEnlistment =
                        TransactionManager.Reenlist(ResourceManagerGuid, recoverable.Value, this);
                }

                this.recoveryComplete.await();
                Tracer.Debug("All Recovered TX enlistments Reports complete, Recovery Complete.");
                TransactionManager.RecoveryComplete(ResourceManagerGuid);
                return;
            }

            // The old recovery information doesn't match what's on the broker so we
            // should discard it as its stale now.
            RecoveryLogger.Purge();
        }
コード例 #9
0
ファイル: Peer.cs プロジェクト: nikserdev/BitcoinSharp
        /// <exception cref="System.IO.IOException" />
        private void ProcessBlock(Block m)
        {
            Debug.Assert(Thread.CurrentThread == _thread);
            try
            {
                // Was this block requested by getblock?
                lock (_pendingGetBlockFutures)
                {
                    for (var i = 0; i < _pendingGetBlockFutures.Count; i++)
                    {
                        var f = _pendingGetBlockFutures[i];
                        if (f.Item.Hash.SequenceEqual(m.Hash))
                        {
                            // Yes, it was. So pass it through the future.
                            f.SetResult(m);
                            // Blocks explicitly requested don't get sent to the block chain.
                            _pendingGetBlockFutures.RemoveAt(i);
                            return;
                        }
                    }
                }
                // Otherwise it's a block sent to us because the peer thought we needed it, so add it to the block chain.
                // This call will synchronize on blockChain.
                if (_blockChain.Add(m))
                {
                    // The block was successfully linked into the chain. Notify the user of our progress.
                    if (_chainCompletionLatch != null)
                    {
                        _chainCompletionLatch.CountDown();
                        if (_chainCompletionLatch.Count == 0)
                        {
                            // All blocks fetched, so we don't need this anymore.
                            _chainCompletionLatch = null;
                        }
                    }
                }
                else
                {
                    // This block is unconnected - we don't know how to get from it back to the genesis block yet. That
                    // must mean that there are blocks we are missing, so do another getblocks with a new block locator
                    // to ask the peer to send them to us. This can happen during the initial block chain download where
                    // the peer will only send us 500 at a time and then sends us the head block expecting us to request
                    // the others.

                    // TODO: Should actually request root of orphan chain here.
                    BlockChainDownload(m.Hash);
                }
            }
            catch (VerificationException e)
            {
                // We don't want verification failures to kill the thread.
                _log.Warn("block verification failed", e);
            }
            catch (ScriptException e)
            {
                // We don't want script failures to kill the thread.
                _log.Warn("script exception", e);
            }
        }
コード例 #10
0
        public async Task CommitAsync(Enlistment enlistment)
        {
            using (await this.syncObject.LockAsync().Await())
            {
                try
                {
                    Tracer.Debug("Commit notification received for TX id: " + this.TransactionId);

                    if (this.TransactionId != null)
                    {
                        // Now notify the broker that a new XA'ish transaction has completed.
                        TransactionInfo info = new TransactionInfo();
                        info.ConnectionId  = this.connection.ConnectionId;
                        info.TransactionId = this.TransactionId;
                        info.Type          = (int)TransactionType.CommitTwoPhase;

                        await this.connection.CheckConnectedAsync().Await();

                        await this.connection.SyncRequestAsync(info).Await();

                        Tracer.Debug("Transaction Commit Done TX id: " + this.TransactionId);

                        RecoveryLogger.LogRecovered(this.TransactionId as XATransactionId);

                        // if server responds that nothing needs to be done, then reply done.
                        enlistment.Done();

                        AfterCommit();
                    }
                }
                catch (Exception ex)
                {
                    Tracer.DebugFormat("Transaction[{0}] Commit failed with error: {1}",
                                       this.TransactionId, ex.Message);
                    try
                    {
                        this.connection.OnAsyncException(ex);
                    }
                    catch (Exception error)
                    {
                        Tracer.Error(error.ToString());
                    }
                }
                finally
                {
                    this.currentEnlistment = null;
                    this.TransactionId     = null;
                    this.netTxState        = TxState.None;

                    CountDownLatch latch = this.recoveryComplete;
                    if (latch != null)
                    {
                        latch.countDown();
                    }

                    this.dtcControlEvent.Set();
                }
            }
        }
コード例 #11
0
        public virtual void TestSaveImageWhileSyncInProgress()
        {
            Configuration conf = GetConf();

            NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode);
            DFSTestUtil.FormatNameNode(conf);
            FSNamesystem namesystem = FSNamesystem.LoadFromDisk(conf);

            try
            {
                FSImage   fsimage = namesystem.GetFSImage();
                FSEditLog editLog = fsimage.GetEditLog();
                JournalSet.JournalAndStream jas     = editLog.GetJournals()[0];
                EditLogFileOutputStream     spyElos = Org.Mockito.Mockito.Spy((EditLogFileOutputStream
                                                                               )jas.GetCurrentStream());
                jas.SetCurrentStreamForTests(spyElos);
                AtomicReference <Exception> deferredException = new AtomicReference <Exception>();
                CountDownLatch waitToEnterFlush = new CountDownLatch(1);
                Sharpen.Thread doAnEditThread   = new _Thread_371(namesystem, deferredException, waitToEnterFlush
                                                                  );
                Answer <Void> blockingFlush = new _Answer_388(doAnEditThread, waitToEnterFlush);
                // Signal to main thread that the edit thread is in the racy section
                Org.Mockito.Mockito.DoAnswer(blockingFlush).When(spyElos).Flush();
                doAnEditThread.Start();
                // Wait for the edit thread to get to the logsync unsynchronized section
                Log.Info("Main thread: waiting to enter flush...");
                waitToEnterFlush.Await();
                NUnit.Framework.Assert.IsNull(deferredException.Get());
                Log.Info("Main thread: detected that logSync is in unsynchronized section.");
                Log.Info("Trying to enter safe mode.");
                Log.Info("This should block for " + BlockTime + "sec, since flush will sleep that long"
                         );
                long st = Time.Now();
                namesystem.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                long et = Time.Now();
                Log.Info("Entered safe mode");
                // Make sure we really waited for the flush to complete!
                NUnit.Framework.Assert.IsTrue(et - st > (BlockTime - 1) * 1000);
                // Once we're in safe mode, save namespace.
                namesystem.SaveNamespace();
                Log.Info("Joining on edit thread...");
                doAnEditThread.Join();
                NUnit.Framework.Assert.IsNull(deferredException.Get());
                // We did 3 edits: begin, txn, and end
                NUnit.Framework.Assert.AreEqual(3, VerifyEditLogs(namesystem, fsimage, NNStorage.
                                                                  GetFinalizedEditsFileName(1, 3), 1));
                // after the save, just the one "begin"
                NUnit.Framework.Assert.AreEqual(1, VerifyEditLogs(namesystem, fsimage, NNStorage.
                                                                  GetInProgressEditsFileName(4), 4));
            }
            finally
            {
                Log.Info("Closing nn");
                if (namesystem != null)
                {
                    namesystem.Close();
                }
            }
        }
コード例 #12
0
 public _Thread_152(long length, OutputStreamWriter osw, int ch, CountDownLatch latch
                    )
 {
     this.length = length;
     this.osw    = osw;
     this.ch     = ch;
     this.latch  = latch;
 }
コード例 #13
0
 public AbstractRunnableHandle(IList <V> items, IThreadLocalCleanupController threadLocalCleanupController)
 {
     this.latch    = new CountDownLatch(items.Count);
     this.exHolder = new InterruptingParamHolder(Thread.CurrentThread);
     this.items    = items;
     this.threadLocalCleanupController = threadLocalCleanupController;
     this.forkState = threadLocalCleanupController.CreateForkState();
 }
コード例 #14
0
ファイル: TestBagOfPostings.cs プロジェクト: zfxsss/lucenenet
 public ThreadAnonymousInnerClassHelper(TestBagOfPostings outerInstance, int maxTermsPerDoc, ConcurrentQueue <string> postings, RandomIndexWriter iw, CountDownLatch startingGun)
 {
     this.OuterInstance  = outerInstance;
     this.MaxTermsPerDoc = maxTermsPerDoc;
     this.Postings       = postings;
     this.Iw             = iw;
     this.StartingGun    = startingGun;
 }
コード例 #15
0
 public ThreadAnonymousInnerClassHelper(TestControlledRealTimeReopenThread outerInstance, CountDownLatch latch, CountDownLatch signal, TrackingIndexWriter writer, SearcherManager manager)
 {
     this.OuterInstance = outerInstance;
     this.Latch         = latch;
     this.Signal        = signal;
     this.Writer        = writer;
     this.Manager       = manager;
 }
コード例 #16
0
 /// <exception cref="System.IO.IOException"/>
 public override void SetReadyToFlush()
 {
     Transmit();
     lock (this)
     {
         syncLatch = new CountDownLatch(outstandingRequests.Get());
     }
 }
 public _Thread_128(ThreadSafeProgressMonitor pm, CountDownLatch doUpdate, CountDownLatch
                    didUpdate, CountDownLatch doEndWorker)
 {
     this.pm          = pm;
     this.doUpdate    = doUpdate;
     this.didUpdate   = didUpdate;
     this.doEndWorker = doEndWorker;
 }
コード例 #18
0
 public ConcurrentMergeSchedulerAnonymousInnerClassHelper(TestConcurrentMergeScheduler outerInstance, int maxMergeCount, CountDownLatch enoughMergesWaiting, AtomicInteger runningMergeCount, AtomicBoolean failed)
 {
     this.OuterInstance       = outerInstance;
     this.MaxMergeCount       = maxMergeCount;
     this.EnoughMergesWaiting = enoughMergesWaiting;
     this.RunningMergeCount   = runningMergeCount;
     this.Failed = failed;
 }
コード例 #19
0
 internal WriterThread(ReaderHolder holder, IndexWriter writer, int numOps, Random random, CountDownLatch latch)
     : base()
 {
     this.Holder = holder;
     this.Writer = writer;
     this.NumOps = numOps;
     this.Latch  = latch;
 }
コード例 #20
0
 public _Callable_240(TestInMemorySCMStore _enclosing, CountDownLatch start, string
                      key, string fileName)
 {
     this._enclosing = _enclosing;
     this.start      = start;
     this.key        = key;
     this.fileName   = fileName;
 }
コード例 #21
0
 public _ChangeTrackerClient_197(CountDownLatch changeTrackerFinishedSignal, CountDownLatch
                                 changeReceivedSignal, int errorCode, string statusMessage)
 {
     this.changeTrackerFinishedSignal = changeTrackerFinishedSignal;
     this.changeReceivedSignal        = changeReceivedSignal;
     this.errorCode     = errorCode;
     this.statusMessage = statusMessage;
 }
コード例 #22
0
 public SearcherFactoryAnonymousInnerClassHelper2(TestSearcherManager outerInstance, CountDownLatch awaitEnterWarm, CountDownLatch awaitClose, AtomicBoolean triedReopen, TaskScheduler es)
 {
     this.OuterInstance  = outerInstance;
     this.AwaitEnterWarm = awaitEnterWarm;
     this.AwaitClose     = awaitClose;
     this.TriedReopen    = triedReopen;
     this.Es             = es;
 }
コード例 #23
0
        public override void SetUp()
        {
            base.SetUp();

            this.doneLatch    = new CountDownLatch(1);
            this.counter      = 0;
            this.errorMessage = null;
        }
コード例 #24
0
 public ThreadAnonymousInnerClassHelper(TestDocValuesIndexing outerInstance, IndexWriter w, CountDownLatch startingGun, AtomicBoolean hitExc, Document doc)
 {
     this.OuterInstance = outerInstance;
     this.w             = w;
     this.StartingGun   = startingGun;
     this.HitExc        = hitExc;
     this.Doc           = doc;
 }
コード例 #25
0
 public virtual void Reset()
 {
     lock (this)
     {
         clientConnected = new CountDownLatch(1);
         connected       = false;
     }
 }
コード例 #26
0
        public void TestPerformance()
        {
            int numEvents  = 1;
            int numThreads = 2;

            Configuration config = new Configuration();

            config.EngineDefaults.Threading.IsListenerDispatchPreserveOrder = false;
            EPServiceProvider engine = EPServiceProviderManager.GetDefaultProvider(config);

            engine.EPAdministrator.Configuration.AddEventType(typeof(TransactionEvent));
            engine.EPAdministrator.Configuration.AddPlugInSingleRowFunction("MyDynModel", GetType().FullName, "MyDynModel");

            String      epl  = "select MyDynModel({Col_001, Col_002, Col_003}) as model_score from TransactionEvent";
            EPStatement stmt = engine.EPAdministrator.CreateEPL(epl);

            stmt.Subscriber = new MySubscriber();

            var queue = new LinkedBlockingQueue <Runnable>();
            var latch = new CountDownLatch(numEvents);

            for (int i = 0; i < numEvents; i++)
            {
                queue.Push((new MyRunnable(engine.EPRuntime, latch, new TransactionEvent(1, 2, 3))).Run);
            }

            var threads = Executors.NewFixedThreadPool(numThreads);

            var delta = PerformanceObserver.TimeMillis(
                () =>
            {
                for (int ii = 0; ii < numThreads; ii++)
                {
                    threads.Submit(
                        () =>
                    {
                        Runnable runnable;
                        while (queue.Pop(0, out runnable))
                        {
                            runnable.Invoke();
                        }
                    });
                }


                //ThreadPoolExecutor threads = new ThreadPoolExecutor(numThreads, numThreads, 10, TimeUnit.SECONDS, queue);
                //threads.PrestartAllCoreThreads();
                latch.Await(TimeSpan.FromMinutes(1));
                if (latch.Count > 0)
                {
                    throw new Exception("Failed to complete in 1 minute");
                }
            });

            Console.WriteLine("Took " + delta + " millis");
            threads.Shutdown();
            threads.AwaitTermination(TimeSpan.FromSeconds(10));
        }
コード例 #27
0
        /*
         * LUCENE-3528 - NRTManager hangs in certain situations
         */
        public virtual void TestThreadStarvationNoDeleteNRTReader()
        {
            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));

            conf.SetMergePolicy(Random().NextBoolean() ? NoMergePolicy.COMPOUND_FILES : NoMergePolicy.NO_COMPOUND_FILES);
            Directory      d      = NewDirectory();
            CountDownLatch latch  = new CountDownLatch(1);
            CountDownLatch signal = new CountDownLatch(1);

            LatchedIndexWriter  _writer = new LatchedIndexWriter(d, conf, latch, signal);
            TrackingIndexWriter writer  = new TrackingIndexWriter(_writer);
            SearcherManager     manager = new SearcherManager(_writer, false, null);
            Document            doc     = new Document();

            doc.Add(NewTextField("test", "test", Field.Store.YES));
            writer.AddDocument(doc);
            manager.MaybeRefresh();
            ThreadClass t = new ThreadAnonymousInnerClassHelper(this, latch, signal, writer, manager);

            t.Start();
            _writer.WaitAfterUpdate = true;                                    // wait in addDocument to let some reopens go through
            long lastGen = writer.UpdateDocument(new Term("foo", "bar"), doc); // once this returns the doc is already reflected in the last reopen

            Assert.IsFalse(manager.SearcherCurrent);                           // false since there is a delete in the queue

            IndexSearcher searcher = manager.Acquire();

            try
            {
                Assert.AreEqual(2, searcher.IndexReader.NumDocs());
            }
            finally
            {
                manager.Release(searcher);
            }
            ControlledRealTimeReopenThread <IndexSearcher> thread = new ControlledRealTimeReopenThread <IndexSearcher>(writer, manager, 0.01, 0.01);

            thread.Start(); // start reopening
            if (VERBOSE)
            {
                Console.WriteLine("waiting now for generation " + lastGen);
            }

            AtomicBoolean finished = new AtomicBoolean(false);
            ThreadClass   waiter   = new ThreadAnonymousInnerClassHelper2(this, lastGen, thread, finished);

            waiter.Start();
            manager.MaybeRefresh();
            waiter.Join(1000);
            if (!finished.Get())
            {
                waiter.Interrupt();
                Assert.Fail("thread deadlocked on waitForGeneration");
            }
            thread.Dispose();
            thread.Join();
            IOUtils.Close(manager, _writer, d);
        }
コード例 #28
0
            public void Run(RegressionEnvironment env)
            {
                // declare
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<SomeType> { name: 'SourceOne' }" +
                    "DefaultSupportSourceOp -> outstream<SomeType> { name: 'SourceTwo' }" +
                    "DefaultSupportCaptureOp(outstream) {}",
                    path);

                // instantiate
                var latchOne = new CountDownLatch(1);
                var latchTwo = new CountDownLatch(1);
                IDictionary<string, object> ops = new Dictionary<string, object>();
                ops.Put(
                    "SourceOne",
                    new DefaultSupportSourceOp(
                        new object[] {
                            latchOne,
                            new object[] {1}
                        }));
                ops.Put(
                    "SourceTwo",
                    new DefaultSupportSourceOp(
                        new object[] {
                            latchTwo,
                            new object[] {1}
                        }));
                var future = new DefaultSupportCaptureOp(2, env.Container.LockManager());
                ops.Put("DefaultSupportCaptureOp", future);

                var options =
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(
                        new DefaultSupportGraphOpProviderByOpName(ops));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);

                dfOne.Start();
                Sleep(50);
                Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State);

                latchOne.CountDown();
                Sleep(200);
                Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State);

                latchTwo.CountDown();
                try {
                    dfOne.Join();
                }
                catch (ThreadInterruptedException e) {
                    throw new EPException(e);
                }

                Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
                Assert.AreEqual(2, future.GetAndReset().Count);
                env.UndeployAll();
            }
コード例 #29
0
        /// <summary>Construct a Bookkeeper journal manager.</summary>
        /// <exception cref="System.IO.IOException"/>
        public BookKeeperJournalManager(Configuration conf, URI uri, NamespaceInfo nsInfo
                                        )
        {
            this.conf   = conf;
            this.nsInfo = nsInfo;
            string zkConnect = uri.GetAuthority().Replace(";", ",");

            basePath     = uri.GetPath();
            ensembleSize = conf.GetInt(BkjmBookkeeperEnsembleSize, BkjmBookkeeperEnsembleSizeDefault
                                       );
            quorumSize = conf.GetInt(BkjmBookkeeperQuorumSize, BkjmBookkeeperQuorumSizeDefault
                                     );
            ackQuorumSize   = conf.GetInt(BkjmBookkeeperAckQuorumSize, quorumSize);
            addEntryTimeout = conf.GetInt(BkjmBookkeeperAddEntryTimeoutSec, BkjmBookkeeperAddEntryTimeoutDefault
                                          );
            speculativeReadTimeout = conf.GetInt(BkjmBookkeeperSpeculativeReadTimeoutMs, BkjmBookkeeperSpeculativeReadTimeoutDefault
                                                 );
            readEntryTimeout = conf.GetInt(BkjmBookkeeperReadEntryTimeoutSec, BkjmBookkeeperReadEntryTimeoutDefault
                                           );
            ledgerPath = basePath + "/ledgers";
            string maxTxIdPath = basePath + "/maxtxid";
            string currentInprogressNodePath = basePath + "/CurrentInprogress";

            versionPath = basePath + "/version";
            digestpw    = conf.Get(BkjmBookkeeperDigestPw, BkjmBookkeeperDigestPwDefault);
            try
            {
                zkConnectLatch = new CountDownLatch(1);
                int bkjmZKSessionTimeout = conf.GetInt(BkjmZkSessionTimeout, BkjmZkSessionTimeoutDefault
                                                       );
                zkc = new ZooKeeper(zkConnect, bkjmZKSessionTimeout, new BookKeeperJournalManager.ZkConnectionWatcher
                                        (this));
                // Configured zk session timeout + some extra grace period (here
                // BKJM_ZK_SESSION_TIMEOUT_DEFAULT used as grace period)
                int zkConnectionLatchTimeout = bkjmZKSessionTimeout + BkjmZkSessionTimeoutDefault;
                if (!zkConnectLatch.Await(zkConnectionLatchTimeout, TimeUnit.Milliseconds))
                {
                    throw new IOException("Error connecting to zookeeper");
                }
                PrepareBookKeeperEnv();
                ClientConfiguration clientConf = new ClientConfiguration();
                clientConf.SetSpeculativeReadTimeout(speculativeReadTimeout);
                clientConf.SetReadEntryTimeout(readEntryTimeout);
                clientConf.SetAddEntryTimeout(addEntryTimeout);
                bkc = new BookKeeper(clientConf, zkc);
            }
            catch (KeeperException e)
            {
                throw new IOException("Error initializing zk", e);
            }
            catch (Exception ie)
            {
                Sharpen.Thread.CurrentThread().Interrupt();
                throw new IOException("Interrupted while initializing bk journal manager", ie);
            }
            ci      = new CurrentInprogress(zkc, currentInprogressNodePath);
            maxTxId = new MaxTxId(zkc, maxTxIdPath);
        }
コード例 #30
0
 public WriterThread(TestMultiThreadedHflush _enclosing, FSDataOutputStream stm, AtomicReference
                     <Exception> thrown, CountDownLatch countdown, int numWrites)
 {
     this._enclosing = _enclosing;
     this.stm        = stm;
     this.thrown     = thrown;
     this.numWrites  = numWrites;
     this.countdown  = countdown;
 }
コード例 #31
0
        internal void TransportInterruptionProcessingComplete()
        {
            CountDownLatch cdl = this.transportInterruptionProcessingComplete;

            if (cdl != null)
            {
                cdl.countDown();
            }
        }
コード例 #32
0
        public void AwaitThatTimesOutReturnsFalse()
        {
            const int      NumThreads = 10;
            CountDownLatch latch      = new CountDownLatch(NumThreads);

            bool result = latch.Await(50);

            Expect(result, False);
        }
コード例 #33
0
        //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
        //ORIGINAL LINE: @Test public void testCloseableScheduleWithFixedDelay() throws InterruptedException
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testCloseableScheduleWithFixedDelay()
        {
            CloseableScheduledExecutorService service = new CloseableScheduledExecutorService(executorService);

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(QTY);
            CountDownLatch latch = new CountDownLatch(QTY);
            service.scheduleWithFixedDelay(() =>
                    {
                        latch.countDown();
                    }, DELAY_MS, DELAY_MS, TimeUnit.MILLISECONDS);

            Assert.assertTrue(latch.@await((QTY * 2) * DELAY_MS, TimeUnit.MILLISECONDS));
        }
コード例 #34
0
ファイル: BaseWebView.cs プロジェクト: vhnatyk/WebMarco.2.0
        /// <summary>
        /// Evaluates the expression and returns the value.
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public string EvaluateScript(BaseWebView webView, string expression) {
            latch = new CountDownLatch(1);
            string code = "javascript:window." + Name + ".setValue((function(){try{return " + expression
            + "+\"\";}catch(js_eval_err){console.log('js_eval_err : ' + js_eval_err); return '';}})());";
            webView.LoadUrl(code);

            try {
                // Set a 1 second timeout in case there's an error
                latch.Await(1, TimeUnit.Seconds);
                return returnValue;
            } catch (System.Exception ex) {
                DLogger.WriteLog(ex);
            }
            return null;
        }
コード例 #35
0
 public SimpleDateFormatTask(CountDownLatch main, CountDownLatch gate, AtomicLong count, String format) {
    this.format = format;
    this.count = count;
    this.gate = gate;
    this.main = main;
 }
コード例 #36
0
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: void internalBlockUntilConnectedOrTimedOut() throws InterruptedException
        internal virtual void internalBlockUntilConnectedOrTimedOut()
        {
            long waitTimeMs = connectionTimeoutMs;
            while (!state.isConnected() && (waitTimeMs > 0))
            {
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(1);
                CountDownLatch latch = new CountDownLatch(1);
                Watcher tempWatcher = new WatcherAnonymousInnerClassHelper(this, latch);

                state.addParentWatcher(tempWatcher);
                var startTimeMs = TimeHelper.ElapsedMiliseconds;
                try
                {
                    latch.@await(1, TimeUnit.SECONDS);
                }
                finally
                {
                    state.removeParentWatcher(tempWatcher);
                }
                var elapsed = Math.Max(1, TimeHelper.ElapsedMiliseconds - startTimeMs);
                waitTimeMs -= elapsed;
            }
        }
コード例 #37
0
ファイル: TaskContinuation.cs プロジェクト: nguyenkien/api
		public void Dispose ()
		{
		    lock (this)
		    {
		        evt = null;
		    }
		}
コード例 #38
0
ファイル: TaskContinuation.cs プロジェクト: nguyenkien/api
		public CountdownContinuation (int initialCount)
		{
            this.evt = new CountDownLatch(initialCount);
		}
コード例 #39
0
 public Worker(CountDownLatch latch, Serializer serializer, Queue<Status> queue, Example example) {
    this.serializer = serializer;
    this.example = example;
    this.latch = latch;
    this.queue = queue;
 }
コード例 #40
0
 public FormatterTask(CountDownLatch main, CountDownLatch gate, AtomicLong count, DateFormatter formatter) {
    this.formatter = formatter;
    this.count = count;
    this.gate = gate;
    this.main = main;
 }
コード例 #41
0
        public void CanPostManyEvents() {
            _eventQueue.DeleteQueue();
            RemoveAllEvents();

            const int batchSize = 250;
            const int batchCount = 10;

            try {
                var countdown = new CountDownLatch(10);
                var messageSubscriber = IoC.GetInstance<IMessageSubscriber>();
                messageSubscriber.Subscribe<EntityChanged>(ch => {
                    if (ch.ChangeType != ChangeType.Added || ch.Type != typeof(PersistentEvent).Name)
                        return;

                    if (countdown.Remaining <= 0)
                        throw new ApplicationException("Too many change notifications.");

                    countdown.Signal();
                });

                Parallel.For(0, batchCount, i => {
                    _eventController.Request = CreateRequestMessage(new ClaimsPrincipal(IdentityUtils.CreateUserIdentity(TestConstants.UserEmail, TestConstants.UserId, new[] { TestConstants.OrganizationId }, new[] { AuthorizationRoles.Client }, TestConstants.ProjectId)), true, false);
                    var events = new RandomEventGenerator().Generate(batchSize);
                    var compressedEvents = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(events)).CompressAsync().Result;
                    var actionResult = _eventController.PostAsync(compressedEvents, version: 2, userAgent: "exceptionless/2.0.0.0").Result;
                    Assert.IsType<StatusCodeResult>(actionResult);
                });

                Assert.Equal(batchCount, _eventQueue.GetQueueCount());

                var sw = new Stopwatch();
                var processEventsJob = IoC.GetInstance<EventPostsJob>();
                sw.Start();
                processEventsJob.RunUntilEmpty();
                sw.Stop();
                Trace.WriteLine(sw.Elapsed);

                Assert.Equal(0, _eventQueue.GetQueueCount());
                Assert.Equal(batchSize * batchCount, EventCount());

                bool success = countdown.Wait(5000);
                Assert.True(success);
            } finally {
                _eventQueue.DeleteQueue();
            }
        }
コード例 #42
0
        /// <summary>
        /// Should be called from NetTxSession when created to check if any TX
        /// data is stored for recovery and whether the Broker has matching info
        /// stored.  If an Transaction is found that belongs to this client and is
        /// still alive on the Broker it will be recovered, otherwise the stored 
        /// data should be cleared.
        /// </summary>
        public void InitializeDtcTxContext()
        {
            // initialize the logger with the current Resource Manager Id
            RecoveryLogger.Initialize(ResourceManagerId);

            KeyValuePair<XATransactionId, byte[]>[] localRecoverables = RecoveryLogger.GetRecoverables();
            if (localRecoverables.Length == 0)
            {
                Tracer.Debug("Did not detect any open DTC transaction records on disk.");
                // No local data so anything stored on the broker can't be recovered here.
                return;
            }

            XATransactionId[] recoverables = TryRecoverBrokerTXIds();
            if (recoverables.Length == 0)
            {
                Tracer.Debug("Did not detect any recoverable transactions at Broker.");
                // Broker has no recoverable data so nothing to do here, delete the
                // old recovery log as its stale.
                RecoveryLogger.Purge();
                return;
            }

            List<KeyValuePair<XATransactionId, byte[]>> matches = new List<KeyValuePair<XATransactionId, byte[]>>();

            foreach(XATransactionId recoverable in recoverables)
            {
                foreach(KeyValuePair<XATransactionId, byte[]> entry in localRecoverables)
                {
                    if(entry.Key.Equals(recoverable))
                    {
                        Tracer.DebugFormat("Found a matching TX on Broker to stored Id: {0} reenlisting.", entry.Key);
                        matches.Add(entry);
                    }
                }
            }

            if (matches.Count != 0)
            {
                this.recoveryComplete = new CountDownLatch(matches.Count);

                foreach (KeyValuePair<XATransactionId, byte[]> recoverable in matches)
                {
                    this.transactionId = recoverable.Key;
                    Tracer.Info("Reenlisting recovered TX with Id: " + this.transactionId);
                    this.currentEnlistment =
                        TransactionManager.Reenlist(ResourceManagerGuid, recoverable.Value, this);
                }

                this.recoveryComplete.await();
                Tracer.Debug("All Recovered TX enlistments Reports complete, Recovery Complete.");
                TransactionManager.RecoveryComplete(ResourceManagerGuid);
                return;
            }

            // The old recovery information doesn't match what's on the broker so we
            // should discard it as its stale now.
            RecoveryLogger.Purge();
        }
コード例 #43
0
 public SynchronizedTask(CountDownLatch main, CountDownLatch gate, AtomicLong count, SimpleDateFormat format) {
    this.format = format;
    this.count = count;
    this.gate = gate;
    this.main = main;
 }