27
27
*/
28
28
public class SimplePipeHelper {
29
29
30
- static interface IPipeThrough {
30
+ public static interface IPipeThrough {
31
31
public void helpThrough (SimplePipeRunnable pipe , SimpleSerializable [] objs );
32
32
}
33
33
34
- static interface IPipeClosing {
34
+ public static interface IPipeClosing {
35
35
public void helpClosing (SimplePipeRunnable pipe );
36
36
}
37
37
@@ -123,7 +123,7 @@ static String nextPipeKey() {
123
123
@ J2SNative ({
124
124
"delete net.sf.j2s.ajax.SimplePipeHelper.pipes[key];"
125
125
})
126
- static void removePipe (String key ) {
126
+ public static void removePipe (String key ) {
127
127
if (key == null ) {
128
128
System .out .println ("Removing pipe for null key???" );
129
129
return ;
@@ -155,15 +155,15 @@ public static SimplePipeRunnable getPipe(String key) {
155
155
}
156
156
157
157
@ J2SIgnore
158
- static List <SimpleSerializable > getPipeDataList (String key ) {
158
+ public static List <SimpleSerializable > getPipeDataList (String key ) {
159
159
if (pipeMap == null ) {
160
160
return null ;
161
161
}
162
162
return pipeMap .get (key );
163
163
}
164
164
165
165
@ J2SIgnore
166
- static void pipeIn (String key , SimpleSerializable [] ss ) {
166
+ public static void pipeIn (String key , SimpleSerializable [] ss ) {
167
167
SimplePipeRunnable pipe = getPipe (key );
168
168
List <SimpleSerializable > list = getPipeDataList (key );
169
169
if (pipe == null || list == null ) {
@@ -180,7 +180,7 @@ static void pipeIn(String key, SimpleSerializable[] ss) {
180
180
}
181
181
182
182
@ J2SIgnore
183
- static boolean isPipeLive (String key ) {
183
+ public static boolean isPipeLive (String key ) {
184
184
SimplePipeRunnable pipe = getPipe (key );
185
185
if (pipe != null ) {
186
186
return pipe .isPipeLive ();
@@ -189,7 +189,7 @@ static boolean isPipeLive(String key) {
189
189
}
190
190
191
191
@ J2SIgnore
192
- static boolean notifyPipeStatus (String key , boolean live ) {
192
+ public static boolean notifyPipeStatus (String key , boolean live ) {
193
193
SimplePipeRunnable pipe = getPipe (key );
194
194
if (pipe != null && pipe .isPipeLive ()) {
195
195
pipe .updateStatus (live );
@@ -199,7 +199,7 @@ static boolean notifyPipeStatus(String key, boolean live) {
199
199
}
200
200
201
201
@ J2SIgnore
202
- public static void helpClosing (SimplePipeRunnable pipe ) {
202
+ static void helpClosing (SimplePipeRunnable pipe ) {
203
203
if (pipe .closer != null ) {
204
204
pipe .closer .helpClosing (pipe );
205
205
} else {
@@ -208,37 +208,79 @@ public static void helpClosing(SimplePipeRunnable pipe) {
208
208
}
209
209
210
210
@ J2SIgnore
211
- public static void printStatistics () {
211
+ public static String printStatistics2 () {
212
+ StringBuffer buffer = new StringBuffer ();
213
+ buffer .append ("Pipe monitor<br />\r \n " );
212
214
if (pipes != null ) {
213
- System . out . println ("Totoal pipe count: " + pipes .size ());
214
- System . out . println ("Totoal pipe map count: " + pipeMap .size ());
215
+ buffer . append ("Totoal pipe count: " + pipes .size () + "<br /> \r \n " );
216
+ buffer . append ("Totoal pipe map count: " + pipeMap .size () + "<br /> \r \n " );
215
217
Object [] keys = pipeMap .keySet ().toArray ();
216
218
for (int i = 0 ; i < keys .length ; i ++) {
217
219
String key = (String ) keys [i ];
218
220
List <SimpleSerializable > list = pipeMap .get (key );
219
221
SimplePipeRunnable p = pipes .get (key );
220
222
if (p instanceof CompoundPipeRunnable ) {
221
223
CompoundPipeRunnable cp = (CompoundPipeRunnable ) p ;
222
- System .out .println (i + "Pipe " + cp .pipeKey + " status=" + cp .status + " pipeAlive=" + cp .isPipeLive () + " created=" + new Date (cp .lastSetup ));
224
+ int activeCount = 0 ;
225
+ for (int j = 0 ; j < cp .pipes .length ; j ++) {
226
+ if (cp .pipes [j ] != null ) {
227
+ activeCount ++;
228
+ }
229
+ }
230
+ if (activeCount > 2 ) {
231
+ buffer .append (i + " Pipe (active=" + activeCount + ") " + cp .pipeKey + " status=" + cp .status + " pipeAlive=" + cp .isPipeLive () + " created=" + new Date (cp .lastSetup ) + "<br />\r \n " );
232
+ }
233
+ }
234
+ if (list != null ) {
235
+ int size = list .size ();
236
+ if (size > 20 ) {
237
+ if (p != null ) {
238
+ buffer .append (i + "::: pipe " + p .pipeKey + " size : " + size + " / " + p .pipeAlive + "<br />\r \n " );
239
+ } else {
240
+ buffer .append ("Error pipe " + key + " with size : " + size + "<br />\r \n " );
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ return buffer .toString ();
247
+ }
248
+
249
+ @ J2SIgnore
250
+ public static String printStatistics () {
251
+ StringBuffer buffer = new StringBuffer ();
252
+ buffer .append ("Pipe monitor<br />\r \n " );
253
+ if (pipes != null ) {
254
+ buffer .append ("Totoal pipe count: " + pipes .size () + "<br />\r \n " );
255
+ buffer .append ("Totoal pipe map count: " + pipeMap .size () + "<br />\r \n " );
256
+ Object [] keys = pipeMap .keySet ().toArray ();
257
+ for (int i = 0 ; i < keys .length ; i ++) {
258
+ String key = (String ) keys [i ];
259
+ List <SimpleSerializable > list = pipeMap .get (key );
260
+ SimplePipeRunnable p = pipes .get (key );
261
+ if (p instanceof CompoundPipeRunnable ) {
262
+ CompoundPipeRunnable cp = (CompoundPipeRunnable ) p ;
263
+ buffer .append (i + "Pipe " + cp .pipeKey + " status=" + cp .status + " pipeAlive=" + cp .isPipeLive () + " created=" + new Date (cp .lastSetup ) + "<br />\r \n " );
223
264
for (int j = 0 ; j < cp .pipes .length ; j ++) {
224
265
CompoundPipeSession ps = cp .pipes [j ];
225
266
if (ps != null ) {
226
- System . out . println (j + " : " + ps .session + " / " + ps .isPipeLive () + " pipeAlive=" + ps .pipeAlive );
267
+ buffer . append (j + " : " + ps .session + " / " + ps .isPipeLive () + " pipeAlive=" + ps .pipeAlive + "<br /> \r \n " );
227
268
}
228
269
}
229
270
}
230
271
if (list != null ) {
231
272
int size = list .size ();
232
273
//if (size > 5) {
233
274
if (p != null ) {
234
- System . out . println ("::: pipe " + p .pipeKey + " size : " + size + " / " + p .pipeAlive );
275
+ buffer . append ("::: pipe " + p .pipeKey + " size : " + size + " / " + p .pipeAlive + "<br /> \r \n " );
235
276
} else {
236
- System . out . println ("Error pipe " + key + " with size : " + size );
277
+ buffer . append ("Error pipe " + key + " with size : " + size + "<br /> \r \n " );
237
278
}
238
279
//}
239
280
}
240
281
}
241
282
}
283
+ return buffer .toString ();
242
284
}
243
285
244
286
@ J2SIgnore
@@ -255,7 +297,7 @@ public static void setMonitoringInterval(long monitoringInterval) {
255
297
private static void monitoringAllPipes () {
256
298
while (true ) {
257
299
try {
258
- Thread .sleep (getMonitoringInterval () );
300
+ Thread .sleep (monitoringInterval );
259
301
} catch (InterruptedException e ) {
260
302
}
261
303
if (pipes == null ) {
@@ -289,7 +331,7 @@ private static void monitoringAllPipes() {
289
331
}
290
332
if (ps .isPipeLive ()) {
291
333
ps .lastLiveDetected = now ;
292
- } else if (now - ps .lastLiveDetected > 30000 + ps .pipeWaitClosingInterval ()) {
334
+ } else if (now - ps .lastLiveDetected > SimplePipeRequest . pipeLiveNotifyInterval * 3 + monitoringInterval + ps .pipeWaitClosingInterval ()) {
293
335
asyncDestroyPipe (ps );
294
336
}
295
337
}
0 commit comments