@@ -34,6 +34,8 @@ public class SimplePipeHttpServlet extends HttpServlet {
3434
3535 protected long pipeScriptBreakout = 1200000 ; // 20 minutes
3636
37+ protected int pipeMaxItemsPerQuery = -1 ; // infinite
38+
3739 /*
3840 * Example of web.xml:
3941 <servlet>
@@ -47,6 +49,10 @@ public class SimplePipeHttpServlet extends HttpServlet {
4749 <param-name>simple.pipe.script.breakout</param-name>
4850 <param-value>1200000</param-value>
4951 </init-param>
52+ <init-param>
53+ <param-name>simple.pipe.max.items.per.query</param-name>
54+ <param-value>60</param-value>
55+ </init-param>
5056 </servlet>
5157 <servlet-mapping>
5258 <servlet-name>simplepipe</servlet-name>
@@ -83,6 +89,19 @@ public void init() throws ServletException {
8389 e .printStackTrace ();
8490 }
8591 }
92+ String perQueryStr = getInitParameter ("simple.pipe.max.items.per.query" );
93+ if (perQueryStr != null ) {
94+ try {
95+ pipeMaxItemsPerQuery = Integer .parseInt (perQueryStr );
96+ if (pipeMaxItemsPerQuery <= 0 ) {
97+ pipeMaxItemsPerQuery = -1 ; // 0, -1 means infinite items
98+ } else if (pipeMaxItemsPerQuery < 5 ) {
99+ pipeMaxItemsPerQuery = 5 ; // hey, we think limiting for less than 5 items make no senses.
100+ }
101+ } catch (NumberFormatException e ) {
102+ e .printStackTrace ();
103+ }
104+ }
86105 super .init ();
87106 }
88107
@@ -193,6 +212,7 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
193212 if (pipe != null ) {
194213 waitClosingInterval = pipe .pipeWaitClosingInterval ();
195214 }
215+ int items = 0 ;
196216 while ((vector = SimplePipeHelper .getPipeVector (key )) != null
197217 /* && SimplePipeHelper.isPipeLive(key) */ // check it!
198218 && !writer .checkError ()) {
@@ -224,6 +244,11 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
224244 }
225245 if (ss == null ) break ; // terminating signal
226246 output (writer , type , key , ss .serialize ());
247+ items ++;
248+ if (pipeMaxItemsPerQuery > 0 && items >= pipeMaxItemsPerQuery
249+ && !SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type )) {
250+ break ;
251+ }
227252 lastPipeDataWritten = new Date ().getTime ();
228253 writer .flush ();
229254 if (ss instanceof ISimplePipePriority ) {
@@ -256,6 +281,8 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
256281
257282 now = new Date ().getTime ();
258283 if ((vector = SimplePipeHelper .getPipeVector (key )) != null // may be broken down already!!
284+ && (pipeMaxItemsPerQuery <= 0 || items < pipeMaxItemsPerQuery
285+ || SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type ))
259286 && (SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type )
260287 || (SimplePipeRequest .PIPE_TYPE_SCRIPT .equals (type )
261288 && now - beforeLoop < pipeScriptBreakout )
0 commit comments