You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/01/03 14:06:05 UTC

svn commit: r730982 - in /webservices/commons/trunk/modules/tcpmon: modules/tcpmon-ui/ src/org/apache/ws/commons/tcpmon/ src/org/apache/ws/commons/tcpmon/core/ src/org/apache/ws/commons/tcpmon/eclipse/ui/

Author: veithen
Date: Sat Jan  3 05:06:05 2009
New Revision: 730982

URL: http://svn.apache.org/viewvc?rev=730982&view=rev
Log:
TCPMon: Some more refactorings:
* Swing Listener implementation: changed the Listener-JPanel relationship from inheritance to composition.
* Introduced a common base class for the two Listener implementations.
* Merged the two SocketWaiter implementations into a single class.

Added:
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractListener.java   (with props)
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/SocketWaiter.java   (contents, props changed)
      - copied, changed from r729930, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketWaiter.java
Removed:
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketWaiter.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java
Modified:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/pom.xml
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/pom.xml?rev=730982&r1=730981&r2=730982&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/pom.xml (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/pom.xml Sat Jan  3 05:06:05 2009
@@ -51,8 +51,6 @@
                         <include>org/apache/ws/commons/tcpmon/JTextAreaWriter.java</include>
                         <include>org/apache/ws/commons/tcpmon/Listener.java</include>
                         <include>org/apache/ws/commons/tcpmon/Sender.java</include>
-                        <include>org/apache/ws/commons/tcpmon/SocketRR.java</include>
-                        <include>org/apache/ws/commons/tcpmon/SocketWaiter.java</include>
                         <include>org/apache/ws/commons/tcpmon/TCPMon.java</include>
                     </includes>
                 </configuration>

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java?rev=730982&r1=730981&r2=730982&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java Sat Jan  3 05:06:05 2009
@@ -38,9 +38,13 @@
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.TableColumn;
 
+import org.apache.ws.commons.tcpmon.core.AbstractConnection;
+import org.apache.ws.commons.tcpmon.core.AbstractListener;
 import org.apache.ws.commons.tcpmon.core.Configuration;
+import org.apache.ws.commons.tcpmon.core.SocketWaiter;
 
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
@@ -49,13 +53,16 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.net.Socket;
 import java.util.Iterator;
 import java.util.Vector;
 
 /**
  * this is one of the tabbed panels that acts as the actual proxy
  */
-class Listener extends JPanel {
+class Listener extends AbstractListener {
+    private final JPanel panel;
+
     /**
      * Field portField
      */
@@ -188,7 +195,7 @@
             // or make up a no-op one.
             this.slowLink = new SlowLinkSimulator(0, 0);
         }
-        this.setLayout(new BorderLayout());
+        panel = new JPanel(new BorderLayout());
 
         // 1st component is just a row of labels and 1-line entry fields
         // ///////////////////////////////////////////////////////////////////
@@ -236,7 +243,7 @@
                 }
             }
         });
-        this.add(top, BorderLayout.NORTH);
+        panel.add(top, BorderLayout.NORTH);
 
         // 2nd component is a split pane with a table on the top
         // and the request/response text areas on the bottom
@@ -442,13 +449,13 @@
         pane1.setTopComponent(tablePane);
         pane1.setBottomComponent(pane2);
         pane1.setDividerLocation(150);
-        this.add(pane1, BorderLayout.CENTER);
+        panel.add(pane1, BorderLayout.CENTER);
 
         // 
         // //////////////////////////////////////////////////////////////////
         sel.setSelectionInterval(0, 0);
         outPane.setDividerLocation(150);
-        notebook.addTab(name, this);
+        notebook.addTab(name, panel);
         start();
     }
 
@@ -478,7 +485,7 @@
     public void start() {
         int port = Integer.parseInt(portField.getText());
         portField.setText("" + port);
-        int i = notebook.indexOfComponent(this);
+        int i = notebook.indexOfComponent(panel);
         notebook.setTitleAt(i, TCPMonBundle.getMessage("port01", "Port") + " " + port);
         int tmp = Integer.parseInt(tPortField.getText());
         tPortField.setText("" + tmp);
@@ -495,7 +502,7 @@
      */
     public void close() {
         stop();
-        notebook.remove(this);
+        notebook.remove(panel);
     }
 
     /**
@@ -551,7 +558,7 @@
      */
     public void save() {
         JFileChooser dialog = new JFileChooser(".");
-        int rc = dialog.showSaveDialog(this);
+        int rc = dialog.showSaveDialog(panel);
         if (rc == JFileChooser.APPROVE_OPTION) {
             try {
                 File file = dialog.getSelectedFile();
@@ -669,4 +676,23 @@
         config.setSlowLink(slowLink);
         return config;
     }
+
+    public void onServerSocketStart() {
+        setLeft(new JLabel(
+                        TCPMonBundle.getMessage("wait00",
+                                " Waiting for Connection...")));
+        panel.repaint();
+    }
+
+    public void onServerSocketError(Throwable ex) {
+        JLabel tmp = new JLabel(ex.toString());
+        tmp.setForeground(Color.red);
+        setLeft(tmp);
+        setRight(new JLabel(""));
+        stop();
+    }
+
+    public AbstractConnection createConnection(Socket inSocket) {
+        return new Connection(this, inSocket);
+    }
 }

Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractListener.java?rev=730982&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractListener.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractListener.java Sat Jan  3 05:06:05 2009
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+import java.net.Socket;
+
+public abstract class AbstractListener {
+    public abstract void onServerSocketStart();
+    public abstract void onServerSocketError(Throwable ex);
+    public abstract AbstractConnection createConnection(Socket inSocket);
+}

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

Copied: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/SocketWaiter.java (from r729930, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketWaiter.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/SocketWaiter.java?p2=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/SocketWaiter.java&p1=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketWaiter.java&r1=729930&r2=730982&rev=730982&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketWaiter.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/SocketWaiter.java Sat Jan  3 05:06:05 2009
@@ -14,10 +14,8 @@
  * limitations under the License.
  */
 
-package org.apache.ws.commons.tcpmon;
+package org.apache.ws.commons.tcpmon.core;
 
-import javax.swing.JLabel;
-import java.awt.Color;
 import java.net.ServerSocket;
 import java.net.Socket;
 
@@ -25,7 +23,7 @@
  * wait for incoming connections, spawn a connection thread when
  * stuff comes in.
  */
-class SocketWaiter extends Thread {
+public class SocketWaiter extends Thread {
 
     /**
      * Field sSocket
@@ -35,7 +33,7 @@
     /**
      * Field listener
      */
-    Listener listener;
+    AbstractListener listener;
 
     /**
      * Field port
@@ -53,7 +51,7 @@
      * @param l
      * @param p
      */
-    public SocketWaiter(Listener l, int p) {
+    public SocketWaiter(AbstractListener l, int p) {
         listener = l;
         port = p;
         start();
@@ -64,27 +62,19 @@
      */
     public void run() {
         try {
-            listener.setLeft(
-                    new JLabel(
-                            TCPMonBundle.getMessage("wait00",
-                                    " Waiting for Connection...")));
-            listener.repaint();
+            listener.onServerSocketStart();
             sSocket = new ServerSocket(port);
             for (; ;) {
                 Socket inSocket = sSocket.accept();
                 if (pleaseStop) {
                     break;
                 }
-                new Connection(listener, inSocket);
+                listener.createConnection(inSocket);
                 inSocket = null;
             }
         } catch (Exception exp) {
             if (!"socket closed".equals(exp.getMessage())) {
-                JLabel tmp = new JLabel(exp.toString());
-                tmp.setForeground(Color.red);
-                listener.setLeft(tmp);
-                listener.setRight(new JLabel(""));
-                listener.stop();
+                listener.onServerSocketError(exp);
             }
         }
     }

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

Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/SocketWaiter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java?rev=730982&r1=730981&r2=730982&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java Sat Jan  3 05:06:05 2009
@@ -17,7 +17,10 @@
 
 import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
 import org.apache.ws.commons.tcpmon.TCPMonBundle;
+import org.apache.ws.commons.tcpmon.core.AbstractConnection;
+import org.apache.ws.commons.tcpmon.core.AbstractListener;
 import org.apache.ws.commons.tcpmon.core.Configuration;
+import org.apache.ws.commons.tcpmon.core.SocketWaiter;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -28,6 +31,7 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.net.Socket;
 import java.util.Iterator;
 import java.util.Vector;
 
@@ -35,7 +39,7 @@
  * This is similar to the main swing listener but includes SWT components instead of Swing ones
  *
  */
-class Listener {
+class Listener extends AbstractListener {
     private Composite leftPanel = null;
     private Composite rightPanel = null;
     private Composite textComposite = null;
@@ -666,4 +670,26 @@
         config.setSlowLink(slowLink);
         return config;
     }
+
+    public void onServerSocketStart() {
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                setLeft(MainView.SWT_LABEL, TCPMonBundle.getMessage("wait00", " Waiting for Connection..."));
+            }
+        });
+    }
+
+    public void onServerSocketError(final Throwable ex) {
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                setLeft(MainView.SWT_LABEL, ex.toString());
+                setRight(MainView.SWT_LABEL, "");
+                stop();
+            }
+        });
+    }
+
+    public AbstractConnection createConnection(Socket inSocket) {
+        return new Connection(this, inSocket);
+    }
 }