/// <summary> /// Implementation of RBroker Interface 'submit' method /// </summary> /// <param name="task">RTask submitted to the RBroker for execution</param> /// <param name="priority">Boolean indicating this is a high priority task</param> /// <returns>RTaskToken reference</returns> /// <remarks></remarks> public RTaskToken submit(RTask task, Boolean priority) { if(Interlocked.Read(ref m_refreshingConfig) == 1) { Console.WriteLine("RTask submissions temporarily disabled while RBroker configuration refreshes."); } try { /* * We clone the incoming RTask into a new instance of * RTask to ensure RTask is unique so it can be used * as a key inside the taskTokenListenerMap. * * How could the value of RTask param not be unique? * * For example, RBrokerAppSimulator apps frequently * create a single RTask instance and submit it many times * to simulate load. */ RTask clonedTask = cloneTask(task); Boolean added = false; if(priority) { added = m_pendingHighPriorityQueue.TryAdd(clonedTask); } else { added = m_pendingLowPriorityQueue.TryAdd(clonedTask); } if(!added) { throw new Exception("Broker at capacity ( " + MAX_TASK_QUEUE_SIZE + " ), rejecting task " + clonedTask); } RTaskToken rTaskToken = new RTaskTokenImpl(task); /* * RTask now on pending[High,Low]PriorityQueue, * appending associated RTaskToken to end of * liveTaskTokens. */ m_liveTaskTokens.Add(rTaskToken); /* * Register RTask and associated RTaskToken here. * Once RTask has been submitted to Executor and * Future for task exists, we will make an * RTaskToken.onTask callback to register Future * on token. */ m_taskTokenListenerMap.TryAdd(clonedTask, rTaskToken); return rTaskToken; } catch(Exception rex) { throw new Exception("RBroker: submit failed, cause: " + rex.ToString()); } }
/// <summary> /// Implementation of RBroker Interface 'submit' method /// </summary> /// <param name="task">RTask submitted to the RBroker for execution</param> /// <param name="priority">Boolean indicating this is a high priority task</param> /// <returns>RTaskToken reference</returns> /// <remarks></remarks> public RTaskToken submit(RTask task, Boolean priority) { if (Interlocked.Read(ref m_refreshingConfig) == 1) { Console.WriteLine("RTask submissions temporarily disabled while RBroker configuration refreshes."); } try { /* * We clone the incoming RTask into a new instance of * RTask to ensure RTask is unique so it can be used * as a key inside the taskTokenListenerMap. * * How could the value of RTask param not be unique? * * For example, RBrokerAppSimulator apps frequently * create a single RTask instance and submit it many times * to simulate load. */ RTask clonedTask = cloneTask(task); Boolean added = false; if (priority) { added = m_pendingHighPriorityQueue.TryAdd(clonedTask); } else { added = m_pendingLowPriorityQueue.TryAdd(clonedTask); } if (!added) { throw new Exception("Broker at capacity ( " + MAX_TASK_QUEUE_SIZE + " ), rejecting task " + clonedTask); } RTaskToken rTaskToken = new RTaskTokenImpl(task); /* * RTask now on pending[High,Low]PriorityQueue, * appending associated RTaskToken to end of * liveTaskTokens. */ m_liveTaskTokens.Add(rTaskToken); /* * Register RTask and associated RTaskToken here. * Once RTask has been submitted to Executor and * Future for task exists, we will make an * RTaskToken.onTask callback to register Future * on token. */ m_taskTokenListenerMap.TryAdd(clonedTask, rTaskToken); return(rTaskToken); } catch (Exception rex) { throw new Exception("RBroker: submit failed, cause: " + rex.ToString()); } }