/// <summary>Print the specified job event to the console.</summary> /// <param name="jobEvent">the job event to print</param> /// <param name="type">the type of event</param> public void WriteEvent(JobEvent jobEvent, string type) { JPPFJob job = jobEvent.getJob(); java.util.List tasks = jobEvent.getJobTasks(); Console.WriteLine("[.Net] Job '" + job.getName() + "' " + type + (tasks != null ? " with " + tasks.size() + " tasks" : "")); }
/// <summary>Add a .Net task to the specified job. The .Net task is serialized and the resulting byte[] is /// held by the returned <c>DotnetTaskWrapper</c> instance on the Java side. /// <para>This is a method extension to the JPPFJob proxy class generated by jni4net.</para></summary> /// <param name="job">The job to add the task to</param> /// <param name="task">The task to add</param> /// <param name="loggingEnabled">Whether the Java wrapper for this task will print messages to the console during its execution</param> /// <returns>A <c>Task</c> instance</returns> public static Task add(this JPPFJob job, BaseDotnetTask task, bool loggingEnabled) { DotnetSerializer ser = new DotnetSerializer(); byte[] bytes = ser.Serialize(task); DotnetTaskWrapper dtw = new DotnetTaskWrapper(bytes); if (task.TimeoutSchedule != null) { dtw.setTimeoutSchedule(task.TimeoutSchedule); } dtw.setLoggingEnabled(loggingEnabled); return(job.add(dtw)); }
/// <summary>Add a .Net job listener to the specified job.</summary> /// <param name="job">The job to add the listener to</param> /// <param name="listener">The listener to add</param> public static void addJobListener(this JPPFJob job, BaseDotnetJobListener listener) { //Console.WriteLine("adding job listener " + listener); job.addJobListener(new DotnetJobListenerWrapper(new DotnetJobEventDispatcher(listener))); }
/// <summary>Add a .Net task to the specified job. The .Net task is serialized and the resulting byte[] is /// held by the returned <c>DotnetTaskWrapper</c> instance. /// <para>This is a method extension to the JPPFJob proxy class generated by jni4net.</para></summary> /// <param name="job">The job to add the task to</param> /// <param name="task">The task to add</param> /// <returns>A <c>Task</c> instance</returns> public static Task add(this JPPFJob job, BaseDotnetTask task) { return(job.add(task, false)); }
static void Main(string[] args) { JPPFClient client = null; TopologyManager manager = null; JobMonitor jobMonitor = null; try { // initialize the .Net bridge with verbose/quiet mode JPPFDotnet.Init(false); // initialize a topology manager and register a listener for topology events manager = new DotnetTopologyManager(new MyTopologyListener()); // initialize a topology manager and register a listener for topology events jobMonitor = new DotnetJobMonitor(manager, new MyJobMonitoringListener()); // wait until the topology manager and job monitor are fully initialized while (jobMonitor.getJobDrivers().size() <= 0) { Thread.Sleep(10); } JobDriver jobDriver = jobMonitor.getJobDrivers().get(0) as JobDriver; while (jobDriver.getTopologyDriver().getChildCount() <= 0) { Thread.Sleep(10); } // initialize the JPPF client client = manager.getJPPFClient(); // print the number of nodes connected to the server PrintNbNodes(client); // provision a slave node for each .Net-capable master node //ProvisionNodes(client, 1); // subscribe to job notifications emitted by the JPPF server //RegisterJobNotificationListener(client); // subscribe to task completion notifications emitted by the JPPF nodes RegisterTaskNotificationListener(client); // uncomment to test an executor service //SubmitWithExecutor(client); // uncomment to test a completion service //SubmitWithCompletionService(client); JPPFJob job = new JPPFJob(); job.setName(".NET job"); // execute the job only on nodes which successfully initialized the .Net bridge job.getSLA().setExecutionPolicy(new Equal("jppf.dotnet.bridge.initialized", true)); int n = 5; for (int i = 0; i < n; i++) { job.add(new MyDotnetTask(1000)).setId("task " + (i + 1)); } MyDotnetTask myTask = new MyDotnetTask(3000); // this .Net task will time out after 1.5 second myTask.TimeoutSchedule = new JPPFSchedule(1500); job.add(myTask).setId("task " + (n + 1)); // alternatively: job.add(new MyDotnetTask(3000)).setTimeoutSchedule(new JPPFSchedule(1500)); // add a job listner that prints job events to the console job.addJobListener(new MyJobListener()); Console.WriteLine("created job"); // submit the job to the grid and get the execution results java.util.List results = client.submitJob(job); Console.WriteLine("got job results"); for (int i = 0; i < results.size(); i++) { Task task = (Task)results.get(i); //BaseDotnetTask dotnetTask = job.asBaseDotnetTask(task); BaseDotnetTask dotnetTask = task.AsBaseDotnetTask(); if (dotnetTask != null) // if .Net task { if (dotnetTask.Exception != null) { Console.WriteLine("got exception for task " + dotnetTask + " : " + dotnetTask.Exception); Console.WriteLine(dotnetTask.Exception.StackTrace); } else if (dotnetTask.Result != null) { Console.WriteLine("got result for task " + dotnetTask + " : " + dotnetTask.Result); } else { Console.WriteLine("no result or exception for task " + dotnetTask); } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } if (!Console.IsInputRedirected && !Console.IsOutputRedirected) { Console.WriteLine("Please press ESC to terminate"); do { while (!Console.KeyAvailable) { } } while (Console.ReadKey(true).Key != ConsoleKey.Escape); } else { Console.WriteLine("Waiting 5 seconds ..."); Thread.Sleep(5000); } if (client != null) { client.close(); } }