Author: veithen
Date: Fri May 29 13:27:21 2009
New Revision: 779963

URL: http://svn.apache.org/viewvc?rev=779963&view=rev
Log:
Split SlowLinkSimulator into an immutable config part and a stateful filter 
part. Also renamed the whole to Throttle.

Added:
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/Throttle.java
      - copied, changed from r779940, 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/SlowLinkSimulator.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/ThrottleConfiguration.java
   (with props)
Removed:
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/SlowLinkSimulator.java
Modified:
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Configuration.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Configuration.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Configuration.java?rev=779963&r1=779962&r2=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Configuration.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Configuration.java
 Fri May 29 13:27:21 2009
@@ -16,7 +16,7 @@
 
 package org.apache.ws.commons.tcpmon.core;
 
-import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
+import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
 
 public class Configuration {
     private int listenPort;
@@ -26,7 +26,7 @@
     private boolean xmlFormat;
     private String httpProxyHost;
     private int httpProxyPort;
-    private SlowLinkSimulator slowLink;
+    private ThrottleConfiguration throttleConfiguration;
     
     public void configProxyFromSystemProperties() {
         String host = System.getProperty("http.proxyHost");
@@ -99,11 +99,11 @@
         this.httpProxyPort = httpProxyPort;
     }
 
-    public SlowLinkSimulator getSlowLink() {
-        return slowLink;
+    public ThrottleConfiguration getThrottleConfiguration() {
+        return throttleConfiguration;
     }
 
-    public void setSlowLink(SlowLinkSimulator slowLink) {
-        this.slowLink = slowLink;
+    public void setThrottleConfiguration(ThrottleConfiguration 
throttleConfiguration) {
+        this.throttleConfiguration = throttleConfiguration;
     }
 }

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java?rev=779963&r1=779962&r2=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java
 Fri May 29 13:27:21 2009
@@ -16,7 +16,6 @@
 
 package org.apache.ws.commons.tcpmon.core;
 
-import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
 import org.apache.ws.commons.tcpmon.core.filter.Pipeline;
 import org.apache.ws.commons.tcpmon.core.filter.StreamException;
 import org.apache.ws.commons.tcpmon.core.filter.Tee;
@@ -24,6 +23,7 @@
 import org.apache.ws.commons.tcpmon.core.filter.http.HttpProxyClientHandler;
 import org.apache.ws.commons.tcpmon.core.filter.http.HttpProxyServerHandler;
 import org.apache.ws.commons.tcpmon.core.filter.http.HttpRequestFilter;
+import org.apache.ws.commons.tcpmon.core.filter.throttle.Throttle;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -147,7 +147,7 @@
                 requestFilter.addHandler(new 
HttpProxyClientHandler(targetHost, targetPort));
                 outSocket = new Socket(HTTPProxyHost, HTTPProxyPort);
             }
-            requestPipeline.addFilter(config.getSlowLink());
+            requestPipeline.addFilter(new 
Throttle(config.getThrottleConfiguration()));
             Tee requestTee = new Tee();
             requestPipeline.addFilter(requestTee);
             
@@ -163,7 +163,7 @@
             requestTee.setOutputStream(tmpOut2);
             
             Pipeline responsePipeline = new Pipeline();
-            responsePipeline.addFilter(new 
SlowLinkSimulator(config.getSlowLink()));
+            responsePipeline.addFilter(new 
Throttle(config.getThrottleConfiguration()));
             if (tmpOut1 != null) {
                 responsePipeline.addFilter(new Tee(tmpOut1));
             }

Copied: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/Throttle.java
 (from r779940, 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/SlowLinkSimulator.java)
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/Throttle.java?p2=webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/Throttle.java&p1=webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/SlowLinkSimulator.java&r1=779940&r2=779963&rev=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/SlowLinkSimulator.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/Throttle.java
 Fri May 29 13:27:21 2009
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.apache.ws.commons.tcpmon;
+package org.apache.ws.commons.tcpmon.core.filter.throttle;
 
 import org.apache.ws.commons.tcpmon.core.filter.Stream;
 import org.apache.ws.commons.tcpmon.core.filter.StreamFilter;
@@ -22,17 +22,8 @@
 /**
  * class to simulate slow connections by slowing down the system
  */
-public class SlowLinkSimulator implements StreamFilter {
-
-       /**
-     * Field delayBytes
-     */
-    private int delayBytes;
-
-    /**
-     * Field delayTime
-     */
-    private int delayTime;
+public class Throttle implements StreamFilter {
+    private final ThrottleConfiguration config;
 
     /**
      * Field currentBytes
@@ -45,25 +36,12 @@
     private int totalBytes;
 
     /**
-     * construct
-     *
-     * @param delayBytes bytes per delay; set to 0 for no delay
-     * @param delayTime  delay time per delay in milliseconds
-     */
-    public SlowLinkSimulator(int delayBytes, int delayTime) {
-        this.delayBytes = delayBytes;
-        this.delayTime = delayTime;
-    }
-
-    /**
-     * construct by copying delay bytes and time, but not current
-     * count of bytes
-     *
-     * @param that source of data
+     * Constructor.
+     * 
+     * @param config the configuration for this throttle instance
      */
-    public SlowLinkSimulator(SlowLinkSimulator that) {
-        this.delayBytes = that.delayBytes;
-        this.delayTime = that.delayTime;
+    public Throttle(ThrottleConfiguration config) {
+        this.config = config;
     }
 
     /**
@@ -82,6 +60,7 @@
      * @param bytes
      */
     public void pump(int bytes) {
+        int delayBytes = config.getDelayBytes();
         totalBytes += bytes;
         if (delayBytes == 0) {
 
@@ -93,7 +72,7 @@
 
             // we have overshot. lets find out how far
             int delaysize = currentBytes / delayBytes;
-            long delay = delaysize * (long) delayTime;
+            long delay = delaysize * (long) config.getDelayTime();
 
             // move byte counter down to the remainder of bytes
             currentBytes = currentBytes % delayBytes;

Added: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/ThrottleConfiguration.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/ThrottleConfiguration.java?rev=779963&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/ThrottleConfiguration.java
 (added)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/ThrottleConfiguration.java
 Fri May 29 13:27:21 2009
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon.core.filter.throttle;
+
+public class ThrottleConfiguration {
+    private int delayBytes;
+    private int delayTime;
+    
+    /**
+     * construct
+     *
+     * @param delayBytes bytes per delay; set to 0 for no delay
+     * @param delayTime  delay time per delay in milliseconds
+     */
+    public ThrottleConfiguration(int delayBytes, int delayTime) {
+        this.delayBytes = delayBytes;
+        this.delayTime = delayTime;
+    }
+
+    public int getDelayBytes() {
+        return delayBytes;
+    }
+
+    public int getDelayTime() {
+        return delayTime;
+    }
+}

Propchange: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/throttle/ThrottleConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java?rev=779963&r1=779962&r2=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
 Fri May 29 13:27:21 2009
@@ -15,12 +15,12 @@
  */
 package org.apache.ws.commons.tcpmon.eclipse.ui;
 
-import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
 import org.apache.ws.commons.tcpmon.TCPMonBundle;
 import org.apache.ws.commons.tcpmon.core.AbstractListener;
 import org.apache.ws.commons.tcpmon.core.Configuration;
 import org.apache.ws.commons.tcpmon.core.IRequestResponse;
 import org.apache.ws.commons.tcpmon.core.SocketWaiter;
+import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -57,7 +57,7 @@
     private TabItem portTabItem;
 
     private SocketWaiter sw = null;
-    private SlowLinkSimulator slowLink;
+    private ThrottleConfiguration throttleConfig;
 
     public final Vector requestResponses = new Vector();
 
@@ -66,16 +66,16 @@
 
     public Listener(TabFolder tabFolder, String name, int listenPort,
                     String host, int targetPort, boolean isProxy,
-                    SlowLinkSimulator slowLink) {
+                    ThrottleConfiguration throttleConfig) {
         if (name == null) {
             name = TCPMonBundle.getMessage("port01", "Port") + " " + 
listenPort;
         }
         // set the slow link to the passed down link
-        if (slowLink != null) {
-            this.slowLink = slowLink;
+        if (throttleConfig != null) {
+            this.throttleConfig = throttleConfig;
         } else {
             // or make up a no-op one.
-            this.slowLink = new SlowLinkSimulator(0, 0);
+            this.throttleConfig = new ThrottleConfiguration(0, 0);
         }
 
         this.tabFolder = tabFolder;
@@ -623,7 +623,7 @@
             config.setHttpProxyHost(HTTPProxyHost);
             config.setHttpProxyPort(HTTPProxyPort);
         }
-        config.setSlowLink(slowLink);
+        config.setThrottleConfiguration(throttleConfig);
         return config;
     }
 

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java?rev=779963&r1=779962&r2=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
 Fri May 29 13:27:21 2009
@@ -16,8 +16,8 @@
 package org.apache.ws.commons.tcpmon.eclipse.ui;
 
 
-import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
 import org.apache.ws.commons.tcpmon.TCPMonBundle;
+import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -115,16 +115,16 @@
                     String tHost = host.getText();
                     int tPort;
                     tPort = getValue(0, tport.getText());
-                    SlowLinkSimulator slowLink = null;
+                    ThrottleConfiguration throttleConfig = null;
                     if (delayBox.getSelection()) {
                         int bytes = getValue(0, delayBytes.getText());
                         int time = getValue(0, delayTime.getText());
-                        slowLink = new SlowLinkSimulator(bytes, time);
+                        throttleConfig = new ThrottleConfiguration(bytes, 
time);
                     }
                     try {
                         l = new Listener(tabFolder, null, lPort, tHost, tPort,
                                 proxyButton.getSelection(),
-                                slowLink);
+                                throttleConfig);
                     } catch (Exception exp) {
                         exp.printStackTrace();
                     }

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java?rev=779963&r1=779962&r2=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
 Fri May 29 13:27:21 2009
@@ -31,6 +31,9 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 import javax.swing.text.PlainDocument;
+
+import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
+
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -381,16 +384,16 @@
                     String tHost = host.getText();
                     int tPort = 0;
                     tPort = tport.getValue(0);
-                    SlowLinkSimulator slowLink = null;
+                    ThrottleConfiguration throttleConfig = null;
                     if (delayBox.isSelected()) {
                         int bytes = delayBytes.getValue(0);
                         int time = delayTime.getValue(0);
-                        slowLink = new SlowLinkSimulator(bytes, time);
+                        throttleConfig = new ThrottleConfiguration(bytes, 
time);
                     }
                     try {
                         l = new Listener(noteb, null, lPort, tHost, tPort,
                                 proxyButton.isSelected(),
-                                slowLink);
+                                throttleConfig);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java?rev=779963&r1=779962&r2=779963&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
 Fri May 29 13:27:21 2009
@@ -44,6 +44,7 @@
 import org.apache.ws.commons.tcpmon.core.Configuration;
 import org.apache.ws.commons.tcpmon.core.IRequestResponse;
 import org.apache.ws.commons.tcpmon.core.SocketWaiter;
+import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -164,7 +165,7 @@
     /**
      * Field slowLink
      */
-    public SlowLinkSimulator slowLink;
+    public ThrottleConfiguration throttleConfig;
 
     /**
      * Field connections
@@ -184,19 +185,19 @@
      */
     public Listener(JTabbedPane _notebook, String name, int listenPort,
                     String host, int targetPort, boolean isProxy,
-                    SlowLinkSimulator slowLink) {
+                    ThrottleConfiguration throttleConfig) {
         notebook = _notebook;
         if (name == null) {
             name = TCPMonBundle.getMessage("port01", "Port") + " " + 
listenPort;
         }
 
         // set the slow link to the passed down link
-        if (slowLink != null) {
-            this.slowLink = slowLink;
+        if (throttleConfig != null) {
+            this.throttleConfig = throttleConfig;
         } else {
 
             // or make up a no-op one.
-            this.slowLink = new SlowLinkSimulator(0, 0);
+            this.throttleConfig = new ThrottleConfiguration(0, 0);
         }
         panel = new JPanel(new BorderLayout());
 
@@ -600,7 +601,7 @@
             config.setHttpProxyHost(HTTPProxyHost);
             config.setHttpProxyPort(HTTPProxyPort);
         }
-        config.setSlowLink(slowLink);
+        config.setThrottleConfiguration(throttleConfig);
         return config;
     }
 


Reply via email to