diff options
author | Keith Wall <kwall@apache.org> | 2014-07-20 14:39:35 +0000 |
---|---|---|
committer | Keith Wall <kwall@apache.org> | 2014-07-20 14:39:35 +0000 |
commit | 02291ffa8f75a05c118f8031263cec14d55bf894 (patch) | |
tree | ffac47229951baebf3054c355b32e83e12d932b8 /java | |
parent | d2930a2952a59aec97c2971f1aa55019feeb94ae (diff) | |
download | qpid-python-02291ffa8f75a05c118f8031263cec14d55bf894.tar.gz |
QPID-2969: Make AMQConnectionFactory and AMQDestination (and subclasses) serializable
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1612097 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
18 files changed, 369 insertions, 25 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java index c324e22ab1..30f92c8e5e 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java b/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java index 25d37aafb1..a659e44363 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java index a2d4b5ee17..e9580eff7e 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java index d59f48542f..2e256b1f57 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java index 6c421a9610..e06fc0f1de 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java b/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java index 714c38d37b..d4bf6440b4 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java b/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java index 0f375e4921..f65ecece2b 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java index 11145e17b2..263dfa6827 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java index db54b320dc..9163583364 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java b/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java index 4cc32022dc..d5724a2910 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java index ec9c595f99..b9099145d5 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQUndefinedDestination.java +++ b/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/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java index fef9769d06..d9d2cf85d3 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java +++ b/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), diff --git a/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java index bb92fa4ecd..6c6aa04ec1 100644 --- a/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java +++ b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java @@ -20,6 +20,12 @@ */ package org.apache.qpid.client; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + import javax.jms.JMSException; import junit.framework.TestCase; @@ -76,4 +82,25 @@ public class AMQConnectionFactoryTest extends TestCase assertEquals("Unexpected exception", AMQConnectionFactory.NO_URL_CONFIGURED, e.getMessage()); } } + + public void testSerialization() throws Exception + { + AMQConnectionFactory factory = new AMQConnectionFactory(); + assertTrue(factory instanceof Serializable); + factory.setConnectionURLString("amqp://guest:guest@clientID/test?brokerlist='tcp://localhost:5672'"); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(factory); + oos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + Object deserializedObject = ois.readObject(); + ois.close(); + + AMQConnectionFactory deserialisedFactory = (AMQConnectionFactory) deserializedObject; + assertEquals(factory, deserialisedFactory); + assertEquals(factory.hashCode(), deserialisedFactory.hashCode()); + } } diff --git a/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java b/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java index 6433c9acb7..a494192148 100644 --- a/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java +++ b/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java @@ -20,10 +20,19 @@ */ package org.apache.qpid.client; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import javax.jms.Destination; +import javax.jms.Queue; +import javax.jms.Topic; + import junit.framework.TestCase; public class AMQDestinationTest extends TestCase @@ -132,11 +141,12 @@ public class AMQDestinationTest extends TestCase assertEmptyLinkBindingsAndSubscriptionArgs(new AMQAnyDestination(xSubscribeAddr)); } - private void assertEmptyLinkBindingsAndSubscriptionArgs(AMQDestination dest) { + private void assertEmptyLinkBindingsAndSubscriptionArgs(AMQDestination dest) + { assertEquals("Default link subscription arguments should be the constant Collections empty map.", Collections.emptyMap(), dest.getLink().getSubscription().getArgs()); assertSame("Defaultl link bindings should be the constant Collections empty list.", - Collections.emptyList(), dest.getLink().getBindings()); + Collections.emptyList(), dest.getLink().getBindings()); } /** @@ -152,10 +162,69 @@ public class AMQDestinationTest extends TestCase assertEmptyNodeBindings(new AMQAnyDestination("ADDR:testDest3; {node: {type: topic}}")); } + public void testSerializeAMQQueue_BURL() throws Exception + { + Queue queue = new AMQQueue("BURL:direct://amq.direct/test-route/Foo?routingkey='Foo'"); + assertTrue(queue instanceof Serializable); + + Queue deserialisedQueue = (Queue) serialiseDeserialiseDestination(queue); + + assertEquals(queue, deserialisedQueue); + assertEquals(queue.hashCode(), deserialisedQueue.hashCode()); + } + + public void testSerializeAMQQueue_ADDR() throws Exception + { + Queue queue = new AMQQueue("ADDR:testDest2; {node: {type: queue}}"); + assertTrue(queue instanceof Serializable); + + Queue deserialisedQueue = (Queue) serialiseDeserialiseDestination(queue); + + assertEquals(queue, deserialisedQueue); + assertEquals(queue.hashCode(), deserialisedQueue.hashCode()); + } + + public void testSerializeAMQTopic_BURL() throws Exception + { + Topic topic = new AMQTopic("BURL:topic://amq.topic/mytopic/?routingkey='mytopic'"); + assertTrue(topic instanceof Serializable); + + Topic deserialisedTopic = (Topic) serialiseDeserialiseDestination(topic); + + assertEquals(topic, deserialisedTopic); + assertEquals(topic.hashCode(), deserialisedTopic.hashCode()); + } + + public void testSerializeAMQTopic_ADDR() throws Exception + { + Topic topic = new AMQTopic("ADDR:my-topic; {assert: always, node:{ type: topic }}"); + assertTrue(topic instanceof Serializable); + + Topic deserialisedTopic = (Topic) serialiseDeserialiseDestination(topic); + + assertEquals(topic, deserialisedTopic); + assertEquals(topic.hashCode(), deserialisedTopic.hashCode()); + } + private void assertEmptyNodeBindings(AMQDestination dest) { assertSame("Empty node bindings should refer to the constant Collections empty list.", Collections.emptyList(), dest.getNode().getBindings()); } + private Destination serialiseDeserialiseDestination(final Destination dest) throws Exception + { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(dest); + oos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + Object deserializedObject = ois.readObject(); + ois.close(); + return (Destination)deserializedObject; + } + + } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java index 7f2288ea3d..c14ea3a101 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java @@ -20,6 +20,12 @@ */ package org.apache.qpid.test.unit.client.connectionurl; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + import junit.framework.TestCase; import org.apache.qpid.client.AMQBrokerDetails; @@ -620,5 +626,29 @@ public class ConnectionURLTest extends TestCase assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND))); } + + public void testSerialization() throws Exception + { + String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672'"; + ConnectionURL connectionurl = new AMQConnectionURL(url); + + + assertTrue(connectionurl instanceof Serializable); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(connectionurl); + oos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + Object deserializedObject = ois.readObject(); + ois.close(); + + ConnectionURL deserialisedConnectionUrl = (AMQConnectionURL) deserializedObject; + assertEquals(connectionurl, deserialisedConnectionUrl); + assertEquals(connectionurl.hashCode(), deserialisedConnectionUrl.hashCode()); + + } } diff --git a/java/common/src/main/java/org/apache/qpid/messaging/Address.java b/java/common/src/main/java/org/apache/qpid/messaging/Address.java index bccae8e671..92cf1c91d5 100644 --- a/java/common/src/main/java/org/apache/qpid/messaging/Address.java +++ b/java/common/src/main/java/org/apache/qpid/messaging/Address.java @@ -24,6 +24,7 @@ import org.apache.qpid.messaging.util.AddressParser; import static org.apache.qpid.messaging.util.PyPrint.pprint; +import java.io.Serializable; import java.util.Map; @@ -32,9 +33,11 @@ import java.util.Map; * */ -public class Address +public class Address implements Serializable { + private static final long serialVersionUID = 6096143531336726036L; + private String _name; private String _subject; private Map _options; diff --git a/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidQueueImpl.java b/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidQueueImpl.java index 162099d1ee..e313ba4b0a 100644 --- a/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidQueueImpl.java +++ b/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidQueueImpl.java @@ -33,6 +33,7 @@ import org.apache.qpid.client.AMQQueue; public class QpidQueueImpl extends AMQQueue implements QpidQueue, Externalizable { + private static final long serialVersionUID = 7952672727182960611L; private String _url; public QpidQueueImpl() @@ -71,6 +72,7 @@ public class QpidQueueImpl extends AMQQueue implements QpidQueue, Externalizable return this._url; } + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this._url = (String)in.readObject(); @@ -86,6 +88,7 @@ public class QpidQueueImpl extends AMQQueue implements QpidQueue, Externalizable } } + @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this._url); diff --git a/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidTopicImpl.java b/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidTopicImpl.java index 8ac1a679ea..37e3c1a3ce 100644 --- a/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidTopicImpl.java +++ b/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidTopicImpl.java @@ -34,6 +34,7 @@ import org.apache.qpid.ra.inflow.QpidActivation; public class QpidTopicImpl extends AMQTopic implements QpidTopic, Externalizable { + private static final long serialVersionUID = -2872685901706214228L; private String _url; public QpidTopicImpl() @@ -71,6 +72,7 @@ public class QpidTopicImpl extends AMQTopic implements QpidTopic, Externalizable return this._url; } + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this._url = (String)in.readObject(); @@ -86,6 +88,7 @@ public class QpidTopicImpl extends AMQTopic implements QpidTopic, Externalizable } } + @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(this._url); |