View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>,
5    *               Henglin Wang <henglinwang@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 3 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, see
19   * <http://www.gnu.org/licenses/>.
20   */
21  package org.jumpmind.symmetric.web;
22  
23  import java.io.ByteArrayOutputStream;
24  import java.io.PrintWriter;
25  
26  import javax.servlet.ServletOutputStream;
27  import javax.servlet.http.HttpServletResponse;
28  import javax.servlet.http.HttpServletResponseWrapper;
29  
30  public class ThrottledResponseWrapper extends HttpServletResponseWrapper {
31      private ByteArrayOutputStream output;
32  
33      private long maxBps = 10240L;
34  
35      private long threshold = 8192L;
36  
37      private long checkPoint = 1024L;
38  
39      public ThrottledResponseWrapper(HttpServletResponse response) {
40          super(response);
41          output = new ByteArrayOutputStream();
42      }
43  
44      public ServletOutputStream getOutputStream() {
45          return new ThrottledServletOutputStream(output, maxBps, threshold, checkPoint);
46      }
47  
48      public PrintWriter getWriter() {
49          return new PrintWriter(getOutputStream(), true);
50      }
51  
52      public ByteArrayOutputStream getOutput() {
53          return output;
54      }
55  
56      public void setOutput(ByteArrayOutputStream output) {
57          this.output = output;
58      }
59  
60      public long getMaxBps() {
61          return maxBps;
62      }
63  
64      public void setMaxBps(long maxBps) {
65          this.maxBps = maxBps;
66      }
67  
68      public long getThreshold() {
69          return threshold;
70      }
71  
72      public void setThreshold(long threshold) {
73          this.threshold = threshold;
74      }
75  
76      public long getCheckPoint() {
77          return checkPoint;
78      }
79  
80      public void setCheckPoint(long checkPoint) {
81          this.checkPoint = checkPoint;
82      }
83  }