Review Board 1.7.22


Destination refactoring

Review Request #4658 - Created April 5, 2012 and updated

rajith attapattu
QPID-3401
Reviewers
qpid
gordon, rgodfrey, rhs, robbie, wprice
qpid
The following patch is based on the various discussions we've had on the dev list about restructing our destination implementation.
As the first phase this patch only includes the new class heirachy. For the second phase we will tackle the integration into the code base.

A summary of the desgin is as follows,

1. Once initialized with the destination string, the destination objects are immutable.
2. There are 2 concrete implementations in the form of QpidTopic and QpidQueue.
3. Destinations will be desginated as "Queues" and "Topics" by the users in the jndi file. This prevents us from having to automagically decide the type.
4. Both BURL and Address strings are parsed and adapted into a common data structure. Internally the code will work with this data structure.
5. The Destination impl does not depend on any other classes, thus allowing it be used with the current code or the new client.

(There are 2 oe 3 white space errors that I can't seem to get rid of. It seems they are comming from the diff process).

 

Diff revision 1

This is not the most recent revision of the diff. The latest diff is revision 2. See what's changed.

1 2
1 2

  1. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java: Loading...
  2. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java: Loading...
  3. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java: Loading...
  4. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTemporaryQueue.java: Loading...
  5. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTemporaryTopic.java: Loading...
  6. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java: Loading...
  7. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/TemporaryDestinationProvider.java: Loading...
  8. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java: Loading...
  9. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java: Loading...
  10. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/AddressException.java: Loading...
  11. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java: Loading...
  12. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java: Loading...
  13. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java: Loading...
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java
New File

    
   
1
/*

    
   
2
 *

    
   
3
 * Licensed to the Apache Software Foundation (ASF) under one

    
   
4
 * or more contributor license agreements.  See the NOTICE file

    
   
5
 * distributed with this work for additional information

    
   
6
 * regarding copyright ownership.  The ASF licenses this file

    
   
7
 * to you under the Apache License, Version 2.0 (the

    
   
8
 * "License"); you may not use this file except in compliance

    
   
9
 * with the License.  You may obtain a copy of the License at

    
   
10
 *

    
   
11
 *   http://www.apache.org/licenses/LICENSE-2.0

    
   
12
 *

    
   
13
 * Unless required by applicable law or agreed to in writing,

    
   
14
 * software distributed under the License is distributed on an

    
   
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

    
   
16
 * KIND, either express or implied.  See the License for the

    
   
17
 * specific language governing permissions and limitations

    
   
18
 * under the License.

    
   
19
 *

    
   
20
 */

    
   
21
package org.apache.qpid.jms;

    
   
22

   

    
   
23
import java.net.URISyntaxException;

    
   
24
import java.util.ArrayList;

    
   
25
import java.util.Collections;

    
   
26
import java.util.HashMap;

    
   
27
import java.util.List;

    
   
28
import java.util.Map;

    
   
29

   

    
   
30
import org.apache.qpid.framing.AMQShortString;

    
   
31
import org.apache.qpid.jms.QpidDestination.DestinationType;

    
   
32
import org.apache.qpid.messaging.Address;

    
   
33
import org.apache.qpid.messaging.address.AddressException;

    
   
34
import org.apache.qpid.messaging.address.Link;

    
   
35
import org.apache.qpid.messaging.address.Link.Reliability;

    
   
36
import org.apache.qpid.messaging.address.Node;

    
   
37
import org.apache.qpid.messaging.address.Node.AddressPolicy;

    
   
38
import org.apache.qpid.messaging.address.Node.NodeType;

    
   
39
import org.apache.qpid.messaging.util.AddressHelper;

    
   
40
import org.apache.qpid.url.AMQBindingURL;

    
   
41

   

    
   
42
public class DestinationStringParser

    
   
43
{

    
   
44
   public static Address parseAddressString(String str, DestinationType type) throws AddressException

    
   
45
   {

    
   
46
       Address addr = Address.parse(str);

    
   
47
       AddressHelper helper = new AddressHelper(addr);

    
   
48

   

    
   
49
       Node node = new Node();

    
   
50
       node.setName(addr.getName());

    
   
51
       node.setAssertPolicy(AddressPolicy.getAddressPolicy(helper.getAssert()));

    
   
52
       node.setCreatePolicy(AddressPolicy.getAddressPolicy(helper.getCreate()));

    
   
53
       node.setDeletePolicy(AddressPolicy.getAddressPolicy(helper.getDelete()));

    
   
54
       node.setDurable(helper.isNodeDurable());

    
   
55

   

    
   
56
       if (DestinationType.TOPIC == type)

    
   
57
       {

    
   
58
           if (helper.getNodeType() == NodeType.QUEUE)

    
   
59
           {

    
   
60
               throw new AddressException("Destination is marked as a Topic, but address is defined as a Queue");

    
   
61
           }

    
   
62
           node.setType(NodeType.TOPIC);

    
   
63
       }

    
   
64
       else

    
   
65
       {

    
   
66
           if (helper.getNodeType() == NodeType.TOPIC)

    
   
67
           {

    
   
68
               throw new AddressException("Destination is marked as a Queue, but address is defined as a Topic");

    
   
69
           }

    
   
70
           node.setType(NodeType.QUEUE);

    
   
71
       }

    
   
72

   

    
   
73
       node.setDeclareProps(helper.getNodeDeclareArgs());

    
   
74
       node.setBindingProps(helper.getNodeBindings());

    
   
75
       addr.setNode(node);

    
   
76

   

    
   
77
       Link link =  new Link();

    
   
78
       link.setName(helper.getLinkName());

    
   
79
       link.setDurable(helper.isLinkDurable());

    
   
80
       link.setReliability(Reliability.getReliability(helper.getLinkReliability()));

    
   
81
       link.setProducerCapacity(helper.getProducerCapacity());

    
   
82
       link.setConsumerCapacity(helper.getConsumeCapacity());

    
   
83
       link.setDeclareProps(helper.getLinkDeclareArgs());

    
   
84
       link.setBindingProps(helper.getLinkBindings());

    
   
85
       link.setSubscribeProps(helper.getLinkSubscribeArgs());

    
   
86
       addr.setLink(link);

    
   
87

   

    
   
88
       return addr;

    
   
89
   }

    
   
90

   

    
   
91
   public static Address parseBURLString(String str, DestinationType type) throws AddressException

    
   
92
   {

    
   
93
	   AMQBindingURL burl;

    
   
94
	   try

    
   
95
	   {

    
   
96
           burl = new AMQBindingURL(str);

    
   
97
	   }

    
   
98
	   catch(URISyntaxException e)

    
   
99
	   {

    
   
100
	       AddressException ex = new AddressException("Error parsing BURL : " + e.getMessage());

    
   
101
	       ex.initCause(e);

    
   
102
	       throw ex;

    
   
103
	   }

    
   
104

   

    
   
105
	   Address addr;

    
   
106
	   Node node = new Node();

    
   
107
	   Link link = new Link();

    
   
108

   

    
   
109
	   if (type == DestinationType.TOPIC)

    
   
110
	   {

    
   
111
	       addr = new Address(burl.getExchangeName().asString(),

    
   
112
                              burl.getRoutingKey().asString(),

    
   
113
                              Collections.emptyMap());

    
   
114

   

    
   
115
	      link.setName(burl.getQueueName().asString());

    
   
116
	      node.setBindingProps(Collections.emptyList());

    
   
117
	   }

    
   
118
	   else

    
   
119
	   {

    
   
120
		   addr = new Address(burl.getQueueName().asString(),

    
   
121
                              burl.getRoutingKey().asString(),

    
   
122
                              Collections.emptyMap());

    
   
123

   

    
   
124
		   List<Object> bindings = new ArrayList<Object>();

    
   
125
		   Map<String,Object> binding = new HashMap<String,Object>();

    
   
126
		   binding.put(AddressHelper.EXCHANGE, burl.getExchangeName().asString());

    
   
127
		   binding.put(AddressHelper.KEY, burl.getRoutingKey());

    
   
128
		   bindings.add(binding);

    
   
129
		   node.setBindingProps(bindings);

    
   
130
	   }

    
   
131

   

    
   
132
	   List<Object> bindings = node.getBindingProperties();

    
   
133
	   for (AMQShortString key: burl.getBindingKeys())

    
   
134
	   {

    
   
135
	       Map<String,Object> binding = new HashMap<String,Object>();

    
   
136
           binding.put(AddressHelper.EXCHANGE, burl.getExchangeName().asString());

    
   
137
           binding.put(AddressHelper.KEY, key.asString());

    
   
138
           bindings.add(binding);

    
   
139
	   }

    
   
140

   

    
   
141
	   node.setAssertPolicy(AddressPolicy.NEVER);

    
   
142
       node.setCreatePolicy(AddressPolicy.RECEIVER);

    
   
143
       node.setDeletePolicy(AddressPolicy.NEVER);

    
   
144

   

    
   
145
	   return addr;

    
   
146
   }

    
   
147
}
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTemporaryQueue.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTemporaryTopic.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/TemporaryDestinationProvider.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java
Revision 1309769 New Change
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java
Revision 1309769 New Change
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/AddressException.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java
New File
 
http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java
New File
 
  1. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/DestinationStringParser.java: Loading...
  2. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidDestination.java: Loading...
  3. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidQueue.java: Loading...
  4. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTemporaryQueue.java: Loading...
  5. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTemporaryTopic.java: Loading...
  6. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/QpidTopic.java: Loading...
  7. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/TemporaryDestinationProvider.java: Loading...
  8. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java: Loading...
  9. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java: Loading...
  10. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/AddressException.java: Loading...
  11. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Link.java: Loading...
  12. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/address/Node.java: Loading...
  13. http://svn.apache.org/repos/asf/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java: Loading...