Beispiel #1
0
        /// <summary>Submit tasks using a JPPFExecutorService</summary>
        /// <param name="client">The JPPF client connected to the server</param>
        public static void SubmitWithExecutor(JPPFClient client)
        {
            JPPFExecutorService executor = new JPPFExecutorService(client);

            // send tasks 1 at a time
            executor.setBatchSize(1);
            IList <Future> futures = new List <Future>();

            for (int i = 0; i < 3; i++)
            {
                futures.Add(executor.Submit(new MyDotnetTask(100)));
            }
            // process the results in the order the tasks were submitted
            foreach (Future future in futures)
            {
                // future.get() returns the value of myTask.Result after execution
                // or throws an eventual exception that was raised
                try {
                    object result = future.get();
                    if (result != null)
                    {
                        Console.WriteLine("[executor service] got result = " + result);
                    }
                    else
                    {
                        Console.WriteLine("[executor service] no result or exception");
                    }
                } catch (Exception e) {
                    Console.WriteLine("[executor service] exception during execution: " + e.ToString());
                }
            }
            executor.shutdownNow();
        }
Beispiel #2
0
        /// <summary>Submit a .Net task to the specified executor service</summary>
        /// <param name="executor">The executor service to submit the task to</param>
        /// <param name="task">The task to submit</param>
        /// <returns>A <c>Future</c> instance</returns>
        public static Future Submit(this JPPFExecutorService executor, BaseDotnetTask task)
        {
            DotnetSerializer ser = new DotnetSerializer();

            byte[]            bytes = ser.Serialize(task);
            DotnetTaskWrapper dtw   = new DotnetTaskWrapper(bytes);

            //if (task.TimeoutSchedule != null) dtw.setTimeoutSchedule(task.TimeoutSchedule);
            dtw.setLoggingEnabled(false);
            return(executor.submit(dtw));
        }
Beispiel #3
0
        /// <summary>Submit tasks using a JPPFCompletionService</summary>
        /// <param name="client">The JPPF client connected to the server</param>
        public static void SubmitWithCompletionService(JPPFClient client)
        {
            JPPFExecutorService   executor          = new JPPFExecutorService(client);
            JPPFCompletionService completionService = new JPPFCompletionService(executor);

            // send tasks 3 at a time
            executor.setBatchSize(3);
            for (int i = 0; i < 3; i++)
            {
                completionService.Submit(new MyDotnetTask(100));
            }
            // process the results in the order in which they arrive
            int count = 0;

            while (count < 3)
            {
                // get the next completed task
                Future future = completionService.poll();
                count++;
                // future.get() returns the value of myTask.Result after execution
                // or throws an eventual exception that was raised
                try {
                    object result = future.get();
                    if (result != null)
                    {
                        Console.WriteLine("[executor service] got result = " + result);
                    }
                    else
                    {
                        Console.WriteLine("[executor service] no result or exception");
                    }
                } catch (Exception e) {
                    Console.WriteLine("[executor service] exception during execution: " + e.ToString());
                }
            }
            executor.shutdownNow();
        }