/// <summary> /// This removes the "num" values currently at the head of the Queue for the /// provided key. /// </summary> /// <remarks> /// This removes the "num" values currently at the head of the Queue for the /// provided key. Will immediately fire the Queue filler function if key /// does not exist /// How many values are actually returned is governed by the /// <code>SyncGenerationPolicy</code> specified by the user. /// </remarks> /// <param name="keyName">String key name</param> /// <param name="num">Minimum number of values to return.</param> /// <returns>List<E> values returned</returns> /// <exception cref="System.IO.IOException"/> /// <exception cref="ExecutionException"/> public virtual IList <E> GetAtMost(string keyName, int num) { LinkedBlockingQueue <E> keyQueue = keyQueues.Get(keyName); // Using poll to avoid race condition.. List <E> ekvs = new List <E>(); try { for (int i = 0; i < num; i++) { E val = keyQueue.Poll(); // If queue is empty now, Based on the provided SyncGenerationPolicy, // figure out how many new values need to be generated synchronously if (val == null) { // Synchronous call to get remaining values int numToFill = 0; switch (policy) { case ValueQueue.SyncGenerationPolicy.AtleastOne: { numToFill = (ekvs.Count < 1) ? 1 : 0; break; } case ValueQueue.SyncGenerationPolicy.LowWatermark: { numToFill = Math.Min(num, (int)(lowWatermark * numValues)) - ekvs.Count; break; } case ValueQueue.SyncGenerationPolicy.All: { numToFill = num - ekvs.Count; break; } } // Synchronous fill if not enough values found if (numToFill > 0) { refiller.FillQueueForKey(keyName, ekvs, numToFill); } // Asynch task to fill > lowWatermark if (i <= (int)(lowWatermark * numValues)) { SubmitRefillTask(keyName, keyQueue); } return(ekvs); } ekvs.AddItem(val); } } catch (Exception e) { throw new IOException("Exeption while contacting value generator ", e); } return(ekvs); }
/// <summary> /// 执行添加 /// </summary> private void Add() { Unit o = null; while ((o = addUnits.Poll()) != null) { units.Add(o.Id, o); } }
protected void Fire() { while (events.GetCount() != 0) { NetEvent netEvent = events.Poll(); if (netEvent != null) { netEvent.Fire(); } } }
/// <summary> /// 消息事件派遣 /// </summary> public void Fire() { //事件派遣 while (mDataPackets.GetCount() > 0) { NetEvent msg = mDataPackets.Poll(); if (msg != null) { msg.Fire(); } } }
public void WriteFile(System.Object param) { LogFileWriter lfw = (LogFileWriter)param; while (lfw.isWorking) { while (logs.GetCount() != 0) { Log log = logs.Poll(1000); if (log != null) { WriteFile(log); } } } }
/// <summary> /// 刷新-逻辑线程调用 /// </summary> /// <param name="runtime"></param> public void RunInLogic(DateTime runtime) { for (IAction action = null; (action = actions.Poll()) != null;) { IEffect effect = action.Proc(this, runtime); if (effect != null) { effects.Enqueue(effect); } } for (IEffect effect = null; (effect = effects.Dequeue()) != null;) { effect.changeState(); } List <int> removeStates = null; foreach (IState o in states.Values) { o.RunInLogic(runtime); if (o.CanRemove()) { if (removeStates == null) { removeStates = new List <int>(); } removeStates.Add(o.GetCode()); } } if (removeStates == null) { return; } for (int i = 0; i < removeStates.Count; i++) { int code = removeStates[i]; if (states.ContainsKey(code)) { states.Remove(code); } } }
protected override IMessage DoReceive(TimeSpan timeout) { IMessage result; return(_queue.Poll(out result) ? result : null); }
/// <summary> Analyze the text in the single thread. </summary> private void analyzeInSingleThread() { // first phase if (plainTextPluginCnt == 0) { return; } LinkedBlockingQueue <PlainSentence> inQueue1 = null; LinkedBlockingQueue <PlainSentence> outQueue1 = null; PlainSentence ps = null; outQueue1 = queuePhase1[0]; for (int i = 0; i < plainTextPluginCnt; i++) { inQueue1 = outQueue1; outQueue1 = queuePhase1[i + 1]; while ((ps = inQueue1.Poll()) != null) { if ((ps = plainTextProcessors[i].doProcess(ps)) != null) { outQueue1.Add(ps); } while (plainTextProcessors[i].hasRemainingData()) { if ((ps = plainTextProcessors[i].doProcess(null)) != null) { outQueue1.Add(ps); } } if ((ps = plainTextProcessors[i].flush()) != null) { outQueue1.Add(ps); } } } // second phase if (morphAnalyzer == null) { return; } LinkedBlockingQueue <SetOfSentences> inQueue2 = null; LinkedBlockingQueue <SetOfSentences> outQueue2 = null; SetOfSentences sos = null; inQueue1 = outQueue1; outQueue2 = queuePhase2[0]; while ((ps = inQueue1.Poll()) != null) { if ((sos = morphAnalyzer.morphAnalyze(ps)) != null) { outQueue2.Add(sos); } } if (morphemePluginCnt == 0) { return; } for (int i = 0; i < morphemePluginCnt; i++) { inQueue2 = outQueue2; outQueue2 = queuePhase2[i + 1]; while ((sos = inQueue2.Poll()) != null) { if ((sos = morphemeProcessors[i].doProcess(sos)) != null) { outQueue2.Add(sos); } } } // third phase if (posTagger == null) { return; } LinkedBlockingQueue <Sentence> inQueue3 = null; LinkedBlockingQueue <Sentence> outQueue3 = null; Sentence sent = null; inQueue2 = outQueue2; outQueue3 = queuePhase3[0]; while ((sos = inQueue2.Poll()) != null) { if ((sent = posTagger.tagPOS(sos)) != null) { outQueue3.Add(sent); } } if (posPluginCnt == 0) { return; } for (int i = 0; i < posPluginCnt; i++) { inQueue3 = outQueue3; outQueue3 = queuePhase3[i + 1]; while ((sent = inQueue3.Poll()) != null) { if ((sent = posProcessors[i].doProcess(sent)) != null) { outQueue3.Add(sent); } } } }
public void TestConstructor6() { ArrayList<String> strings = new ArrayList<String>(); for (int i = 0; i < SIZE; ++i) { strings.Add(i.ToString()); } LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(strings); for (int i = 0; i < SIZE; ++i) { Assert.AreEqual(strings.Get(i), q.Poll()); } }
public void TestAddAll5() { ArrayList<String> empty = new ArrayList<String>(); ArrayList<String> strings = new ArrayList<String>(SIZE); for (int i = 0; i < SIZE; ++i) { strings.Add(i.ToString()); } LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(SIZE); Assert.IsFalse(q.AddAll(empty)); Assert.IsTrue(q.AddAll(strings)); for (int i = 0; i < SIZE; ++i) { Assert.AreEqual(strings.Get(i), q.Poll()); } }
/// <exception cref="System.Exception"/> public virtual TestValueQueue.FillInfo GetTop() { return(fillCalls.Poll(500, TimeUnit.Milliseconds)); }