From be86bed3bc86cbf9bc52ba9325972757b744ffa0 Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Wed, 9 May 2012 23:11:19 +0000 Subject: QPID-3401 Marked the Address object read-only once it's processed and the Node and Link data structures are populated. Marked member variables in Link and Node as private. Fixed leading/trailing spaces. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1336444 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/jms/DestinationStringParser.java | 1 + .../java/org/apache/qpid/messaging/Address.java | 27 +++++++-- .../org/apache/qpid/messaging/address/Link.java | 64 +++++++++++----------- .../org/apache/qpid/messaging/address/Node.java | 46 ++++++++-------- 4 files changed, 77 insertions(+), 61 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 1005aa83b8..d9d837a07e 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 @@ -184,6 +184,7 @@ public class DestinationStringParser link.setSubscribeProps(helper.getLinkSubscribeArgs()); addr.setLink(link); + addr.markReadOnly(); return addr; } 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 887800fc4c..403dbf72c9 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 @@ -27,6 +27,7 @@ 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; /** @@ -42,8 +43,9 @@ public class Address private Map _options; private final String _myToString; - private Node node; - private Link link; + private Node _node; + private Link _link; + private AtomicBoolean readOnly = new AtomicBoolean(false); public static Address parse(String address) { @@ -80,21 +82,34 @@ public class Address public Node getNode() { - return node; + return _node; } public void setNode(Node n) { - this.node = n; + if (readOnly.get()) + { + throw new IllegalArgumentException("Once initialized the address object is immutable"); + } + this._node = n; } public Link getLink() { - return link; + return _link; } public void setLink(Link l) { - this.link = l; + if (readOnly.get()) + { + throw new IllegalArgumentException("Once initialized the address object is immutable"); + } + this._link = l; + } + + public void markReadOnly() + { + readOnly.set(true); } } 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 1a6775df57..6e39911718 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 @@ -38,7 +38,7 @@ public class Link UNRELIABLE, AT_MOST_ONCE, AT_LEAST_ONCE, EXACTLY_ONCE; public static Reliability getReliability(String reliability) - throws AddressException + throws AddressException { if (reliability == null) { @@ -60,52 +60,52 @@ public class Link } } - protected String name; - protected String filter; - protected FilterType filterType = FilterType.SUBJECT; - protected boolean noLocal; - protected boolean durable; - protected int consumerCapacity = 0; - protected int producerCapacity = 0; - protected Reliability reliability = AT_LEAST_ONCE; + private String name; + private String _filter; + private FilterType _filterType = FilterType.SUBJECT; + private boolean _noLocal; + private boolean _durable; + private int _consumerCapacity = 0; + private int _producerCapacity = 0; + private Reliability _reliability = AT_LEAST_ONCE; - protected Map xDeclareProps = Collections.emptyMap(); - protected List xBindingProps = Collections.emptyList(); - protected Map xSubscribeProps = Collections.emptyMap(); + private Map _xDeclareProps = Collections.emptyMap(); + private List _xBindingProps = Collections.emptyList(); + private Map _xSubscribeProps = Collections.emptyMap(); public Reliability getReliability() { - return reliability; + return _reliability; } public boolean isDurable() { - return durable; + return _durable; } public String getFilter() { - return filter; + return _filter; } public FilterType getFilterType() { - return filterType; + return _filterType; } public boolean isNoLocal() { - return noLocal; + return _noLocal; } public int getConsumerCapacity() { - return consumerCapacity; + return _consumerCapacity; } public int getProducerCapacity() { - return producerCapacity; + return _producerCapacity; } public String getName() @@ -115,17 +115,17 @@ public class Link public Map getDeclareProperties() { - return xDeclareProps; + return _xDeclareProps; } public List getBindingProperties() { - return xBindingProps; + return _xBindingProps; } public Map getSubscribeProperties() { - return xSubscribeProps; + return _xSubscribeProps; } public void setName(String name) @@ -135,52 +135,52 @@ public class Link public void setFilter(String filter) { - this.filter = filter; + this._filter = filter; } public void setFilterType(FilterType filterType) { - this.filterType = filterType; + this._filterType = filterType; } public void setNoLocal(boolean noLocal) { - this.noLocal = noLocal; + this._noLocal = noLocal; } public void setDurable(boolean durable) { - this.durable = durable; + this._durable = durable; } public void setConsumerCapacity(int consumerCapacity) { - this.consumerCapacity = consumerCapacity; + this._consumerCapacity = consumerCapacity; } public void setProducerCapacity(int producerCapacity) { - this.producerCapacity = producerCapacity; + this._producerCapacity = producerCapacity; } public void setReliability(Reliability reliability) { - this.reliability = reliability; + this._reliability = reliability; } public void setDeclareProps(Map xDeclareProps) { - this.xDeclareProps = xDeclareProps; + this._xDeclareProps = xDeclareProps; } public void setBindingProps(List xBindingProps) { - this.xBindingProps = xBindingProps; + this._xBindingProps = xBindingProps; } public void setSubscribeProps(Map xSubscribeProps) { - this.xSubscribeProps = xSubscribeProps; + this._xSubscribeProps = xSubscribeProps; } } 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 dbda939307..a606e0559e 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 @@ -33,7 +33,7 @@ public class Node NEVER, SENDER, RECEIVER, ALWAYS; public static AddressPolicy getAddressPolicy(String policy) - throws AddressException + throws AddressException { if (policy == null || policy.equalsIgnoreCase("never")) { @@ -83,17 +83,17 @@ public class Node } }; - protected String name; + private String name; - protected boolean durable = false; - protected NodeType type = NodeType.QUEUE; + private boolean _durable = false; + private NodeType _type = NodeType.QUEUE; - protected AddressPolicy createPolicy = AddressPolicy.NEVER; - protected AddressPolicy assertPolicy = AddressPolicy.NEVER; - protected AddressPolicy deletePolicy = AddressPolicy.NEVER; + private AddressPolicy _createPolicy = AddressPolicy.NEVER; + private AddressPolicy _assertPolicy = AddressPolicy.NEVER; + private AddressPolicy _deletePolicy = AddressPolicy.NEVER; - protected Map xDeclareProps = Collections.emptyMap(); - protected List xBindingProps = Collections.emptyList(); + private Map _xDeclareProps = Collections.emptyMap(); + private List _xBindingProps = Collections.emptyList(); public String getName() { @@ -102,37 +102,37 @@ public class Node public boolean isDurable() { - return durable; + return _durable; } public NodeType getType() { - return type; + return _type; } public AddressPolicy getCreatePolicy() { - return createPolicy; + return _createPolicy; } public AddressPolicy getAssertPolicy() { - return assertPolicy; + return _assertPolicy; } public AddressPolicy getDeletePolicy() { - return deletePolicy; + return _deletePolicy; } public Map getDeclareProperties() { - return xDeclareProps; + return _xDeclareProps; } public List getBindingProperties() { - return xBindingProps; + return _xBindingProps; } public void setName(String name) @@ -142,36 +142,36 @@ public class Node public void setDurable(boolean durable) { - this.durable = durable; + this._durable = durable; } public void setType(NodeType type) { - this.type = type; + this._type = type; } public void setCreatePolicy(AddressPolicy createPolicy) { - this.createPolicy = createPolicy; + this._createPolicy = createPolicy; } public void setAssertPolicy(AddressPolicy assertPolicy) { - this.assertPolicy = assertPolicy; + this._assertPolicy = assertPolicy; } public void setDeletePolicy(AddressPolicy deletePolicy) { - this.deletePolicy = deletePolicy; + this._deletePolicy = deletePolicy; } public void setDeclareProps(Map xDeclareProps) { - this.xDeclareProps = xDeclareProps; + this._xDeclareProps = xDeclareProps; } public void setBindingProps(List xBindingProps) { - this.xBindingProps = xBindingProps; + this._xBindingProps = xBindingProps; } } \ No newline at end of file -- cgit v1.2.1