static public void Execute()
        {
            try {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT);
                RBroker rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);

                /*
                 * 2. Register RTaskListener for asynchronous
                 * notifications on RTask completion.
                 */

                SampleTaskBrokerListener sampleListeners = new SampleTaskBrokerListener(rBroker);

                rBroker.addTaskListener(sampleListeners);
                rBroker.addBrokerListener(sampleListeners);


                /*
                 * 3. Define RTask
                 *
                 * This example creates a DiscreteTask that will
                 * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp.
                 */

                RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                        Program.TUTORIAL_REPO_DIRECTORY,
                                                        Program.TUTORIAL_REPO_OWNER,
                                                        "",
                                                        null);

                /*
                 * 4. Submit RTask to RBroker for execution.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 *
                 * However, in this example we are going to allow
                 * the RTaskListener handle the result so
                 * there is nothing further for us to do here after
                 * we submit the RTask.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("DiscreteProfiling: submitted " + rTask +
                                  " for execution on RBroker.");
            }
            catch (Exception tex)
            {
                Console.WriteLine("DiscreteProfiling: ex=" + tex.ToString());
            }
        }
        /*
         * RTaskAppSimulator method.
         */

        public void simulateApp(RBroker rBroker)
        {
            /*
             * 1. Prepare RTask(s) for simulation.
             *
             * In the example we will simply simulate the execution
             * a fixed number of RTask.
             *
             * Note, this is a somewhat artificial demo as we are
             * executing the same RTask SIMULATE_TOTAL_TASK_COUNT
             * times. You can experiment by modifying the
             * implementation to execute a range of RTask of
             * your own choosing.
             */

            RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                    Program.TUTORIAL_REPO_DIRECTORY,
                                                    Program.TUTORIAL_REPO_OWNER,
                                                    "",
                                                    null);

            /*
             * 2. Loop submitting SIMULATE_TOTAL_TASK_COUNT
             * task(s) to RBroker for execution.
             */

            simulationStartTime = System.Environment.TickCount;

            for (int tasksPushedToBroker = 0;
                 tasksPushedToBroker < SIMULATE_TOTAL_TASK_COUNT;
                 tasksPushedToBroker++)
            {
                try
                {
                    RTaskToken taskToken = rBroker.submit(rTask);
                    Console.WriteLine("simulateApp: submitted task " +
                                      rTask + " for execution on RBroker.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("simulateApp: ex=" + ex.ToString());
                }
            }
        }
Exemple #3
0
        static public void Execute()
        {
            RBroker rBroker = null;

            try
            {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT);
                rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);


                /*
                 * 2. Define RTask
                 *
                 * This example creates a DiscreteTask that will
                 * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp.
                 */

                RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                        Program.TUTORIAL_REPO_DIRECTORY,
                                                        Program.TUTORIAL_REPO_OWNER,
                                                        "",
                                                        null);


                /*
                 * 3. Submit RTask to RBroker for execution.
                 *
                 * Note, unlike an RClient.executeScript call or
                 * an RProject.executeScript call the RBroker.submit
                 * call is non-blocking.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("DiscreteBlocking: submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Demonstrate blocking for an RTask result.
                 *
                 * The call to getResult() will either return
                 * an RTaskResult or raise an Exception. An Exception
                 * indicates the RTask failed to complete and why.
                 */

                RTaskResult rTaskResult = rTaskToken.getResult();

                Console.WriteLine("DiscreteBlocking: " + rTask + " completed, result=" + rTaskResult.getTimeOnCall());
            } catch (Exception tex)
            {
                Console.WriteLine("DiscreteBlocking: error=" + tex.ToString());
            }
            finally
            {
                /*
                 * Final Step: Shutdown RBroker to release
                 * all associated resources, connections.
                 */
                if (rBroker != null)
                {
                    rBroker.shutdown();
                    Console.WriteLine("DiscreteBlocking: rBroker has been shutdown.");
                }
            }
        }