From d9ed1de9c5fc37c90e8277e0fd736b489f630962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20G=C3=A9rard?= Date: Mon, 7 Feb 2011 14:25:57 +0100 Subject: [PATCH] java exemple --- test/async/Wanted_Normalized_movie.java | 106 ++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/async/Wanted_Normalized_movie.java diff --git a/test/async/Wanted_Normalized_movie.java b/test/async/Wanted_Normalized_movie.java new file mode 100644 index 0000000..650ea73 --- /dev/null +++ b/test/async/Wanted_Normalized_movie.java @@ -0,0 +1,106 @@ +package pipline_b; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public class Wanted_Normalized_movie { + protected final int N;; + protected Async_mean_factory mean_factory;; + protected Substr[] substr_inst;; + protected Future v;; + protected boolean v_2;; + protected int[] v_4;; + protected boolean v_5;; + + + + public Wanted_Normalized_movie (int N) { + this.mean_factory = new Async_mean_factory(N); + this.substr_inst = new Substr[N]; + for (int i_3 = 0; i_3 m = null; + if (this.v_2) { v_3 = 0; } + else { v_3 = this.v.get(); }; + if (this.v_5) { v_6 = i; } + else { v_6 = this.v_4; }; + this.v_5 = false; + trash = v_3; + for (int i_2 = 0; i_2 out = substr_inst[i_2].step(v_6[i_2], trash); + im[i_2] = out.c0; + trash = out.c1; + }; + this.v_2 = false; + m = mean_factory.step(i); + this.v_4 = i; + this.v = m; + return im; + } + + + //params, class, step_result_type, step_args + public class Async_mean_factory { + Mean mean_inst; + int N; + Future result; + + public Async_mean_factory(int N) { + this.N = N; + this.mean_inst = new Mean(N); + } + + public void reset () { + this.mean_inst = new Mean(N); + this.result = null; + } + + public Future step(int[] i) { + if (null != result) // Wait for the last result to be completed, null if nothing to wait for. + try { + result.get(); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (ExecutionException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + result = jeptagon.Pervasives.executor_cached.submit(new Async_mean_step(mean_inst, i)); + return result; + } + + class Async_mean_step implements Callable{ + int[] i; + Mean mean_inst; + public Async_mean_step(Mean mean_inst, int[] i) { + this.i = i; + this.mean_inst = mean_inst; + } + public Integer call () { + return mean_inst.step(i); + } + } + + + + } + + + + public static void main() { + + } + + public void reset () { + this.v_5 = true; + this.v_2 = true; + } +} \ No newline at end of file