/// <summary>
        /// Constructor for specifying a Background Instance of RBroker
        /// </summary>
        /// <param name="brokerConfig">Background Broker Configuration object</param>
        /// <remarks></remarks>
        public BackgroundTaskBroker(BackgroundBrokerConfig brokerConfig)
            : base((RBrokerConfig) brokerConfig)
        {
            m_rClient = RClientFactory.createClient(brokerConfig.deployrEndpoint);

            m_rUser = m_rClient.login(brokerConfig.userCredentials);

            /*
             * Prep the base RBrokerEngine.
             */

            initEngine(PARALLEL_TASK_LIMIT);

            /*
             * Initialize the resourceTokenPool with Integer
             * based resourceTokens.
             */
            for(int i=0; i< PARALLEL_TASK_LIMIT; i++)
            {
                m_resourceTokenPool.TryAdd(i);
            }
        }
Example #2
0
        /// <summary>
        /// Constructor for specifying a Background Instance of RBroker
        /// </summary>
        /// <param name="brokerConfig">Background Broker Configuration object</param>
        /// <remarks></remarks>
        public BackgroundTaskBroker(BackgroundBrokerConfig brokerConfig)
            : base((RBrokerConfig)brokerConfig)
        {
            m_rClient = RClientFactory.createClient(brokerConfig.deployrEndpoint);

            m_rUser = m_rClient.login(brokerConfig.userCredentials);

            /*
             * Prep the base RBrokerEngine.
             */

            initEngine(PARALLEL_TASK_LIMIT);

            /*
             * Initialize the resourceTokenPool with Integer
             * based resourceTokens.
             */
            for (int i = 0; i < PARALLEL_TASK_LIMIT; i++)
            {
                m_resourceTokenPool.TryAdd(i);
            }
        }
 /// <summary>
 /// Utility function for creating a Background Instance of RBroker
 /// </summary>
 /// <param name="brokerConfig">Background Broker Configuration object</param>
 /// <returns>BackgroundTaskBroker instance</returns>
 /// <remarks></remarks>
 public static RBroker backgroundTaskBroker(BackgroundBrokerConfig brokerConfig)
 {
     return new BackgroundTaskBroker(brokerConfig);
 }
        public static void Execute()
        {
            try
            {

                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a BackgroundTaskBroker.
                 */

                RAuthentication rAuth = new RBasicAuthentication(Program.AUTH_USER_NAME, Program.AUTH_PASSWORD);

                BackgroundBrokerConfig brokerConfig = new BackgroundBrokerConfig(Program.DEPLOYR_ENDPOINT, rAuth);
                RBroker rBroker = RBrokerFactory.backgroundTaskBroker(brokerConfig);

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

                BackgroundTaskListener myTaskListener = new BackgroundTaskListener(rBroker);

                rBroker.addTaskListener(myTaskListener);

                /*
                 * 3. Define RTask
                 *
                 * This example creates a BackgroundTask that will
                 * execute an artibrary block of R code.
                 */

                String rCode = "x <- rnorm(100)";
                RTask rTask = RTaskFactory.backgroundTask("Example Background RTask",
                                                            "Example background RTask.",
                                                            rCode,
                                                            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("Submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();

            }
            catch(Exception tex)
            {
                Console.WriteLine("Runtime exception=" + tex.ToString());
            }
        }
 /// <summary>
 /// Utility function for creating a Background Instance of RBroker
 /// </summary>
 /// <param name="brokerConfig">Background Broker Configuration object</param>
 /// <returns>BackgroundTaskBroker instance</returns>
 /// <remarks></remarks>
 public static RBroker backgroundTaskBroker(BackgroundBrokerConfig brokerConfig)
 {
     return(new BackgroundTaskBroker(brokerConfig));
 }