activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r384220 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq: transport/ transport/failover/ transport/fanout/ transport/mock/ transport/tcp/ transport/vm/ util/
Date Wed, 08 Mar 2006 14:10:28 GMT
Author: jstrachan
Date: Wed Mar  8 06:10:27 2006
New Revision: 384220

URL: http://svn.apache.org/viewcvs?rev=384220&view=rev
Log:
minor refactor to use "stopped" and "stopping" as properties on ServiceSupport and the transport
classes. Also made the TransportListener getter visible and avoided the need for protected
variables in the various TransportFilter implementations (due to inlining, often getter methods
are faster in hotspot than access to protected fields, plus it simplifies the code & makes
it less brittle)

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/MarshallingTransportFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/WireFormatNegotiator.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ServiceSupport.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java
Wed Mar  8 06:10:27 2006
@@ -112,7 +112,7 @@
     public void onCommand(Command command) {
         inReceive.set(true);
         try {
-            commandListener.onCommand(command);
+            getTransportListener().onCommand(command);
         } finally {
             inReceive.set(false);
             commandReceived.set(true);
@@ -132,6 +132,6 @@
     
     public void onException(IOException error) {
         Scheduler.cancel(this);
-        commandListener.onException(error);
+        getTransportListener().onException(error);
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/MarshallingTransportFilter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/MarshallingTransportFilter.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/MarshallingTransportFilter.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/MarshallingTransportFilter.java
Wed Mar  8 06:10:27 2006
@@ -38,9 +38,9 @@
     
     public void onCommand(Command command) {
         try {
-            commandListener.onCommand((Command)localWireFormat.unmarshal(remoteWireFormat.marshal(command)));
+            getTransportListener().onCommand((Command)localWireFormat.unmarshal(remoteWireFormat.marshal(command)));
         } catch (IOException e) {
-            commandListener.onException(e);
+            getTransportListener().onException(e);
         }
     }
     

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/ResponseCorrelator.java
Wed Mar  8 06:10:27 2006
@@ -79,7 +79,7 @@
                 if( debug ) log.debug("Received unexpected response for command id: "+response.getCorrelationId());
             }
         } else {
-            commandListener.onCommand(command);
+            getTransportListener().onCommand(command);
         }
     }
     

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/Transport.java
Wed Mar  8 06:10:27 2006
@@ -47,6 +47,11 @@
     public Response request(Command command) throws IOException;
 
     /**
+     * Returns the current transport listener
+     */
+    public TransportListener getTransportListener();
+
+    /**
      * Registers an inbound command listener
      */
     public void setTransportListener(TransportListener commandListener);

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportFilter.java
Wed Mar  8 06:10:27 2006
@@ -28,16 +28,18 @@
 public class TransportFilter extends DefaultTransportListener implements Transport {
 
     final protected Transport next;
-    protected TransportListener commandListener;
+    private TransportListener transportListener;
 
     public TransportFilter(Transport next) {
         this.next = next;
     }
 
-    /**
-     */
+    public TransportListener getTransportListener() {
+        return transportListener;
+    }
+    
     public void setTransportListener(TransportListener channelListener) {
-        this.commandListener = channelListener;
+        this.transportListener = channelListener;
         if (channelListener == null)
             next.setTransportListener(null);
         else
@@ -52,7 +54,7 @@
     public void start() throws Exception {
         if( next == null )
             throw new IOException("The next channel has not been set.");
-        if( commandListener == null )
+        if( transportListener == null )
             throw new IOException("The command listener has not been set.");
         next.start();
     }
@@ -65,7 +67,7 @@
     }    
 
     public void onCommand(Command command) {
-        commandListener.onCommand(command);
+        transportListener.onCommand(command);
     }
 
     /**
@@ -75,13 +77,7 @@
         return next;
     }
 
-    /**
-     * @return Returns the packetListener.
-     */
-    public TransportListener getCommandListener() {
-        return commandListener;
-    }
-    
+
     public String toString() {
         return next.toString();
     }
@@ -99,7 +95,7 @@
     }
 
     public void onException(IOException error) {
-        commandListener.onException(error);
+        transportListener.onException(error);
     }
 
     public Object narrow(Class target) {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportLogger.java
Wed Mar  8 06:10:27 2006
@@ -55,14 +55,14 @@
         if( log.isDebugEnabled() ) {
             log.debug("RECEIVED: "+command);
         }
-        commandListener.onCommand(command);
+        getTransportListener().onCommand(command);
     }
     
     public void onException(IOException error) {
         if( log.isDebugEnabled() ) {
             log.debug("RECEIVED Exception: "+error, error);
         }
-        commandListener.onException(error);
+        getTransportListener().onException(error);
     }
     
     public String toString() {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportSupport.java
Wed Mar  8 06:10:27 2006
@@ -17,7 +17,9 @@
 package org.apache.activemq.transport;
 
 import org.apache.activemq.command.Command;
+import org.apache.activemq.command.RemoveInfo;
 import org.apache.activemq.command.Response;
+import org.apache.activemq.command.ShutdownInfo;
 import org.apache.activemq.util.ServiceSupport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -32,8 +34,11 @@
 public abstract class TransportSupport extends ServiceSupport implements Transport {
     private static final Log log = LogFactory.getLog(TransportSupport.class);
 
-    private TransportListener transportListener;
+    TransportListener transportListener;
 
+    /**
+     * Returns the current transport listener
+     */
     public TransportListener getTransportListener() {
         return transportListener;
     }
@@ -89,6 +94,15 @@
     public void onException(IOException e) {
         if (transportListener != null) {
             transportListener.onException(e);
+        }
+    }
+
+    protected void checkStarted(Command command) throws IOException {
+        if (!isStarted()) {
+            // we might try to shut down the transport before it was ever started in some
test cases
+            if (!(command instanceof ShutdownInfo || command instanceof RemoveInfo)) {
+                throw new IOException("The transport " + this + " of type: " + getClass().getName()
+ " is not running.");
+            }
         }
     }
 

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportThreadSupport.java
Wed Mar  8 06:10:27 2006
@@ -16,11 +16,7 @@
  */
 package org.apache.activemq.transport;
 
-import org.apache.activemq.command.Command;
-import org.apache.activemq.command.RemoveInfo;
-import org.apache.activemq.command.ShutdownInfo;
 
-import java.io.IOException;
 
 /**
  * A useful base class for a transport implementation which has a background
@@ -45,14 +41,5 @@
         runner = new Thread(this, toString());
         runner.setDaemon(daemon);
         runner.start();
-    }
-
-    protected void checkStarted(Command command) throws IOException {
-        if (!isStarted()) {
-            // we might try to shut down the transport before it was ever started in some
test cases
-            if (!(command instanceof ShutdownInfo || command instanceof RemoveInfo)) {
-                throw new IOException("The transport " + this + " of type: " + getClass().getName()
+ " is not running.");
-            }
-        }
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/WireFormatNegotiator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/WireFormatNegotiator.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/WireFormatNegotiator.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/WireFormatNegotiator.java
Wed Mar  8 06:10:27 2006
@@ -90,9 +90,9 @@
             }
             
             if( !info.isValid() ) {
-                commandListener.onException(new IOException("Remote wire format magic is
invalid"));
+                getTransportListener().onException(new IOException("Remote wire format magic
is invalid"));
             } else if( info.getVersion() < minimumVersion ) {
-                commandListener.onException(new IOException("Remote wire format ("+info.getVersion()+")
is lower the minimum version required ("+minimumVersion+")"));
+                getTransportListener().onException(new IOException("Remote wire format ("+info.getVersion()+")
is lower the minimum version required ("+minimumVersion+")"));
             } else if ( info.getVersion()!=wireFormat.getVersion() ) {
                 // Match the remote side.
                 wireFormat.setVersion(info.getVersion());
@@ -115,14 +115,14 @@
                         ((OpenWireFormat)wireFormat).setTightEncodingEnabled(false);
                     }
                 } catch (IOException e) {
-                    commandListener.onException(e);
+                    getTransportListener().onException(e);
                 }
             }
                 
             readyCountDownLatch.countDown();
             
         }
-        commandListener.onCommand(command);
+        getTransportListener().onCommand(command);
     }
     
     public String toString() {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
Wed Mar  8 06:10:27 2006
@@ -443,6 +443,10 @@
         return l;
     }
 
+    public TransportListener getTransportListener() {
+        return transportListener;
+    }
+
     public void setTransportListener(TransportListener commandListener) {
         this.transportListener = commandListener;
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/fanout/FanoutTransport.java
Wed Mar  8 06:10:27 2006
@@ -428,6 +428,10 @@
         }
     }
 
+    public TransportListener getTransportListener() {
+        return transportListener;
+    }
+
     public void setTransportListener(TransportListener commandListener) {
         this.transportListener = commandListener;
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/mock/MockTransport.java
Wed Mar  8 06:10:27 2006
@@ -33,7 +33,7 @@
 public class MockTransport extends DefaultTransportListener implements Transport {
 
     protected Transport next;
-    protected TransportListener commandListener;
+    protected TransportListener transportListener;
 
     public MockTransport(Transport next) {
         this.next = next;
@@ -42,7 +42,7 @@
     /**
      */
     synchronized public void setTransportListener(TransportListener channelListener) {
-        this.commandListener = channelListener;
+        this.transportListener = channelListener;
         if (channelListener == null)
             next.setTransportListener(null);
         else
@@ -57,7 +57,7 @@
     public void start() throws Exception {
         if( next == null )
             throw new IOException("The next channel has not been set.");
-        if( commandListener == null )
+        if( transportListener == null )
             throw new IOException("The command listener has not been set.");
         next.start();
     }
@@ -70,7 +70,7 @@
     }    
 
     synchronized public void onCommand(Command command) {
-        commandListener.onCommand(command);
+        transportListener.onCommand(command);
     }
 
     /**
@@ -83,8 +83,8 @@
     /**
      * @return Returns the packetListener.
      */
-    synchronized public TransportListener getCommandListener() {
-        return commandListener;
+    synchronized public TransportListener getTransportListener() {
+        return transportListener;
     }
     
     synchronized public String toString() {
@@ -104,7 +104,7 @@
     }
 
     synchronized public void onException(IOException error) {
-        commandListener.onException(error);
+        transportListener.onException(error);
     }
 
     synchronized public Object narrow(Class target) {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
Wed Mar  8 06:10:27 2006
@@ -131,7 +131,7 @@
      */
     public void run() {
         log.trace("TCP consumer thread starting");
-        while (!isClosed()) {
+        while (!isStopped()) {
             try {
                 Command command = (Command) wireFormat.unmarshal(dataIn);
                 doConsume(command);

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
Wed Mar  8 06:10:27 2006
@@ -118,12 +118,12 @@
      * pull Sockets from the ServerSocket
      */
     public void run() {
-        while (!isClosed()) {
+        while (!isStopped()) {
             Socket socket = null;
             try {
                 socket = serverSocket.accept();
                 if (socket != null) {
-                    if (isClosed() || getAcceptListener() == null) {
+                    if (isStopped() || getAcceptListener() == null) {
                         socket.close();
                     }
                     else {
@@ -142,9 +142,9 @@
                 // expect this to happen
             }
             catch (Exception e) {
-                if (!isClosing()) {
+                if (!isStopping()) {
                     onAcceptError(e); 
-                } else if (!isClosed()) {
+                } else if (!isStopped()) {
                     log.warn("run()", e);
                     onAcceptError(e);
                 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
Wed Mar  8 06:10:27 2006
@@ -87,6 +87,10 @@
         throw new AssertionError("Unsupported Method");
     }
 
+    public synchronized TransportListener getTransportListener() {
+        return transportListener;
+    }
+
     synchronized public void setTransportListener(TransportListener commandListener){
         this.transportListener=commandListener;
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ServiceSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ServiceSupport.java?rev=384220&r1=384219&r2=384220&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ServiceSupport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ServiceSupport.java
Wed Mar  8 06:10:27 2006
@@ -30,9 +30,9 @@
 public abstract class ServiceSupport {
     private static final Log log = LogFactory.getLog(ServiceSupport.class);
 
-    private AtomicBoolean closed = new AtomicBoolean(false);
     private AtomicBoolean started = new AtomicBoolean(false);
-    private AtomicBoolean closing = new AtomicBoolean(false);
+    private AtomicBoolean stopping = new AtomicBoolean(false);
+    private AtomicBoolean stopped = new AtomicBoolean(false);
 
     public static void dispose(Service service) {
         try {
@@ -50,8 +50,8 @@
     }
 
     public void stop() throws Exception {
-        if (closed.compareAndSet(false, true)) {
-            closing.set(true);
+        if (stopped.compareAndSet(false, true)) {
+            stopping.set(true);
             ServiceStopper stopper = new ServiceStopper();
             try {
                 doStop(stopper);
@@ -59,9 +59,9 @@
             catch (Exception e) {
                 stopper.onException(this, e);
             }
-            closed.set(true);
+            stopped.set(true);
             started.set(false);
-            closing.set(false);
+            stopping.set(false);
             stopper.throwFirstException();
         }
     }
@@ -76,16 +76,16 @@
     /**
      * @return true if this service is in the process of closing
      */
-    public boolean isClosing() {
-        return closing.get();
+    public boolean isStopping() {
+        return stopping.get();
     }
 
     
     /**
      * @return true if this service is closed
      */
-    public boolean isClosed() {
-        return closed.get();
+    public boolean isStopped() {
+        return stopped.get();
     }
 
     protected abstract void doStop(ServiceStopper stopper) throws Exception;



Mime
View raw message