1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.gridservice.server;
30
31 import java.util.Vector;
32
33 import uk.ac.rdg.resc.jstyx.StyxException;
34 import uk.ac.rdg.resc.jstyx.server.StyxFile;
35 import uk.ac.rdg.resc.jstyx.server.StyxFileClient;
36
37 /***
38 * File that is read in order to get the exit code from the service instance.
39 * If the exit code has not yet been set, read requests will be queued and replied
40 * to when the exit code is set.
41 * @todo This class might be more generally useful - refactor?
42 *
43 * @author Jon Blower
44 * $Revision: 510 $
45 * $Date: 2005-12-01 08:26:45 +0000 (Thu, 01 Dec 2005) $
46 * $Log$
47 * Revision 1.2 2005/12/01 08:26:45 jonblower
48 * Fixed javadoc comment
49 *
50 * Revision 1.1 2005/11/14 21:31:54 jonblower
51 * Got SGSRun working for SC2005 demo
52 *
53 */
54
55 public class ExitCodeFile extends StyxFile
56 {
57
58 private String exitCode;
59 private Vector queuedRequests;
60
61 /*** Creates a new instance of ExitCodeFile */
62 public ExitCodeFile() throws StyxException
63 {
64 super("exitCode", 0444);
65 this.exitCode = null;
66 this.queuedRequests = new Vector();
67 }
68
69 public synchronized void read(StyxFileClient client, long offset, int count,
70 int tag) throws StyxException
71 {
72 if (this.exitCode != null)
73 {
74
75 this.processAndReplyRead(this.exitCode, client, offset, count, tag);
76 }
77 else
78 {
79
80 DataRequest dr = new DataRequest(client, offset, count, tag);
81 synchronized(this.queuedRequests)
82 {
83 this.queuedRequests.add(dr);
84 }
85 }
86 }
87
88 /***
89 * Sets the exit code. When this is called, all waiting clients will be notified
90 * of the new exit code.
91 */
92 public synchronized void setExitCode(int exitCode)
93 {
94 this.exitCode = "" + exitCode;
95 synchronized(this.queuedRequests)
96 {
97 for (int i = 0; i < this.queuedRequests.size(); i++)
98 {
99 DataRequest dr = (DataRequest)this.queuedRequests.get(i);
100 this.processAndReplyRead(this.exitCode, dr.client, dr.offset,
101 dr.count, dr.tag);
102 }
103 }
104 }
105
106 /***
107 * Class representing a request for data that we have enqueued
108 */
109 private static class DataRequest
110 {
111 private StyxFileClient client;
112 private int tag;
113 private long offset;
114 private int count;
115
116 private DataRequest(StyxFileClient client, long offset, int count, int tag)
117 {
118 this.client = client;
119 this.tag = tag;
120 this.offset = offset;
121 this.count = count;
122 }
123 }
124
125 }