summaryrefslogtreecommitdiff
path: root/qpid/java/client/src/main
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2014-07-20 14:39:35 +0000
committerKeith Wall <kwall@apache.org>2014-07-20 14:39:35 +0000
commitd9653e77fa93275cb9782581796d0a3bcf39b569 (patch)
treeb2e2387c3c7c5420d29f29dc1220a7f201c83512 /qpid/java/client/src/main
parentcd126b93a9ec0b3891e19a2b3012e5ccc222cbbd (diff)
downloadqpid-python-d9653e77fa93275cb9782581796d0a3bcf39b569.tar.gz
QPID-2969: Make AMQConnectionFactory and AMQDestination (and subclasses) serializable
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1612097 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src/main')
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java2
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java5
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java43
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java129
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java54
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java2
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java4
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java3
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java1
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java4
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java1
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java5
12 files changed, 231 insertions, 22 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java
index c324e22ab1..30f92c8e5e 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java
@@ -40,6 +40,8 @@ import java.net.URISyntaxException;
*/
public class AMQAnyDestination extends AMQDestination implements Queue, Topic
{
+ private static final long serialVersionUID = 2853054849716163231L;
+
protected AMQAnyDestination()
{
super();
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
index 25d37aafb1..a659e44363 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
@@ -25,13 +25,16 @@ import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.url.URLHelper;
import org.apache.qpid.url.URLSyntaxException;
+import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
-public class AMQBrokerDetails implements BrokerDetails
+public class AMQBrokerDetails implements BrokerDetails, Serializable
{
+ private static final long serialVersionUID = 8450786374975932890L;
+
private String _host;
private int _port;
private String _transport;
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
index a2d4b5ee17..e9580eff7e 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
@@ -45,6 +45,8 @@ import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
+
+import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
@@ -53,10 +55,11 @@ import java.util.UUID;
public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory,
ObjectFactory, Referenceable, XATopicConnectionFactory,
- XAQueueConnectionFactory, XAConnectionFactory
+ XAQueueConnectionFactory, XAConnectionFactory, Serializable
{
protected static final String NO_URL_CONFIGURED = "The connection factory wasn't created with a proper URL, the connection details are empty";
+
private ConnectionURL _connectionDetails;
// The default constructor is necessary to allow AMQConnectionFactory to be deserialised from JNDI
@@ -412,4 +415,42 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
{
return (XAQueueConnection) createXAConnection(username, password);
}
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ final AMQConnectionFactory that = (AMQConnectionFactory) o;
+
+ if (_connectionDetails != null
+ ? !_connectionDetails.equals(that._connectionDetails)
+ : that._connectionDetails != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _connectionDetails != null ? _connectionDetails.hashCode() : 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "AMQConnectionFactory{" +
+ "_connectionDetails=" + _connectionDetails +
+ '}';
+ }
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
index d59f48542f..2e256b1f57 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
@@ -27,13 +27,16 @@ import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.url.URLHelper;
import org.apache.qpid.url.URLSyntaxException;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-public class AMQConnectionURL implements ConnectionURL
+public class AMQConnectionURL implements ConnectionURL, Serializable
{
+ private static final long serialVersionUID = -5102704772070465832L;
+
private String _url;
private String _failoverMethod;
private Map<String, String> _failoverOptions;
@@ -43,10 +46,10 @@ public class AMQConnectionURL implements ConnectionURL
private String _username;
private String _password;
private String _virtualHost;
- private AMQShortString _defaultQueueExchangeName;
- private AMQShortString _defaultTopicExchangeName;
- private AMQShortString _temporaryTopicExchangeName;
- private AMQShortString _temporaryQueueExchangeName;
+ private String _defaultQueueExchangeName;
+ private String _defaultTopicExchangeName;
+ private String _temporaryTopicExchangeName;
+ private String _temporaryQueueExchangeName;
public AMQConnectionURL(String fullURL) throws URLSyntaxException
{
@@ -183,47 +186,145 @@ public class AMQConnectionURL implements ConnectionURL
public AMQShortString getDefaultQueueExchangeName()
{
- return _defaultQueueExchangeName;
+ return _defaultQueueExchangeName == null ? null : new AMQShortString(_defaultQueueExchangeName);
}
public void setDefaultQueueExchangeName(AMQShortString defaultQueueExchangeName)
{
- _defaultQueueExchangeName = defaultQueueExchangeName;
+ _defaultQueueExchangeName = defaultQueueExchangeName == null ? null : defaultQueueExchangeName.asString();
}
public AMQShortString getDefaultTopicExchangeName()
{
- return _defaultTopicExchangeName;
+ return _defaultTopicExchangeName == null ? null : new AMQShortString(_defaultTopicExchangeName);
}
public void setDefaultTopicExchangeName(AMQShortString defaultTopicExchangeName)
{
- _defaultTopicExchangeName = defaultTopicExchangeName;
+ _defaultTopicExchangeName = defaultTopicExchangeName == null ? null : defaultTopicExchangeName.asString();
}
public AMQShortString getTemporaryQueueExchangeName()
{
- return _temporaryQueueExchangeName;
+ return _temporaryQueueExchangeName == null ? null : new AMQShortString(_temporaryQueueExchangeName);
}
public void setTemporaryQueueExchangeName(AMQShortString temporaryQueueExchangeName)
{
- _temporaryQueueExchangeName = temporaryQueueExchangeName;
+ _temporaryQueueExchangeName = temporaryQueueExchangeName == null ? null : temporaryQueueExchangeName.asString();
}
public AMQShortString getTemporaryTopicExchangeName()
{
- return _temporaryTopicExchangeName;
+ return _temporaryTopicExchangeName == null ? null : new AMQShortString(_temporaryTopicExchangeName);
}
public void setTemporaryTopicExchangeName(AMQShortString temporaryTopicExchangeName)
{
- _temporaryTopicExchangeName = temporaryTopicExchangeName;
+ _temporaryTopicExchangeName = temporaryTopicExchangeName == null ? null : temporaryTopicExchangeName.asString() ;
+ }
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ final AMQConnectionURL that = (AMQConnectionURL) o;
+
+ if (_brokers != null ? !_brokers.equals(that._brokers) : that._brokers != null)
+ {
+ return false;
+ }
+ if (_clientName != null ? !_clientName.equals(that._clientName) : that._clientName != null)
+ {
+ return false;
+ }
+ if (_defaultQueueExchangeName != null
+ ? !_defaultQueueExchangeName.equals(that._defaultQueueExchangeName)
+ : that._defaultQueueExchangeName != null)
+ {
+ return false;
+ }
+ if (_defaultTopicExchangeName != null
+ ? !_defaultTopicExchangeName.equals(that._defaultTopicExchangeName)
+ : that._defaultTopicExchangeName != null)
+ {
+ return false;
+ }
+ if (_failoverMethod != null ? !_failoverMethod.equals(that._failoverMethod) : that._failoverMethod != null)
+ {
+ return false;
+ }
+ if (_failoverOptions != null ? !_failoverOptions.equals(that._failoverOptions) : that._failoverOptions != null)
+ {
+ return false;
+ }
+ if (_options != null ? !_options.equals(that._options) : that._options != null)
+ {
+ return false;
+ }
+ if (_password != null ? !_password.equals(that._password) : that._password != null)
+ {
+ return false;
+ }
+ if (_temporaryQueueExchangeName != null
+ ? !_temporaryQueueExchangeName.equals(that._temporaryQueueExchangeName)
+ : that._temporaryQueueExchangeName != null)
+ {
+ return false;
+ }
+ if (_temporaryTopicExchangeName != null
+ ? !_temporaryTopicExchangeName.equals(that._temporaryTopicExchangeName)
+ : that._temporaryTopicExchangeName != null)
+ {
+ return false;
+ }
+ if (_url != null ? !_url.equals(that._url) : that._url != null)
+ {
+ return false;
+ }
+ if (_username != null ? !_username.equals(that._username) : that._username != null)
+ {
+ return false;
+ }
+ if (_virtualHost != null ? !_virtualHost.equals(that._virtualHost) : that._virtualHost != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = _url != null ? _url.hashCode() : 0;
+ result = 31 * result + (_failoverMethod != null ? _failoverMethod.hashCode() : 0);
+ result = 31 * result + (_failoverOptions != null ? _failoverOptions.hashCode() : 0);
+ result = 31 * result + (_options != null ? _options.hashCode() : 0);
+ result = 31 * result + (_brokers != null ? _brokers.hashCode() : 0);
+ result = 31 * result + (_clientName != null ? _clientName.hashCode() : 0);
+ result = 31 * result + (_username != null ? _username.hashCode() : 0);
+ result = 31 * result + (_password != null ? _password.hashCode() : 0);
+ result = 31 * result + (_virtualHost != null ? _virtualHost.hashCode() : 0);
+ result = 31 * result + (_defaultQueueExchangeName != null ? _defaultQueueExchangeName.hashCode() : 0);
+ result = 31 * result + (_defaultTopicExchangeName != null ? _defaultTopicExchangeName.hashCode() : 0);
+ result = 31 * result + (_temporaryTopicExchangeName != null ? _temporaryTopicExchangeName.hashCode() : 0);
+ result = 31 * result + (_temporaryQueueExchangeName != null ? _temporaryQueueExchangeName.hashCode() : 0);
+ return result;
}
+ @Override
public String toString()
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append(AMQ_PROTOCOL);
sb.append("://");
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
index 6c421a9610..e06fc0f1de 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
@@ -39,14 +39,20 @@ import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
-public abstract class AMQDestination implements Destination, Referenceable
+public abstract class AMQDestination implements Destination, Referenceable, Externalizable
{
private static final Logger _logger = LoggerFactory.getLogger(AMQDestination.class);
+ private static final long serialVersionUID = -3716263015355017537L;
private AMQShortString _exchangeName;
@@ -996,4 +1002,50 @@ public abstract class AMQDestination implements Destination, Referenceable
{
return _rejectBehaviour;
}
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException
+ {
+ out.writeObject(_destSyntax);
+ if (_destSyntax == DestSyntax.BURL)
+ {
+ out.writeObject(toURL());
+ }
+ else
+ {
+ out.writeObject(_address);
+ }
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ _destSyntax = (DestSyntax) in.readObject();
+ if (_destSyntax == DestSyntax.BURL)
+ {
+ String burl = (String) in.readObject();
+ final AMQBindingURL binding;
+ try
+ {
+ binding = new AMQBindingURL(burl);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new IllegalStateException("Cannot convert url " + burl + " into a BindingURL", e);
+ }
+ getInfoFromBindingURL(binding);
+ }
+ else
+ {
+ _address = (Address) in.readObject();
+ try
+ {
+ getInfoFromAddress();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Cannot convert get info from " + _address, e);
+ }
+ }
+ }
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java
index 714c38d37b..d4bf6440b4 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java
@@ -29,6 +29,8 @@ import org.apache.qpid.url.BindingURL;
*/
public class AMQHeadersExchange extends AMQDestination
{
+ private static final long serialVersionUID = 2187866678283988301L;
+
public AMQHeadersExchange(BindingURL binding)
{
super(binding);
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java
index 0f375e4921..f65ecece2b 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java
@@ -29,7 +29,9 @@ import java.net.URISyntaxException;
public class AMQQueue extends AMQDestination implements Queue
{
- protected AMQQueue()
+ private static final long serialVersionUID = -1283142598932655606L;
+
+ public AMQQueue()
{
super();
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
index 11145e17b2..263dfa6827 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
@@ -29,8 +29,7 @@ import java.util.UUID;
/** AMQ implementation of a TemporaryQueue. */
final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue, TemporaryDestination
{
-
-
+ private static final long serialVersionUID = -5457866720195625708L;
private final AMQSession _session;
private boolean _deleted;
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
index db54b320dc..9163583364 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
@@ -32,6 +32,7 @@ import java.util.UUID;
class AMQTemporaryTopic extends AMQTopic implements TemporaryTopic, TemporaryDestination
{
+ private static final long serialVersionUID = -4990099300883216207L;
private final AMQSession _session;
private boolean _deleted;
/**
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
index 4cc32022dc..d5724a2910 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
@@ -33,6 +33,8 @@ import java.net.URISyntaxException;
public class AMQTopic extends AMQDestination implements Topic
{
+ private static final long serialVersionUID = -4773561540716587036L;
+
public AMQTopic(String address) throws URISyntaxException
{
super(address);
@@ -43,7 +45,7 @@ public class AMQTopic extends AMQDestination implements Topic
super(address);
}
- protected AMQTopic()
+ public AMQTopic()
{
super();
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java
index ec9c595f99..b9099145d5 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java
@@ -26,6 +26,7 @@ public class AMQUndefinedDestination extends AMQDestination
{
private static final AMQShortString UNKNOWN_EXCHANGE_CLASS = new AMQShortString("unknown");
+ private static final long serialVersionUID = -1487224209485888847L;
public AMQUndefinedDestination(AMQShortString exchange, AMQShortString routingKey, AMQShortString queueName)
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java b/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java
index fef9769d06..d9d2cf85d3 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java
@@ -27,7 +27,6 @@ import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.AMQSession_0_8;
import org.apache.qpid.client.AMQTopic;
import org.apache.qpid.client.CustomJMSXProperty;
-import org.apache.qpid.client.JMSAMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.BasicContentHeaderProperties;
import org.apache.qpid.url.AMQBindingURL;
@@ -611,6 +610,8 @@ public class AMQMessageDelegate_0_8 extends AbstractAMQMessageDelegate
private static class DefaultRouterDestination extends AMQDestination implements Queue
{
+ private static final long serialVersionUID = -5042408431861384536L;
+
public DefaultRouterDestination(final String replyToEncoding)
{
super(AMQShortString.EMPTY_STRING,
@@ -634,6 +635,8 @@ public class AMQMessageDelegate_0_8 extends AbstractAMQMessageDelegate
private static class NonBURLReplyToDestination extends AMQDestination implements Queue
{
+ private static final long serialVersionUID = 122897705932489259L;
+
public NonBURLReplyToDestination(final String exchange, final String routingKey)
{
super(AMQShortString.valueOf(exchange),