From 1ccd7bdbf00e80046cf0275e3742cf62f41e27be Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 8 Mar 2006 14:30:48 +0000 Subject: [PATCH] Refactorings of the transport/service base classes git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@384222 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/BlockingQueueTransport.java | 9 +-- .../transport/http/HttpClientTransport.java | 2 +- .../transport/http/HttpTransport.java | 4 +- .../transport/http/HttpTransportServer.java | 56 ++++++++++--------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/activemq-optional/src/main/java/org/apache/activemq/transport/http/BlockingQueueTransport.java b/activemq-optional/src/main/java/org/apache/activemq/transport/http/BlockingQueueTransport.java index b817c83bea..a4138c4dff 100755 --- a/activemq-optional/src/main/java/org/apache/activemq/transport/http/BlockingQueueTransport.java +++ b/activemq-optional/src/main/java/org/apache/activemq/transport/http/BlockingQueueTransport.java @@ -21,6 +21,7 @@ import edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue; import org.apache.activemq.command.Command; import org.apache.activemq.transport.TransportSupport; +import org.apache.activemq.util.ServiceStopper; import javax.jms.JMSException; @@ -44,13 +45,13 @@ public class BlockingQueueTransport extends TransportSupport { return queue; } - public void start() throws JMSException { - } - public void oneway(Command command) throws IOException { queue.add(command); } - public void stop() throws Exception { + protected void doStart() throws Exception { } + + protected void doStop(ServiceStopper stopper) throws Exception { + } } diff --git a/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java b/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java index 2012178d60..ca144c86b6 100755 --- a/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java +++ b/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java @@ -94,7 +94,7 @@ public class HttpClientTransport extends HttpTransportSupport { log.trace("HTTP GET consumer thread starting: " + this); HttpClient httpClient = getReceiveHttpClient(); URI remoteUrl = getRemoteUrl(); - while (!isClosed()) { + while (!isStopped()) { GetMethod httpMethod = new GetMethod(remoteUrl.toString()); configureMethod(httpMethod); diff --git a/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java b/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java index 6141d26bc1..066c6b14f7 100755 --- a/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java +++ b/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java @@ -75,7 +75,7 @@ public class HttpTransport extends HttpTransportSupport { public void run() { log.trace("HTTP GET consumer thread starting for transport: " + this); URI remoteUrl = getRemoteUrl(); - while (!isClosed()) { + while (!isStopped()) { try { HttpURLConnection connection = getReceiveConnection(); int answer = connection.getResponseCode(); @@ -100,7 +100,7 @@ public class HttpTransport extends HttpTransportSupport { } } catch (Exception e) { - if (!isClosed()) { + if (!isStopped()) { log.warn("Failed to perform GET on: " + remoteUrl + " due to: " + e, e); } else { diff --git a/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java b/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java index 3da68884d0..3ca09026f1 100755 --- a/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java +++ b/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java @@ -20,6 +20,7 @@ import org.apache.activemq.command.BrokerInfo; import org.apache.activemq.transport.TransportServerSupport; import org.apache.activemq.transport.util.TextWireFormat; import org.apache.activemq.transport.xstream.XStreamWireFormat; +import org.apache.activemq.util.ServiceStopper; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; import org.mortbay.jetty.bio.SocketConnector; @@ -46,7 +47,33 @@ public class HttpTransportServer extends TransportServerSupport { this.bindAddress = uri; } - public void start() throws Exception { + public void setBrokerInfo(BrokerInfo brokerInfo) { + } + + // Properties + // ------------------------------------------------------------------------- + public TextWireFormat getWireFormat() { + if (wireFormat == null) { + wireFormat = createWireFormat(); + } + return wireFormat; + } + + public void setWireFormat(TextWireFormat wireFormat) { + this.wireFormat = wireFormat; + } + + // Implementation methods + // ------------------------------------------------------------------------- + protected TextWireFormat createWireFormat() { + return new XStreamWireFormat(); + } + + protected void setConnector(Connector connector) { + this.connector = connector; + } + + protected void doStart() throws Exception { server = new Server(); if (connector==null) connector = new SocketConnector(); @@ -81,7 +108,7 @@ public class HttpTransportServer extends TransportServerSupport { server.start(); } - public synchronized void stop() throws Exception { + protected void doStop(ServiceStopper stopper) throws Exception { Server temp = server; server = null; if (temp != null) { @@ -89,29 +116,4 @@ public class HttpTransportServer extends TransportServerSupport { } } - // Properties - // ------------------------------------------------------------------------- - public TextWireFormat getWireFormat() { - if (wireFormat == null) { - wireFormat = createWireFormat(); - } - return wireFormat; - } - - public void setWireFormat(TextWireFormat wireFormat) { - this.wireFormat = wireFormat; - } - - // Implementation methods - // ------------------------------------------------------------------------- - protected TextWireFormat createWireFormat() { - return new XStreamWireFormat(); - } - - protected void setConnector(Connector connector) { - this.connector = connector; - } - - public void setBrokerInfo(BrokerInfo brokerInfo) { - } }