@@ -182,101 +182,100 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
182182 writer = resp .getWriter ();
183183 }
184184
185- SimplePipeHelper .notifyPipeStatus (key , true ); // update it!
186-
187185 long lastPipeDataWritten = -1 ;
188-
189186 long beforeLoop = new Date ().getTime ();
190- Vector <SimpleSerializable > vector = null ;
191- int priority = 0 ;
192- long lastLiveDetected = System .currentTimeMillis ();
193- SimplePipeRunnable pipe = SimplePipeHelper .getPipe (key );
194- long waitClosingInterval = 5000 ;
195- if (pipe != null ) {
196- waitClosingInterval = pipe .pipeWaitClosingInterval ();
197- }
198- while ((vector = SimplePipeHelper .getPipeVector (key )) != null
199- /* && SimplePipeHelper.isPipeLive(key) */ // check it!
200- && !writer .checkError ()) {
201- if (!SimplePipeHelper .isPipeLive (key )) {
202- if (System .currentTimeMillis () - lastLiveDetected > waitClosingInterval ) {
203- // break out while loop so pipe connection will be closed
204- break ;
205- } else { // sleep 1s and continue to check pipe status again
206- try {
207- Thread .sleep (1000 );
208- } catch (InterruptedException e ) {
187+ if (SimplePipeHelper .notifyPipeStatus (key , true )) { // update it!
188+ Vector <SimpleSerializable > vector = null ;
189+ int priority = 0 ;
190+ long lastLiveDetected = System .currentTimeMillis ();
191+ SimplePipeRunnable pipe = SimplePipeHelper .getPipe (key );
192+ long waitClosingInterval = 5000 ;
193+ if (pipe != null ) {
194+ waitClosingInterval = pipe .pipeWaitClosingInterval ();
195+ }
196+ while ((vector = SimplePipeHelper .getPipeVector (key )) != null
197+ /* && SimplePipeHelper.isPipeLive(key) */ // check it!
198+ && !writer .checkError ()) {
199+ if (!SimplePipeHelper .isPipeLive (key )) {
200+ if (System .currentTimeMillis () - lastLiveDetected > waitClosingInterval ) {
201+ // break out while loop so pipe connection will be closed
202+ break ;
203+ } else { // sleep 1s and continue to check pipe status again
204+ try {
205+ Thread .sleep (1000 );
206+ } catch (InterruptedException e ) {
207+ }
208+ continue ;
209209 }
210- continue ;
210+ } else {
211+ lastLiveDetected = System .currentTimeMillis ();
211212 }
212- } else {
213- lastLiveDetected = System .currentTimeMillis ();
214- }
215- int size = vector .size ();
216- if (size > 0 ) {
217- for (int i = 0 ; i < size ; i ++) {
218- SimpleSerializable ss = null ;
219- /*
220- * Still need to check vector size!
221- * Maybe multiple pipe servlets!
222- */
223- synchronized (vector ) {
224- if (vector .size () <= 0 ) break ;
225- ss = vector .remove (0 );
226- }
227- if (ss == null ) break ; // terminating signal
228- output (writer , type , key , ss .serialize ());
229- lastPipeDataWritten = new Date ().getTime ();
230- writer .flush ();
231- if (ss instanceof ISimplePipePriority ) {
232- ISimplePipePriority spp = (ISimplePipePriority ) ss ;
233- int p = spp .getPriority ();
234- if (p <= 0 ) {
235- p = ISimplePipePriority .IMPORTANT ;
213+ int size = vector .size ();
214+ if (size > 0 ) {
215+ for (int i = 0 ; i < size ; i ++) {
216+ SimpleSerializable ss = null ;
217+ /*
218+ * Still need to check vector size!
219+ * Maybe multiple pipe servlets!
220+ */
221+ synchronized (vector ) {
222+ if (vector .size () <= 0 ) break ;
223+ ss = vector .remove (0 );
224+ }
225+ if (ss == null ) break ; // terminating signal
226+ output (writer , type , key , ss .serialize ());
227+ lastPipeDataWritten = new Date ().getTime ();
228+ writer .flush ();
229+ if (ss instanceof ISimplePipePriority ) {
230+ ISimplePipePriority spp = (ISimplePipePriority ) ss ;
231+ int p = spp .getPriority ();
232+ if (p <= 0 ) {
233+ p = ISimplePipePriority .IMPORTANT ;
234+ }
235+ priority += p ;
236+ } else {
237+ priority += ISimplePipePriority .IMPORTANT ;
236238 }
237- priority += p ;
238- } else {
239- priority += ISimplePipePriority .IMPORTANT ;
240239 }
240+ } else {
241+ writer .flush ();
241242 }
242- } else {
243- writer .flush ();
244- }
245- /*
246- * Client should send in "notify" request to simulate the following #notifyPipeStatus
247- */
248- // SimplePipeHelper.notifyPipeStatus(key, true);
249-
250- long now = new Date ().getTime ();
251- if ((lastPipeDataWritten == -1 && now - beforeLoop >= pipeQueryTimeout )
252- || (lastPipeDataWritten > 0
253- && now - lastPipeDataWritten >= pipeQueryTimeout
254- && SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type ))) {
255- output (writer , type , key , SimplePipeRequest .PIPE_STATUS_OK );
256- lastPipeDataWritten = new Date ().getTime ();
257- }
258-
259- now = new Date ().getTime ();
260- if ((vector = SimplePipeHelper .getPipeVector (key )) != null // may be broken down already!!
261- && (SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type )
262- || (SimplePipeRequest .PIPE_TYPE_SCRIPT .equals (type )
263- && now - beforeLoop < pipeScriptBreakout )
264- || (priority < ISimplePipePriority .IMPORTANT
265- && now - beforeLoop < pipeQueryTimeout ))) {
266- synchronized (vector ) {
267- try {
268- vector .wait (1000 );
269- } catch (InterruptedException e ) {
270- e .printStackTrace ();
243+ /*
244+ * Client should send in "notify" request to simulate the following #notifyPipeStatus
245+ */
246+ // SimplePipeHelper.notifyPipeStatus(key, true);
247+
248+ long now = new Date ().getTime ();
249+ if ((lastPipeDataWritten == -1 && now - beforeLoop >= pipeQueryTimeout )
250+ || (lastPipeDataWritten > 0
251+ && now - lastPipeDataWritten >= pipeQueryTimeout
252+ && SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type ))) {
253+ output (writer , type , key , SimplePipeRequest .PIPE_STATUS_OK );
254+ lastPipeDataWritten = new Date ().getTime ();
255+ }
256+
257+ now = new Date ().getTime ();
258+ if ((vector = SimplePipeHelper .getPipeVector (key )) != null // may be broken down already!!
259+ && (SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type )
260+ || (SimplePipeRequest .PIPE_TYPE_SCRIPT .equals (type )
261+ && now - beforeLoop < pipeScriptBreakout )
262+ || (priority < ISimplePipePriority .IMPORTANT
263+ && now - beforeLoop < pipeQueryTimeout ))) {
264+ synchronized (vector ) {
265+ try {
266+ vector .wait (1000 );
267+ } catch (InterruptedException e ) {
268+ e .printStackTrace ();
269+ }
271270 }
271+ } else {
272+ break ;
272273 }
273- } else {
274- break ;
275- }
276- } // end of while
274+ } // end of while
275+ } // else pips is already closed or in other statuses
277276 if (SimplePipeHelper .getPipeVector (key ) == null
278277 || !SimplePipeHelper .isPipeLive (key )) { // pipe is tore down!
279- SimplePipeHelper .notifyPipeStatus (key , false );
278+ // SimplePipeHelper.notifyPipeStatus(key, false); // Leave for pipe monitor to destroy it
280279 SimplePipeHelper .pipeTearDown (key );
281280 SimplePipeHelper .removePipe (key );
282281 try {
0 commit comments