113 |
ServerSocket service; |
ServerSocket service; |
114 |
|
|
115 |
/** |
/** |
116 |
|
* True if the serving node must shutdown due |
117 |
|
* call of the close_now(). |
118 |
|
*/ |
119 |
|
boolean terminated; |
120 |
|
|
121 |
|
/** |
122 |
* Create a new portServer, serving on specific port. |
* Create a new portServer, serving on specific port. |
123 |
*/ |
*/ |
124 |
portServer(int _port) |
portServer(int _port) |
133 |
*/ |
*/ |
134 |
public void run() |
public void run() |
135 |
{ |
{ |
|
boolean terminated; |
|
|
|
|
136 |
try |
try |
137 |
{ |
{ |
138 |
service = new ServerSocket(s_port); |
service = new ServerSocket(s_port); |
150 |
} |
} |
151 |
catch (SocketException ex) |
catch (SocketException ex) |
152 |
{ |
{ |
153 |
// Thrown when the service is closed by |
// May be thrown when the service is closed by |
154 |
// the close_now(). |
// the close_now(). |
155 |
return; |
if (terminated) |
156 |
|
return; |
157 |
} |
} |
158 |
catch (IOException iex) |
catch (Exception iex) |
159 |
{ |
{ |
160 |
// Wait 5 seconds. Do not terminate the |
// Wait 5 seconds. Do not terminate the |
161 |
// service due potentially transient error. |
// service due potentially transient error. |
177 |
{ |
{ |
178 |
try |
try |
179 |
{ |
{ |
180 |
|
terminated = true; |
181 |
service.close(); |
service.close(); |
182 |
} |
} |
183 |
catch (Exception ex) |
catch (Exception ex) |
223 |
public static final String NAME_SERVICE = "NameService"; |
public static final String NAME_SERVICE = "NameService"; |
224 |
|
|
225 |
/** |
/** |
226 |
|
* The if the client has once opened a socket, it should start sending |
227 |
|
* the message header in a given time. Otherwise the server will close the |
228 |
|
* socket. This prevents server hang when the client opens the socket, |
229 |
|
* but does not send any message, usually due crash on the client side. |
230 |
|
*/ |
231 |
|
public static String START_READING_MESSAGE = |
232 |
|
"gnu.classpath.CORBA.TOUT_START_READING_MESSAGE"; |
233 |
|
|
234 |
|
/** |
235 |
|
* If the client has started to send the request message, the socket time |
236 |
|
* out changes to the specified value. |
237 |
|
*/ |
238 |
|
public static String WHILE_READING = |
239 |
|
"gnu.classpath.CORBA.TOUT_WHILE_READING"; |
240 |
|
|
241 |
|
/** |
242 |
|
* If the message body is received, the time out changes to the |
243 |
|
* specifice value. This must be longer, as includes time, required to |
244 |
|
* process the received task. We make it 40 minutes. |
245 |
|
*/ |
246 |
|
public static String AFTER_RECEIVING = |
247 |
|
"gnu.classpath.CORBA.TOUT_AFTER_RECEIVING"; |
248 |
|
|
249 |
|
/** |
250 |
* The address of the local host. |
* The address of the local host. |
251 |
*/ |
*/ |
252 |
public final String LOCAL_HOST; |
public final String LOCAL_HOST; |
253 |
|
|
254 |
/** |
/** |
255 |
|
* The if the client has once opened a socket, it should start sending |
256 |
|
* the message header in a given time. Otherwise the server will close the |
257 |
|
* socket. This prevents server hang when the client opens the socket, |
258 |
|
* but does not send any message, usually due crash on the client side. |
259 |
|
*/ |
260 |
|
private int TOUT_START_READING_MESSAGE = 20*1000; |
261 |
|
// (Here and below, we use * to make meaning of the constant clearler). |
262 |
|
|
263 |
|
/** |
264 |
|
* If the client has started to send the request message, the socket time |
265 |
|
* out changes to the specified value. |
266 |
|
*/ |
267 |
|
private int TOUT_WHILE_READING = 2*60*1000; |
268 |
|
|
269 |
|
/** |
270 |
|
* If the message body is received, the time out changes to the |
271 |
|
* specifice value. This must be longer, as includes time, required to |
272 |
|
* process the received task. We make it 40 minutes. |
273 |
|
*/ |
274 |
|
private int TOUT_AFTER_RECEIVING = 40*60*1000; |
275 |
|
|
276 |
|
/** |
277 |
* The map of the already conncted objects. |
* The map of the already conncted objects. |
278 |
*/ |
*/ |
279 |
protected final Connected_objects connected_objects = new Connected_objects(); |
protected final Connected_objects connected_objects = new Connected_objects(); |
872 |
if (para [ i ] [ 0 ].equals(NS_HOST)) |
if (para [ i ] [ 0 ].equals(NS_HOST)) |
873 |
ns_host = para [ i ] [ 1 ]; |
ns_host = para [ i ] [ 1 ]; |
874 |
|
|
875 |
|
if (para [ i ] [ 0 ].equals(START_READING_MESSAGE)) |
876 |
|
TOUT_START_READING_MESSAGE = Integer.parseInt(para [ i ] [ 1 ]); |
877 |
|
|
878 |
|
if (para [ i ] [ 0 ].equals(WHILE_READING)) |
879 |
|
TOUT_WHILE_READING = Integer.parseInt(para [ i ] [ 1 ]); |
880 |
|
|
881 |
|
if (para [ i ] [ 0 ].equals(AFTER_RECEIVING)) |
882 |
|
TOUT_AFTER_RECEIVING = Integer.parseInt(para [ i ] [ 1 ]); |
883 |
|
|
884 |
try |
try |
885 |
{ |
{ |
886 |
if (para [ i ] [ 0 ].equals(NS_PORT)) |
if (para [ i ] [ 0 ].equals(NS_PORT)) |
1077 |
try |
try |
1078 |
{ |
{ |
1079 |
service = serverSocket.accept(); |
service = serverSocket.accept(); |
|
service.setKeepAlive(true); |
|
|
|
|
1080 |
InputStream in = service.getInputStream(); |
InputStream in = service.getInputStream(); |
1081 |
|
service.setSoTimeout(TOUT_START_READING_MESSAGE); |
1082 |
|
|
1083 |
MessageHeader msh_request = new MessageHeader(); |
MessageHeader msh_request = new MessageHeader(); |
1084 |
msh_request.read(in); |
msh_request.read(in); |
1091 |
{ |
{ |
1092 |
OutputStream out = service.getOutputStream(); |
OutputStream out = service.getOutputStream(); |
1093 |
new ErrorMessage(max_version).write(out); |
new ErrorMessage(max_version).write(out); |
|
service.close(); |
|
1094 |
return; |
return; |
1095 |
} |
} |
1096 |
|
|
1098 |
|
|
1099 |
int n = 0; |
int n = 0; |
1100 |
|
|
1101 |
|
service.setSoTimeout(TOUT_WHILE_READING); |
1102 |
|
|
1103 |
reading: |
reading: |
1104 |
while (n < r.length) |
while (n < r.length) |
1105 |
{ |
{ |
1106 |
n = in.read(r, n, r.length - n); |
n = in.read(r, n, r.length - n); |
1107 |
} |
} |
1108 |
|
|
1109 |
|
service.shutdownInput(); |
1110 |
|
|
1111 |
|
service.setSoTimeout(TOUT_AFTER_RECEIVING); |
1112 |
|
|
1113 |
if (msh_request.message_type == MessageHeader.REQUEST) |
if (msh_request.message_type == MessageHeader.REQUEST) |
1114 |
{ |
{ |
1115 |
RequestHeader rh_request; |
RequestHeader rh_request; |
1205 |
{ |
{ |
1206 |
if (props.containsKey(NS_PORT)) |
if (props.containsKey(NS_PORT)) |
1207 |
ns_port = Integer.parseInt(props.getProperty(NS_PORT)); |
ns_port = Integer.parseInt(props.getProperty(NS_PORT)); |
1208 |
|
|
1209 |
|
if (props.containsKey(START_READING_MESSAGE)) |
1210 |
|
TOUT_START_READING_MESSAGE = |
1211 |
|
Integer.parseInt(props.getProperty(START_READING_MESSAGE)); |
1212 |
|
|
1213 |
|
if (props.containsKey(WHILE_READING)) |
1214 |
|
TOUT_WHILE_READING = |
1215 |
|
Integer.parseInt(props.getProperty(WHILE_READING)); |
1216 |
|
|
1217 |
|
if (props.containsKey(AFTER_RECEIVING)) |
1218 |
|
TOUT_AFTER_RECEIVING = |
1219 |
|
Integer.parseInt(props.getProperty(AFTER_RECEIVING)); |
1220 |
} |
} |
1221 |
catch (NumberFormatException ex) |
catch (NumberFormatException ex) |
1222 |
{ |
{ |