diff options
| author | Rajith Muditha Attapattu <rajith@apache.org> | 2010-02-03 17:34:56 +0000 |
|---|---|---|
| committer | Rajith Muditha Attapattu <rajith@apache.org> | 2010-02-03 17:34:56 +0000 |
| commit | 5ea8e393b5987a2b11404bf9c12414e34e7d112c (patch) | |
| tree | beba90495afd5603b87f510fdb32fae946fe23e0 /java/client/src | |
| parent | c301ee6d82f16bc2367caf10f326bbab17790420 (diff) | |
| download | qpid-python-5ea8e393b5987a2b11404bf9c12414e34e7d112c.tar.gz | |
This is related to QPID-1831
Contains helper classes for retrieving and holding information from a parsed address string
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@906145 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src')
3 files changed, 366 insertions, 0 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java b/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java new file mode 100644 index 0000000000..d1ea8dce2d --- /dev/null +++ b/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java @@ -0,0 +1,215 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.client.messaging.address; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.qpid.client.AMQDestination.Binding; +import org.apache.qpid.configuration.Accessor; +import org.apache.qpid.configuration.Accessor.MapAccessor; +import org.apache.qpid.messaging.Address; + +/** + * Utility class for extracting information + * from the address class + */ +public class AddressHelper +{ + public static final String NODE_PROPS = "node-properties"; + public static final String X_PROPS = "x-properties"; + public static final String CREATE = "create"; + public static final String ASSERT = "assert"; + public static final String DELETE = "delete"; + public static final String FILTER = "filter"; + public static final String NO_LOCAL = "no-local"; + public static final String DURABLE = "durable"; + public static final String EXCLUSIVE = "exclusive"; + public static final String AUTO_DELETE = "auto-delete"; + public static final String TYPE = "type"; + public static final String ALT_EXCHANGE = "alt-exchange"; + public static final String BINDINGS = "bindings"; + public static final String BROWSE_ONLY = "browse"; + + private Address address; + private Accessor addressProps; + private Accessor nodeProps; + private Accessor xProps; + + public AddressHelper(Address address) + { + this.address = address; + addressProps = new MapAccessor(address.getOptions()); + Map node_props = address.getOptions() == null || + address.getOptions().get(NODE_PROPS) == null ? + null : (Map)address.getOptions().get(NODE_PROPS); + nodeProps = new MapAccessor(node_props); + xProps = new MapAccessor(node_props == null || node_props.get(X_PROPS) == null? + null: (Map)node_props.get(X_PROPS)); + } + + public String getCreate() + { + return addressProps.getString(CREATE); + } + + public String getAssert() + { + return addressProps.getString(ASSERT); + } + + public String getDelete() + { + return addressProps.getString(DELETE); + } + + public String getFilter() + { + return addressProps.getString(FILTER); + } + + public boolean isNoLocal() + { + Boolean b = nodeProps.getBoolean(NO_LOCAL); + return b == null ? false : b ; + } + + public boolean isDurable() + { + Boolean b = nodeProps.getBoolean(DURABLE); + return b == null ? false : b ; + } + + public boolean isExclusive() + { + Boolean b = xProps.getBoolean(EXCLUSIVE); + return b == null ? false : b ; + } + + public boolean isAutoDelete() + { + Boolean b = xProps.getBoolean(AUTO_DELETE); + return b == null ? false : b ; + } + + public boolean isBrowseOnly() + { + Boolean b = xProps.getBoolean(BROWSE_ONLY); + return b == null ? false : b ; + } + + public String getNodeType() + { + return nodeProps.getString(TYPE); + } + + public String getAltExchange() + { + return xProps.getString(ALT_EXCHANGE); + } + + public QpidQueueOptions getQpidQueueOptions() + { + QpidQueueOptions options = new QpidQueueOptions(); + if (xProps.getInt(QpidQueueOptions.QPID_MAX_COUNT) != null) + { + options.setMaxCount(xProps.getInt(QpidQueueOptions.QPID_MAX_COUNT)); + } + + if (xProps.getInt(QpidQueueOptions.QPID_MAX_SIZE) != null) + { + options.setMaxSize(xProps.getInt(QpidQueueOptions.QPID_MAX_SIZE)); + } + + if (xProps.getInt(QpidQueueOptions.QPID_POLICY_TYPE) != null) + { + options.setPolicyType(xProps.getString(QpidQueueOptions.QPID_POLICY_TYPE)); + } + + if (xProps.getInt(QpidQueueOptions.QPID_PERSIST_LAST_NODE) != null) + { + options.setPersistLastNode(); + } + + if (xProps.getString(QpidQueueOptions.QPID_LAST_VALUE_QUEUE) != null) + { + options.setOrderingPolicy(xProps.getString(QpidQueueOptions.QPID_LAST_VALUE_QUEUE)); + options.setLvqKey(xProps.getString(QpidQueueOptions.QPID_LVQ_KEY)); + } + else if (xProps.getString(QpidQueueOptions.QPID_LAST_VALUE_QUEUE_NO_BROWSE) != null) + { + options.setOrderingPolicy(xProps.getString(QpidQueueOptions.QPID_LAST_VALUE_QUEUE_NO_BROWSE)); + options.setLvqKey(xProps.getString(QpidQueueOptions.QPID_LVQ_KEY)); + } + + if (xProps.getString(QpidQueueOptions.QPID_QUEUE_EVENT_GENERATION) != null) + { + options.setQueueEvents(xProps.getString(QpidQueueOptions.QPID_QUEUE_EVENT_GENERATION)); + } + + return options; + } + + public QpidExchangeOptions getQpidExchangeOptions() + { + QpidExchangeOptions options = new QpidExchangeOptions(); + if (xProps.getInt(QpidExchangeOptions.QPID_EXCLUSIVE_BINDING) != null) + { + options.setExclusiveBinding(); + } + + if (xProps.getInt(QpidExchangeOptions.QPID_INITIAL_VALUE_EXCHANGE) != null) + { + options.setInitialValueExchange(); + } + + if (xProps.getInt(QpidExchangeOptions.QPID_MSG_SEQUENCE) != null) + { + options.setMessageSequencing(); + } + return options; + } + + public List<Binding> getBindings() + { + List<Binding> bindings = new ArrayList<Binding>(); + if (address.getOptions() != null && + address.getOptions().get(NODE_PROPS) != null) + { + Map node_props = (Map)address.getOptions().get(NODE_PROPS); + List<String> bindingList = + (List<String>)((Map)node_props.get(X_PROPS)).get(BINDINGS); + if (bindingList != null) + { + for (String bindingStr: bindingList) + { + Address addr = Address.parse(bindingStr); + Binding binding = new Binding(addr.getName(), + addr.getSubject(), + addr.getOptions()); + bindings.add(binding); + } + } + } + return bindings; + } +} diff --git a/java/client/src/main/java/org/apache/qpid/client/messaging/address/QpidExchangeOptions.java b/java/client/src/main/java/org/apache/qpid/client/messaging/address/QpidExchangeOptions.java new file mode 100644 index 0000000000..3ad9aff9ea --- /dev/null +++ b/java/client/src/main/java/org/apache/qpid/client/messaging/address/QpidExchangeOptions.java @@ -0,0 +1,45 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.client.messaging.address; + +import java.util.HashMap; + +public class QpidExchangeOptions extends HashMap<String,Object> +{ + public static final String QPID_MSG_SEQUENCE = "qpid.msg_sequence"; + public static final String QPID_INITIAL_VALUE_EXCHANGE = "qpid.ive"; + public static final String QPID_EXCLUSIVE_BINDING = "qpid.exclusive-binding"; + + public void setMessageSequencing() + { + this.put(QPID_MSG_SEQUENCE, 1); + } + + public void setInitialValueExchange() + { + this.put(QPID_INITIAL_VALUE_EXCHANGE, 1); + } + + public void setExclusiveBinding() + { + this.put(QPID_EXCLUSIVE_BINDING, 1); + } +} diff --git a/java/client/src/main/java/org/apache/qpid/client/messaging/address/QpidQueueOptions.java b/java/client/src/main/java/org/apache/qpid/client/messaging/address/QpidQueueOptions.java new file mode 100644 index 0000000000..ac9bc59d79 --- /dev/null +++ b/java/client/src/main/java/org/apache/qpid/client/messaging/address/QpidQueueOptions.java @@ -0,0 +1,106 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.client.messaging.address; + +import java.util.HashMap; + +public class QpidQueueOptions extends HashMap<String,Object> +{ + public static final String QPID_MAX_COUNT = "qpid.max_count"; + public static final String QPID_MAX_SIZE = "qpid.max_size"; + public static final String QPID_POLICY_TYPE = "qpid.policy_type"; + public static final String QPID_PERSIST_LAST_NODE = "qpid.persist_last_node"; + public static final String QPID_LVQ_KEY = "qpid.LVQ_key"; + public static final String QPID_LAST_VALUE_QUEUE = "qpid.last_value_queue"; + public static final String QPID_LAST_VALUE_QUEUE_NO_BROWSE = "qpid.last_value_queue_no_browse"; + public static final String QPID_QUEUE_EVENT_GENERATION = "qpid.queue_event_generation"; + + public void validatePolicyType(String type) + { + if (type == null || + !("reject".equals(type) || "flow_to_disk".equals(type) || + "ring".equals(type) || "ring_strict".equals(type))) + { + throw new IllegalArgumentException("Invalid Queue Policy Type" + + " should be one of {reject|flow_to_disk|ring|ring_strict}"); + } + } + + public void setPolicyType(String s) + { + validatePolicyType(s); + this.put(QPID_POLICY_TYPE, s); + } + + public void setMaxCount(Integer i) + { + this.put(QPID_MAX_COUNT, i); + } + + public void setMaxSize(Integer i) + { + this.put(QPID_MAX_SIZE, i); + } + + public void setPersistLastNode() + { + this.put(QPID_PERSIST_LAST_NODE, 1); + } + + public void setOrderingPolicy(String s) + { + if ("lvq".equals(s)) + { + this.put(QPID_LAST_VALUE_QUEUE, 1); + } + else if ("lvq_no_browse".equals(s)) + { + this.put(QPID_LAST_VALUE_QUEUE_NO_BROWSE,1); + } + else + { + throw new IllegalArgumentException("Invalid Ordering Policy" + + " should be one of {lvq|lvq_no_browse}"); + } + } + + public void setLvqKey(String key) + { + this.put(QPID_LVQ_KEY, key); + } + + public void setQueueEvents(String s) + { + if (s.equals("enque_only")) + { + this.put(QPID_QUEUE_EVENT_GENERATION, 1); + } + else if (s.equals("enque_and_dequeue")) + { + this.put(QPID_QUEUE_EVENT_GENERATION,2); + } + else + { + throw new IllegalArgumentException("Invalid value" + + " should be one of {enqueue_only|enqueue_and_dequeue}"); + } + } +} |
