/// <summary> /// Only applicable to leaf level queues /// Parse ACLs for the queue from the configuration. /// </summary> private QueueState GetQueueState(string name, Configuration conf) { string stateVal = conf.Get(QueueManager.ToFullPropertyName(name, "state"), QueueState .Running.GetStateName()); return(QueueState.GetState(stateVal)); }
public void Shutdown(Func <Exception> pendingExceptionGenerator) { IQueueReader <T>[] array = null; lock (this.ThisLock) { if ((this.queueState == QueueState <T> .Shutdown) || (this.queueState == QueueState <T> .Closed)) { return; } this.queueState = QueueState <T> .Shutdown; if ((this.readerQueue.Count > 0) && (this.itemQueue.ItemCount == 0)) { array = new IQueueReader <T> [this.readerQueue.Count]; this.readerQueue.CopyTo(array, 0); this.readerQueue.Clear(); } } if (array != null) { for (int i = 0; i < array.Length; i++) { Exception exception = (pendingExceptionGenerator != null) ? pendingExceptionGenerator() : null; array[i].Set(new Item <T>(exception, null)); } } }
/// <summary> /// continues the execution of enqueued operations after a pause. /// </summary> public void Continue() { lock (syncobj) { if ((qs == QueueState.Pauseing) || (qs == QueueState.Paused)) { qs = QueueState.Running; QueueStateChangedInternal(this, new QueueChangedState(QueueState.Paused, QueueState.Running)); //while (currentthreads < maxthreads) { TryNewThread(); //Queuestate may have changed, so return if doing nothing //if (qs == QueueState.Idle || qs == QueueState.Paused) { return; } } } else if ((qs == QueueState.Idle) || (qs == QueueState.Running)) { /// Continuing to process while the queue is idle is meaning /// less just ignore the command return; } else if (qs == QueueState.Stopping) { ThreadErrorInternal(default(T), new ThreadStateException("Once the queue is stopping its done processing")); } } }
/// <summary> /// Enqueues a collection of items to be executed in the background. /// </summary> public Task Enqueue(IAsyncEnumerable <TItem> items, TState state, bool priority) { lock (disposeLock) { if (!disposed) { var completionSource = new TaskCompletionSource <bool>(); var queueState = new QueueState(completionSource, state); if (priority) { insert.Enqueue(items, queueState); } else { queue.Enqueue(items, queueState); } EnsureExecuting(); return(completionSource.Task); } else { return(Task.CompletedTask); } } }
private void on_queue_state_changed(QueueState new_state) { switch (new_state) { case QueueState.NotQueued: set_objects_active(QueueRelatedObjects, false); break; case QueueState.ArenaJoinable: Debug.Log("Time to join arena!!!"); break; case QueueState.AwaitingOtherPlayers: set_objects_interactable(QueueRelatedObjects, false); break; case QueueState.InArena: //What should I do here? //TODO: What was the semantics between ArenaJoinable and InArena?? break; case QueueState.Queued: set_objects_active(QueueRelatedObjects, true); set_objects_interactable(QueueRelatedObjects, true); break; case QueueState.QueuePopped: BinaryQuestion.Display("Queue popped.", "Accept?", () => answer_queue_pop(true), () => answer_queue_pop(false)); break; default: throw new Exception("Unhandled enum value " + new_state); } }
public void Shutdown() { IQueueReader <T>[] outstandingReaders = null; lock (LockObject) { if (_QueueState == QueueState.Shutdown) { return; } if (_QueueState == QueueState.Closed) { return; } this._QueueState = QueueState.Shutdown; if (_QueueReader.Count > 0 && _ItemQueue.ItemCount == 0) { outstandingReaders = new IQueueReader <T> [_QueueReader.Count]; _QueueReader.CopyTo(outstandingReaders, 0); _QueueReader.Clear(); } } if (outstandingReaders != null) { for (int i = 0; i < outstandingReaders.Length; i++) { outstandingReaders[i].Set(new ExItem <T>((Exception)null, null)); } } }
protected void Dispose(bool disposing) { if (disposing) { bool dispose = false; lock (LockObject) { if (_QueueState != QueueState.Closed) { _QueueState = QueueState.Closed; dispose = true; } if (dispose) { while (_QueueReader.Count > 0) { var reader = _QueueReader.Dequeue(); reader.Set(default(ExItem <T>)); } while (_ItemQueue.HasAnyItem) { var item = _ItemQueue.DequeueAnyItem(); item.Dispose(); invokeDequeueCallback(item.Callback); } } } } }
public ExQueue() { _ItemQueue = new ExItemQueue <T>(); _QueueReader = new Queue <IQueueReader <T> >(); _WaiterList = new List <IQueueWaiter>(); _QueueState = QueueState.Open; }
public ActionResult DetermineWaitExperience(string callsid, int QueuePosition, int CurrentQueueSize, int AvgQueueTime) { var state = QueueState.Load(callsid); // I'm just faking some metrics here that help me determine if // the caller should be given the option to play a game. // Normally I'd be using the values passed from Twilio. var waitTime = 400; // AvgQueueTime; var memberPosition = 10; // QueuePosition; if (state.PlayQuizShow && waitTime > 300 && memberPosition > 5) { state.PlayQuizShow = true; state.Save(); return(RedirectToAction("QuizShowInvitationRedirect", "QuizShow", new { CallSid = callsid })); } else { state.PlayQuizShow = false; state.Save(); return(RedirectToAction("BasicWaitExperienceRedirect", "BasicWait", new { CallSid = callsid })); } }
public FifoSchedulerInfo(ResourceManager rm) { // JAXB needs this RMContext rmContext = rm.GetRMContext(); FifoScheduler fs = (FifoScheduler)rm.GetResourceScheduler(); qName = fs.GetQueueInfo(string.Empty, false, false).GetQueueName(); QueueInfo qInfo = fs.GetQueueInfo(qName, true, true); this.usedCapacity = qInfo.GetCurrentCapacity(); this.capacity = qInfo.GetCapacity(); this.minQueueMemoryCapacity = fs.GetMinimumResourceCapability().GetMemory(); this.maxQueueMemoryCapacity = fs.GetMaximumResourceCapability().GetMemory(); this.qstate = qInfo.GetQueueState(); this.numNodes = rmContext.GetRMNodes().Count; this.usedNodeCapacity = 0; this.availNodeCapacity = 0; this.totalNodeCapacity = 0; this.numContainers = 0; foreach (RMNode ni in rmContext.GetRMNodes().Values) { SchedulerNodeReport report = fs.GetNodeReport(ni.GetNodeID()); this.usedNodeCapacity += report.GetUsedResource().GetMemory(); this.availNodeCapacity += report.GetAvailableResource().GetMemory(); this.totalNodeCapacity += ni.GetTotalCapability().GetMemory(); this.numContainers += fs.GetNodeReport(ni.GetNodeID()).GetNumContainers(); } }
public InputQueue() { itemQueue = new ItemQueue <T>(); readerQueue = new Queue <IQueueReader>(); waiterList = new List <IQueueWaiter>(); queueState = QueueState.Open; }
void IActivatedMessageQueue.OnQueueInstancesStopped() { lock (ThisLock) { this.queueState = QueueState.PendingOpen; } }
public InputQueue() { this.itemQueue = new ItemQueue(); this.readerQueue = new Queue <IQueueReader>(); this.waiterList = new List <IQueueWaiter>(); this.queueState = QueueState.Open; }
public virtual QueueState GetState(string queue) { string state = Get(GetQueuePrefix(queue) + State); return((state != null) ? QueueState.ValueOf(StringUtils.ToUpperCase(state)) : QueueState .Running); }
public void Dispose() { bool flag = false; lock (this.ThisLock) { if (this.queueState != QueueState <T> .Closed) { this.queueState = QueueState <T> .Closed; flag = true; } } if (flag) { while (this.readerQueue.Count > 0) { Item <T> item2 = new Item <T>(); this.readerQueue.Dequeue().Set(item2); } while (this.itemQueue.HasAnyItem) { Item <T> item = this.itemQueue.DequeueAnyItem(); this.DisposeItem(item); InputQueue <T> .InvokeDequeuedCallback(item.DequeuedCallback); } } }
/// <summary> /// Adds the item to the queue to process asynchronously and /// uses the different operation instead of the default. /// </summary> /// <param name="item">the item to enqueue</param> /// <param name="opp">the new operation that overrides the default</param> /// <exception cref="System.ArgumentNullException">opp is null</exception> public void EnQueue(T item, QueueOperationHandler <T> opp) { if (opp == null) { throw new ArgumentNullException("operation can not be null"); } lock (syncobj) { if (qs == QueueState.Idle) { #region idle qs = QueueState.Running; QueueStateChangedInternal(this, new QueueChangedState(QueueState.Idle, QueueState.Running)); /// the problem with generics is that sometimes the fully /// descriptive name goes on for a while KeyValuePair <T, QueueOperationHandler <T> > kvp = new KeyValuePair <T, QueueOperationHandler <T> >(item, opp); /// thread demands that its ParameterizedThreadStart take an object not a generic type /// one might have resonably thought that there would be a generic constructor that /// took a strongly typed value but there is not one currentthreads++; new Thread(new ParameterizedThreadStart(RunOpp)).Start(kvp); #endregion } else if ((qs == QueueState.Paused) || (qs == QueueState.Pauseing)) { #region pause /// in the case that we are pausing or currently paused we just add the value to the /// queue we dont try to run the process queue.Enqueue(new KeyValuePair <T, QueueOperationHandler <T> >(item, opp)); #endregion } else if (qs == QueueState.Running) { #region running /// you have to enqueue the item then try to execute the first item in the process /// always enqueue first as this ensures that you get the oldest item first since /// that is what you wanted to do you did not want a stack queue.Enqueue(new KeyValuePair <T, QueueOperationHandler <T> >(item, opp)); TryNewThread(); #endregion } else if (qs == QueueState.Stopping) { #region stopping /// when you are stopping the queue i assume that you wanted to stop it not pause it this /// means that if you try to enqueue something it will throw an exception since you /// shouldnt be enqueueing anything since when the queue gets done all its current /// threads it clears the rest out so why bother enqueueing it. at this point we have /// a choice we can make the notifyer die or we can use the error event we already /// have built in to tell the sender. i chose the later. also try to pick an appropriate /// exception not just the base ThreadErrorInternal(item, new ThreadStateException("the Queue is stopping . no processing done")); #endregion } } }
internal CapacitySchedulerQueueInfo(CSQueue q) { queuePath = q.GetQueuePath(); capacity = q.GetCapacity() * 100; usedCapacity = q.GetUsedCapacity() * 100; maxCapacity = q.GetMaximumCapacity(); if (maxCapacity < Epsilon || maxCapacity > 1f) { maxCapacity = 1f; } maxCapacity *= 100; absoluteCapacity = Cap(q.GetAbsoluteCapacity(), 0f, 1f) * 100; absoluteMaxCapacity = Cap(q.GetAbsoluteMaximumCapacity(), 0f, 1f) * 100; absoluteUsedCapacity = Cap(q.GetAbsoluteUsedCapacity(), 0f, 1f) * 100; numApplications = q.GetNumApplications(); queueName = q.GetQueueName(); state = q.GetState(); resourcesUsed = new ResourceInfo(q.GetUsedResources()); if (q is PlanQueue && !((PlanQueue)q).ShowReservationsAsQueues()) { hideReservationQueues = true; } // add labels ICollection <string> labelSet = q.GetAccessibleNodeLabels(); if (labelSet != null) { Sharpen.Collections.AddAll(nodeLabels, labelSet); nodeLabels.Sort(); } }
/// <summary> /// pauses the execution of future operations. the current operations are allowed to finish. /// </summary> public void Pause() { lock (syncobj) { if (qs == QueueState.Idle) { /// this is a judgment call if you pause this when you /// don’t have any elements in it then you can go directly /// to paused and this means that you basically want to /// keep queuing until something happens qs = QueueState.Paused; QueueStateChangedInternal(this, new QueueChangedState(QueueState.Idle, QueueState.Paused)); } else if (qs == QueueState.Running) { qs = QueueState.Pauseing; QueueStateChangedInternal(this, new QueueChangedState(QueueState.Running, QueueState.Pauseing)); /// running means you had some active threads so you couldn’t /// get to paused right away } else if (qs == QueueState.Stopping) { ThreadErrorInternal(default(T), new ThreadStateException("Once the queue is stopping its done processing")); } /// if we are already paused or pausing we dont need to do anything } }
// Don't let any more items in. Differs from Close in that we keep around // existing items in our itemQueue for possible future calls to Dequeue public void Shutdown(Func <Exception> pendingExceptionGenerator) { IQueueReader[] outstandingReaders = null; lock (ThisLock) { if (queueState == QueueState.Shutdown) { return; } if (queueState == QueueState.Closed) { return; } this.queueState = QueueState.Shutdown; if (readerQueue.Count > 0 && this.itemQueue.ItemCount == 0) { outstandingReaders = new IQueueReader[readerQueue.Count]; readerQueue.CopyTo(outstandingReaders, 0); readerQueue.Clear(); } } if (outstandingReaders != null) { for (int i = 0; i < outstandingReaders.Length; i++) { Exception exception = (pendingExceptionGenerator != null) ? pendingExceptionGenerator() : null; outstandingReaders[i].Set(new Item(exception, null)); } } }
private int StateIndex(QueueState state) { switch (state) { case QueueState.Canceled: return(3); case QueueState.Complete: return(4); case QueueState.Encoding: return(2); case QueueState.Failed: return(5); case QueueState.LogoPending: return(1); case QueueState.PreFailed: return(5); case QueueState.Queue: return(0); } return(0); }
protected void Dispose(bool disposing) { if (disposing) { var dispose = false; lock (ThisLock) { if (_queueState != QueueState.Closed) { _queueState = QueueState.Closed; dispose = true; } } if (dispose) { while (_readerQueue.Count > 0) { var reader = _readerQueue.Dequeue(); reader.Set(default(Item <T>)); } while (_itemQueue.HasAnyItem) { var item = _itemQueue.DequeueAnyItem(); item.Dispose(); InvokeDequeuedCallback(item.DequeuedCallback); } } } }
public void Dispose() { bool dispose = false; lock (ThisLock) { if (queueState != QueueState.Closed) { queueState = QueueState.Closed; dispose = true; } } if (dispose) { while (readerQueue.Count > 0) { IQueueReader reader = readerQueue.Dequeue(); reader.Set(default(Item)); } while (itemQueue.HasAnyItem) { Item item = itemQueue.DequeueAnyItem(); DisposeItem(item); InvokeDequeuedCallback(item.DequeuedCallback); } } }
public void Shutdown() { IQueueReader <T>[] outstandingReaders = null; lock (ThisLock) { if (_queueState == QueueState.Shutdown) { return; } if (_queueState == QueueState.Closed) { return; } _queueState = QueueState.Shutdown; if (_readerQueue.Count > 0 && _itemQueue.ItemCount == 0) { outstandingReaders = new IQueueReader <T> [_readerQueue.Count]; _readerQueue.CopyTo(outstandingReaders, 0); _readerQueue.Clear(); } } if (outstandingReaders != null) { for (var i = 0; i < outstandingReaders.Length; i++) { outstandingReaders[i].Set(new Item <T>((Exception)null, null)); } } }
private void UpdateSongStates(Song currentSong, QueueState queueState) { if (this.Songs != null) { foreach (var song in this.Songs) { if (currentSong != null && string.Equals(song.Metadata.ProviderSongId, currentSong.ProviderSongId, StringComparison.Ordinal)) { if (queueState == QueueState.Play) { song.State = SongState.Playing; } else if (queueState == QueueState.Paused) { song.State = SongState.Paused; } else { song.State = SongState.None; } } else { song.State = SongState.None; } } } }
public InputQueue() { _itemQueue = new ItemQueue(); _readerQueue = new Queue <IQueueReader>(); _waiterList = new List <IQueueWaiter>(); _queueState = QueueState.Open; }
public void LaunchQueueInstance() { lock (ThisLock) { if (this.queueState == QueueState.Faulted) { return; } else if (this.queueState == QueueState.OpenedPendingConnect) { // We treat this as error case. if (this.OnListenerChannelFailed()) { return; } } this.queueState = QueueState.PendingOpen; } if (this.PendingCount > 0) { EnsureListenerChannelInstanceOpened(); } }
void ThrottlingCallback(object state) { lock (ThisLock) { this.queueState = QueueState.PendingOpen; listenerChannelFailCount = 0; } }
public void Initialize() { _queueState = default(QueueState); _lastEnqueuedEventTag = default(CheckpointTag); _subscriptionPaused = false; _queuePendingEvents.Initialize(); }
/// <summary> /// Dispatch messages from the queue. This call blocks and dispatches /// until timeout has elapsed. /// </summary> public void timedDispatch(long timeout) { status = QueueState.Running; EnsurePeerCreated(); int code = NativeMethods.mamaQueue_timedDispatch(nativeHandle, (ulong)timeout); CheckResultCode(code); status = QueueState.Stopped; }
public void FillQueue() { queueState = QueueState.Filling; Thread thread = new Thread( new ThreadStart(DoFillQueue)); thread.Name = string.Format("{0} FillQueue", this); thread.Start(); }
internal ActivatedMessageQueue(ListenerAdapter listenerAdapter, App app) : base() { Debug.Print("ActivatedMessageQueue.ctor(listenerAdapter:" + listenerAdapter + " appKey:" + app.AppKey + " appPoolId:" + app.AppPool.AppPoolId + ")"); this.listenerAdapter = listenerAdapter; this.app = app; this.queueState = QueueState.PendingOpen; CreateListenerChannelContext(); }
public void Remove() { State = QueueState.Removed; }
/// <summary> /// Dispatch messages from the queue. This call blocks and dispatches /// until timeout has elapsed. /// </summary> public void timedDispatch(long timeout) { status = QueueState.Running; EnsurePeerCreated(); int code = NativeMethods.mamaQueue_timedDispatch(nativeHandle, (ulong) timeout); CheckResultCode(code); status = QueueState.Stopped; }
public QueueStateChangedEventArgs(QueueState state) { QueueState = state; }
/// <summary> /// Dispatch a single event from the specified queue. If there is no event on /// the queue simply return and do nothing. /// </summary> public void dispatchEvent () { status = QueueState.Running; EnsurePeerCreated(); int code = NativeMethods.mamaQueue_dispatchEvent(nativeHandle); CheckResultCode(code); status = QueueState.Stopped; }
/// <summary> /// Unblock the queue as soon as possible. This will cause mamaDispatchers to /// exit. Creating a new dispatcher will resume dispatching events. /// </summary> public void stopDispatch() { status = QueueState.Stopping; EnsurePeerCreated(); int code = NativeMethods.mamaQueue_stopDispatch(nativeHandle); CheckResultCode(code); while (status != QueueState.Stopped) Thread.Sleep(10); }
public void SetStopped() { _queueState = QueueState.Stopped; // unsubscribe? }
void FaultMessageQueueOnFailure() { lock (ThisLock) { this.queueState = QueueState.Faulted; // Drop pending messages. this.DropPendingMessages(true); // Throttling if (throttlingTimer == null) { throttlingTimer = new IOThreadTimer(new Action<object>(ThrottlingCallback), this, true, ThrottlingMaxSkewInMilliseconds); } throttlingTimer.Set(FailureThrottlingTimeout); } }
void EnsureListenerChannelInstanceOpened() { lock (ThisLock) { if (this.queueState != QueueState.PendingOpen) { return; } this.queueState = QueueState.OpenedPendingConnect; } if (!listenerAdapter.OpenListenerChannelInstance(this)) { FaultMessageQueueOnFailure(); } }
public void SetPaused() { _queueState = QueueState.Paused; PauseSubscription(); }
protected override void OnUnregisterCompleted() { this.queueState = QueueState.PendingOpen; }
void OnListenerChannelConnected() { lock (ThisLock) { // Clear the failure count. this.listenerChannelFailCount = 0; this.queueState = QueueState.Connected; } }
private bool ChangeState(QueueState newState) { // Do nothing if the state is closed if (_state == QueueState.Closed) { return false; } if (_state != newState) { Trace("Changed state from {0} to {1}", _state, newState); _state = newState; return true; } return false; }
public void SetRunning() { _queueState = QueueState.Running; ResumeSubscription(); }