1
2
3
4
5
6
7
8
9
10
11 package pt.digitalis.sampleApp.iss;
12
13 import pt.digitalis.iss.IProcess;
14 import pt.digitalis.iss.ISS;
15 import pt.digitalis.iss.ProcessResults;
16 import pt.digitalis.iss.ProcessState;
17 import pt.digitalis.iss.ServiceRequest;
18
19
20
21
22
23
24
25
26
27 public class myProcessCaller extends Thread {
28
29
30 private ISS theISS;
31
32
33 String id = "";
34
35
36 ServiceRequest req;
37
38
39 IProcess theProcess;
40
41
42 ProcessResults results;
43
44
45
46
47
48
49
50
51
52
53
54 public myProcessCaller(IProcess theProcess, ISS theISS, String id) {
55 super("myProcessCaller-" + id);
56 this.theProcess = theProcess;
57 this.theISS = theISS;
58 this.id = id;
59 }
60
61
62
63
64
65
66 public ServiceRequest getRequest() {
67 return this.req;
68 }
69
70
71
72
73
74
75 public void run() {
76 try {
77 if (theISS == null) {
78
79
80 results = theProcess.execute();
81
82 } else {
83
84
85 this.req = theISS.delegate(this.theProcess, this.id);
86
87 while (req.getState() != ProcessState.FINISHED
88 && req.getState() != ProcessState.ERROR) {
89 try {
90 synchronized (this) {
91
92 wait(500);
93 }
94 } catch (InterruptedException e) {
95 e.printStackTrace();
96 }
97
98 req = theISS.fetchResults(id);
99 }
100
101 results = new ProcessResults();
102 results.setResults(req.getResults());
103 }
104
105 } catch (OutOfMemoryError e) {
106 System.out
107 .println("Process #"
108 + id
109 + ": Out of memory! Releasing failed process objects from RAM...");
110
111 req = null;
112 results = null;
113 }
114 }
115
116
117
118
119 public ProcessResults getResults() {
120 return results;
121 }
122
123
124
125
126 public IProcess getTheProcess() {
127 return theProcess;
128 }
129 }