summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2012-05-10 20:23:11 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2012-05-10 20:23:11 +0000
commit0d23b30fea253e99723063658fadf70b74779fc5 (patch)
tree3d22a44edc6e35863a2c754821018aacd2f22cd2
parentbe86bed3bc86cbf9bc52ba9325972757b744ffa0 (diff)
downloadqpid-python-0d23b30fea253e99723063658fadf70b74779fc5.tar.gz
QPID-3401 Node and Link objects are now immutable once they are
initialized. All maps/lists returned by them are wrapped with unmodifiable map/lists. All setter methods will throw an exception once they are marked read-only. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1336878 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java18
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java2
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java2
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java8
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java56
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java69
6 files changed, 92 insertions, 63 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java
index d9d837a07e..9356a13153 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java
@@ -57,15 +57,11 @@ public class DestinationStringParser
public static DestSyntax getSyntaxType(String s)
{
- if ((BURL_STR).equals(s))
+ try
{
- return BURL;
+ return Enum.valueOf(DestSyntax.class, s.toUpperCase());
}
- else if ((ADDR_STR).equals(s))
- {
- return ADDR;
- }
- else
+ catch (IllegalArgumentException e)
{
throw new IllegalArgumentException("Invalid Destination Syntax Type" +
" should be one of {BURL|ADDR}");
@@ -172,6 +168,7 @@ public class DestinationStringParser
node.setDeclareProps(helper.getNodeDeclareArgs());
node.setBindingProps(helper.getNodeBindings());
addr.setNode(node);
+ node.markReadOnly();
Link link = new Link();
link.setName(helper.getLinkName());
@@ -183,6 +180,7 @@ public class DestinationStringParser
link.setBindingProps(helper.getLinkBindings());
link.setSubscribeProps(helper.getLinkSubscribeArgs());
addr.setLink(link);
+ link.markReadOnly();
addr.markReadOnly();
return addr;
@@ -241,7 +239,13 @@ public class DestinationStringParser
node.setAssertPolicy(AddressPolicy.NEVER);
node.setCreatePolicy(AddressPolicy.RECEIVER);
node.setDeletePolicy(AddressPolicy.NEVER);
+ node.markReadOnly();
+ addr.setNode(node);
+ link.markReadOnly();
+ addr.setLink(link);
+
+ addr.markReadOnly();
return addr;
}
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
index de5014c7bc..d5d2260a9e 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
@@ -56,7 +56,7 @@ public class QpidQueue extends QpidDestination implements Queue
return true;
}
- if (!(obj instanceof QpidQueue))
+ if(obj.getClass() != getClass())
{
return false;
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
index c0ce5077e2..911c1a4c07 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
@@ -54,7 +54,7 @@ public class QpidTopic extends QpidDestination implements Topic
return true;
}
- if (!(obj instanceof QpidTopic))
+ if(obj.getClass() != getClass())
{
return false;
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java
index 403dbf72c9..8edf07d7ee 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java
@@ -20,15 +20,15 @@
*/
package org.apache.qpid.messaging;
-import org.apache.qpid.messaging.address.Link;
-import org.apache.qpid.messaging.address.Node;
-import org.apache.qpid.messaging.util.AddressParser;
-
import static org.apache.qpid.messaging.util.PyPrint.pprint;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.qpid.messaging.address.Link;
+import org.apache.qpid.messaging.address.Node;
+import org.apache.qpid.messaging.util.AddressParser;
+
/**
* Address
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java
index 6e39911718..491f2f9bab 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java
@@ -25,6 +25,7 @@ import static org.apache.qpid.messaging.address.Link.Reliability.AT_LEAST_ONCE;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
public class Link
{
@@ -35,27 +36,21 @@ public class Link
public enum Reliability
{
- UNRELIABLE, AT_MOST_ONCE, AT_LEAST_ONCE, EXACTLY_ONCE;
+ UNRELIABLE, AT_LEAST_ONCE;
- public static Reliability getReliability(String reliability)
+ public static Reliability getReliability(String str)
throws AddressException
{
- if (reliability == null)
+ try
{
- return AT_LEAST_ONCE;
+ return str == null ? AT_LEAST_ONCE : Enum.valueOf(Reliability.class, str.toUpperCase());
}
- else if (reliability.equalsIgnoreCase("unreliable"))
+ catch (IllegalArgumentException e)
{
- return UNRELIABLE;
- }
- else if (reliability.equalsIgnoreCase("at-least-once"))
- {
- return AT_LEAST_ONCE;
- }
- else
- {
- throw new AddressException("The reliability mode '"
- + reliability + "' is not yet supported");
+ throw new AddressException((new StringBuffer("The reliability mode")
+ .append(" '").append(str).append("' ")
+ .append("is not yet supported, supported.")
+ .append("Supported types are { UNRELIABLE, AT_LEAST_ONCE }.")).toString());
}
}
}
@@ -73,6 +68,8 @@ public class Link
private List<Object> _xBindingProps = Collections.emptyList();
private Map<String, Object> _xSubscribeProps = Collections.emptyMap();
+ private AtomicBoolean readOnly = new AtomicBoolean(false);
+
public Reliability getReliability()
{
return _reliability;
@@ -115,72 +112,95 @@ public class Link
public Map<String, Object> getDeclareProperties()
{
- return _xDeclareProps;
+ return Collections.unmodifiableMap(_xDeclareProps);
}
public List<Object> getBindingProperties()
{
- return _xBindingProps;
+ return Collections.unmodifiableList(_xBindingProps);
}
public Map<String, Object> getSubscribeProperties()
{
- return _xSubscribeProps;
+ return Collections.unmodifiableMap(_xSubscribeProps);
}
public void setName(String name)
{
+ checkReadOnly();
this.name = name;
}
public void setFilter(String filter)
{
+ checkReadOnly();
this._filter = filter;
}
public void setFilterType(FilterType filterType)
{
+ checkReadOnly();
this._filterType = filterType;
}
public void setNoLocal(boolean noLocal)
{
+ checkReadOnly();
this._noLocal = noLocal;
}
public void setDurable(boolean durable)
{
+ checkReadOnly();
this._durable = durable;
}
public void setConsumerCapacity(int consumerCapacity)
{
+ checkReadOnly();
this._consumerCapacity = consumerCapacity;
}
public void setProducerCapacity(int producerCapacity)
{
+ checkReadOnly();
this._producerCapacity = producerCapacity;
}
public void setReliability(Reliability reliability)
{
+ checkReadOnly();
this._reliability = reliability;
}
public void setDeclareProps(Map<String, Object> xDeclareProps)
{
+ checkReadOnly();
this._xDeclareProps = xDeclareProps;
}
public void setBindingProps(List<Object> xBindingProps)
{
+ checkReadOnly();
this._xBindingProps = xBindingProps;
}
public void setSubscribeProps(Map<String, Object> xSubscribeProps)
{
+ checkReadOnly();
this._xSubscribeProps = xSubscribeProps;
}
+ public void checkReadOnly()
+ {
+ if (readOnly.get())
+ {
+ throw new IllegalArgumentException("Once initialized the Link object is immutable");
+ }
+ }
+
+ public void markReadOnly()
+ {
+ readOnly.set(true);
+ }
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java
index a606e0559e..a909fee675 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java
@@ -23,8 +23,7 @@ package org.apache.qpid.messaging.address;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-
-import org.apache.qpid.messaging.address.Link.Reliability;
+import java.util.concurrent.atomic.AtomicBoolean;
public class Node
{
@@ -35,26 +34,15 @@ public class Node
public static AddressPolicy getAddressPolicy(String policy)
throws AddressException
{
- if (policy == null || policy.equalsIgnoreCase("never"))
- {
- return NEVER;
- }
- else if (policy.equalsIgnoreCase("always"))
- {
- return ALWAYS;
- }
- else if (policy.equalsIgnoreCase("sender"))
+ try
{
- return SENDER;
+ return policy == null ? NEVER : Enum.valueOf(AddressPolicy.class, policy.toUpperCase());
}
- else if (policy.equalsIgnoreCase("receiver"))
+ catch (IllegalArgumentException e)
{
- return RECEIVER;
- }
- else
- {
- throw new AddressException("Invalid address policy type : '"
- + policy + "'");
+ throw new AddressException ((new StringBuffer("Invalid address policy")
+ .append(" '").append(policy).append("' ")
+ .append("Valid policy types are { NEVER, ALWAYS, SENDER, RECEIVER}.")).toString());
}
}
};
@@ -65,20 +53,15 @@ public class Node
public static NodeType getNodeType(String type) throws AddressException
{
- if (type == null)
- {
- return QUEUE; // defaults to queue
- }
- else if (type.equalsIgnoreCase("queue"))
+ try
{
- return QUEUE;
+ return type == null ? QUEUE : Enum.valueOf(NodeType.class, type.toUpperCase());
}
- else if (type.equalsIgnoreCase("topic"))
+ catch (IllegalArgumentException e)
{
- return TOPIC;
- }else
- {
- throw new AddressException("Invalid node type : '" + type + "'");
+ throw new AddressException ((new StringBuffer("Invalid node type")
+ .append(" '").append(type).append("' ")
+ .append("Valid node types are { QUEUE, TOPIC }.")).toString());
}
}
};
@@ -94,6 +77,7 @@ public class Node
private Map<String, Object> _xDeclareProps = Collections.emptyMap();
private List<Object> _xBindingProps = Collections.emptyList();
+ private AtomicBoolean readOnly = new AtomicBoolean(false);
public String getName()
{
@@ -127,51 +111,72 @@ public class Node
public Map<String, Object> getDeclareProperties()
{
- return _xDeclareProps;
+ return Collections.unmodifiableMap(_xDeclareProps);
}
public List<Object> getBindingProperties()
{
- return _xBindingProps;
+ return Collections.unmodifiableList(_xBindingProps);
}
public void setName(String name)
{
+ checkReadOnly();
this.name = name;
}
public void setDurable(boolean durable)
{
+ checkReadOnly();
this._durable = durable;
}
public void setType(NodeType type)
{
+ checkReadOnly();
this._type = type;
}
public void setCreatePolicy(AddressPolicy createPolicy)
{
+ checkReadOnly();
this._createPolicy = createPolicy;
}
public void setAssertPolicy(AddressPolicy assertPolicy)
{
+ checkReadOnly();
this._assertPolicy = assertPolicy;
}
public void setDeletePolicy(AddressPolicy deletePolicy)
{
+ checkReadOnly();
this._deletePolicy = deletePolicy;
}
public void setDeclareProps(Map<String, Object> xDeclareProps)
{
+ checkReadOnly();
this._xDeclareProps = xDeclareProps;
}
public void setBindingProps(List<Object> xBindingProps)
{
+ checkReadOnly();
this._xBindingProps = xBindingProps;
}
+
+ public void checkReadOnly()
+ {
+ if (readOnly.get())
+ {
+ throw new IllegalArgumentException("Once initialized the Link object is immutable");
+ }
+ }
+
+ public void markReadOnly()
+ {
+ readOnly.set(true);
+ }
} \ No newline at end of file