2727 */
2828public class SimplePipeHelper {
2929
30- static interface IPipeThrough {
30+ public static interface IPipeThrough {
3131public void helpThrough (SimplePipeRunnable pipe ,SimpleSerializable []objs );
3232}
3333
34- static interface IPipeClosing {
34+ public static interface IPipeClosing {
3535public void helpClosing (SimplePipeRunnable pipe );
3636}
3737
@@ -123,7 +123,7 @@ static String nextPipeKey() {
123123@ J2SNative ({
124124"delete net.sf.j2s.ajax.SimplePipeHelper.pipes[key];"
125125})
126- static void removePipe (String key ) {
126+ public static void removePipe (String key ) {
127127if (key ==null ) {
128128System .out .println ("Removing pipe for null key???" );
129129return ;
@@ -155,15 +155,15 @@ public static SimplePipeRunnable getPipe(String key) {
155155}
156156
157157@ J2SIgnore
158- static List <SimpleSerializable >getPipeDataList (String key ) {
158+ public static List <SimpleSerializable >getPipeDataList (String key ) {
159159if (pipeMap ==null ) {
160160return null ;
161161}
162162return pipeMap .get (key );
163163}
164164
165165@ J2SIgnore
166- static void pipeIn (String key ,SimpleSerializable []ss ) {
166+ public static void pipeIn (String key ,SimpleSerializable []ss ) {
167167SimplePipeRunnable pipe =getPipe (key );
168168List <SimpleSerializable >list =getPipeDataList (key );
169169if (pipe ==null ||list ==null ) {
@@ -180,7 +180,7 @@ static void pipeIn(String key, SimpleSerializable[] ss) {
180180}
181181
182182@ J2SIgnore
183- static boolean isPipeLive (String key ) {
183+ public static boolean isPipeLive (String key ) {
184184SimplePipeRunnable pipe =getPipe (key );
185185if (pipe !=null ) {
186186return pipe .isPipeLive ();
@@ -189,7 +189,7 @@ static boolean isPipeLive(String key) {
189189}
190190
191191@ J2SIgnore
192- static boolean notifyPipeStatus (String key ,boolean live ) {
192+ public static boolean notifyPipeStatus (String key ,boolean live ) {
193193SimplePipeRunnable pipe =getPipe (key );
194194if (pipe !=null &&pipe .isPipeLive ()) {
195195pipe .updateStatus (live );
@@ -199,7 +199,7 @@ static boolean notifyPipeStatus(String key, boolean live) {
199199}
200200
201201@ J2SIgnore
202- public static void helpClosing (SimplePipeRunnable pipe ) {
202+ static void helpClosing (SimplePipeRunnable pipe ) {
203203if (pipe .closer !=null ) {
204204pipe .closer .helpClosing (pipe );
205205}else {
@@ -208,37 +208,79 @@ public static void helpClosing(SimplePipeRunnable pipe) {
208208}
209209
210210@ J2SIgnore
211- public static void printStatistics () {
211+ public static String printStatistics2 () {
212+ StringBuffer buffer =new StringBuffer ();
213+ buffer .append ("Pipe monitor<br />\r \n " );
212214if (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 " );
215217Object []keys =pipeMap .keySet ().toArray ();
216218for (int i =0 ;i <keys .length ;i ++) {
217219String key = (String )keys [i ];
218220List <SimpleSerializable >list =pipeMap .get (key );
219221SimplePipeRunnable p =pipes .get (key );
220222if (p instanceof CompoundPipeRunnable ) {
221223CompoundPipeRunnable 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 " );
223264for (int j =0 ;j <cp .pipes .length ;j ++) {
224265CompoundPipeSession ps =cp .pipes [j ];
225266if (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 " );
227268}
228269}
229270}
230271if (list !=null ) {
231272int size =list .size ();
232273//if (size > 5) {
233274if (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 " );
235276}else {
236- System . out . println ("Error pipe " +key +" with size : " +size );
277+ buffer . append ("Error pipe " +key +" with size : " +size + "<br /> \r \n " );
237278}
238279//}
239280}
240281}
241282}
283+ return buffer .toString ();
242284}
243285
244286@ J2SIgnore
@@ -255,7 +297,7 @@ public static void setMonitoringInterval(long monitoringInterval) {
255297private static void monitoringAllPipes () {
256298while (true ) {
257299try {
258- Thread .sleep (getMonitoringInterval () );
300+ Thread .sleep (monitoringInterval );
259301}catch (InterruptedException e ) {
260302}
261303if (pipes ==null ) {
@@ -289,7 +331,7 @@ private static void monitoringAllPipes() {
289331}
290332if (ps .isPipeLive ()) {
291333ps .lastLiveDetected =now ;
292- }else if (now -ps .lastLiveDetected >30000 +ps .pipeWaitClosingInterval ()) {
334+ }else if (now -ps .lastLiveDetected >SimplePipeRequest . pipeLiveNotifyInterval * 3 + monitoringInterval +ps .pipeWaitClosingInterval ()) {
293335asyncDestroyPipe (ps );
294336}
295337}