You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2010/02/03 18:27:29 UTC

svn commit: r906135 - in /qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration: Accessor.java ClientProperties.java QpidProperty.java Validator.java

Author: rajith
Date: Wed Feb  3 17:27:28 2010
New Revision: 906135

URL: http://svn.apache.org/viewvc?rev=906135&view=rev
Log:
This is related to QPID-2343
Added the Accessor.java to abstract the access strategies. Added several acess strategies including one which takes a list of Accessors.
Added a constrcutor in the QpidProperty class to take an Accessor. The other constructor defaults to SystemPropertyAccessor

Added:
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/QpidProperty.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Validator.java

Added: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java?rev=906135&view=auto
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java (added)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java Wed Feb  3 17:27:28 2010
@@ -0,0 +1,241 @@
+package org.apache.qpid.configuration;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public interface Accessor
+{
+    public Boolean getBoolean(String name);
+    public Integer getInt(String name);
+    public Long getLong(String name);
+    public String getString(String name);
+    
+    static class SystemPropertyAccessor implements Accessor
+    {
+        public Boolean getBoolean(String name)
+        {
+            return Boolean.getBoolean(name);
+        }
+        
+        public Integer getInt(String name)
+        {
+            return Integer.getInteger(name);
+        }
+        
+        public Long getLong(String name)
+        {
+            return Long.getLong(name);
+        }
+        
+        public String getString(String name)
+        {
+            return System.getProperty(name);
+        }
+    }
+    
+    static class MapAccessor implements Accessor
+    {
+        protected Map<Object,Object> source;
+        
+        public MapAccessor(Map<Object,Object> map)
+        {
+            source = map;
+        }
+        
+        public Boolean getBoolean(String name)
+        {
+            if (source != null && source.containsKey(name))
+            {
+                if (source.get(name) instanceof Boolean)
+                {
+                    return (Boolean)source.get(name);
+                }
+                else
+                {
+                    return Boolean.parseBoolean((String)source.get(name));
+                }
+            }
+            else
+            {
+                return null;
+            }
+        }
+        
+        public Integer getInt(String name)
+        {
+            if (source != null && source.containsKey(name))
+            {
+                if (source.get(name) instanceof Integer)
+                {
+                    return (Integer)source.get(name);
+                }
+                else
+                {
+                    return Integer.parseInt((String)source.get(name));
+                }
+            }
+            else
+            {
+                return null;
+            }
+        }
+        
+        public Long getLong(String name)
+        {
+            if (source != null && source.containsKey(name))
+            {
+                if (source.get(name) instanceof Long)
+                {
+                    return (Long)source.get(name);
+                }
+                else
+                {
+                    return Long.parseLong((String)source.get(name));
+                }
+            }
+            else
+            {
+                return null;
+            }
+        }
+        
+        public String getString(String name)
+        {
+            if (source != null && source.containsKey(name))
+            {
+                return (String)source.get(name);
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }  
+    
+    static class PropertyFileAccessor extends MapAccessor
+    {
+        public PropertyFileAccessor(String fileName) throws FileNotFoundException, IOException
+        {
+            super(null);
+            Properties props = new Properties();
+            props.load(new FileInputStream(fileName));
+            source = props;
+        }
+    }
+    
+    static class CombinedAccessor implements Accessor
+    {
+        private List<Accessor> accessors;
+        
+        public CombinedAccessor(Accessor...accessors)
+        {
+            this.accessors = Arrays.asList(accessors);
+        }
+        
+        public Boolean getBoolean(String name)
+        {
+            for (Accessor accessor: accessors)
+            {
+                if (accessor.getBoolean(name) != null)
+                {
+                    return accessor.getBoolean(name);
+                }
+            }
+            return null;
+        }
+        
+        public Integer getInt(String name)
+        {
+            for (Accessor accessor: accessors)
+            {
+                if (accessor.getBoolean(name) != null)
+                {
+                    return accessor.getInt(name);
+                }
+            }
+            return null;
+        }
+        
+        public Long getLong(String name)
+        {
+            for (Accessor accessor: accessors)
+            {
+                if (accessor.getBoolean(name) != null)
+                {
+                    return accessor.getLong(name);
+                }
+            }
+            return null;
+        }
+        
+        public String getString(String name)
+        {
+            for (Accessor accessor: accessors)
+            {
+                if (accessor.getBoolean(name) != null)
+                {
+                    return accessor.getString(name);
+                }
+            }
+            return null;
+        }
+    }
+    
+    static class ValidationAccessor implements Accessor
+    {   
+        private List<Validator> validators;
+        private Accessor delegate;
+        
+        public ValidationAccessor(Accessor delegate,Validator...validators)
+        {
+            this.validators = Arrays.asList(validators);
+            this.delegate = delegate;
+        }
+
+        public Boolean getBoolean(String name)
+        {
+            Boolean v = delegate.getBoolean(name);
+            for (Validator validator: validators)
+            {
+                validator.validate(v);
+            }
+            return v;
+        }
+        
+        public Integer getInt(String name)
+        {
+            Integer v = delegate.getInt(name);
+            for (Validator validator: validators)
+            {
+                validator.validate(v);
+            }
+            return v;
+        }
+        
+        public Long getLong(String name)
+        {
+            Long v = delegate.getLong(name);
+            for (Validator validator: validators)
+            {
+                validator.validate(v);
+            }
+            return v;
+        }
+        
+        public String getString(String name)
+        {
+            String v = delegate.getString(name);
+            for (Validator validator: validators)
+            {
+                validator.validate(v);
+            }
+            return v;
+        }
+    }
+}
\ No newline at end of file

Added: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java?rev=906135&view=auto
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java (added)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java Wed Feb  3 17:27:28 2010
@@ -0,0 +1,134 @@
+/* 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.configuration;
+
+/**
+ * This class centralized the Qpid client properties.
+ */
+public class ClientProperties
+{
+  
+    /**
+     * Currently with Qpid it is not possible to change the client ID.
+     * If one is not specified upon connection construction, an id is generated automatically.
+     * Therefore an exception is always thrown unless this property is set to true.
+     * type: boolean
+     */
+    public static final String IGNORE_SET_CLIENTID_PROP_NAME = "ignore_setclientID";
+
+    /**
+     * This property is currently used within the 0.10 code path only
+     * The maximum number of pre-fetched messages per destination
+     * This property is used for all the connection unless it is overwritten by the connectionURL
+     * type: long
+     */
+    public static final String MAX_PREFETCH_PROP_NAME = "max_prefetch";
+    public static final String MAX_PREFETCH_DEFAULT = "500";
+
+    /**
+     * When true a sync command is sent after every persistent messages.
+     * type: boolean
+     */
+    public static final String SYNC_PERSISTENT_PROP_NAME = "sync_persistence";
+
+    /**
+     * When true a sync command is sent after sending a message ack.
+     * type: boolean
+     */
+    public static final String SYNC_ACK_PROP_NAME = "sync_ack";
+
+    /**
+     * sync_publish property - {persistent|all}
+     * If set to 'persistent',then persistent messages will be publish synchronously
+     * If set to 'all', then all messages regardless of the delivery mode will be
+     * published synchronously.
+     */
+    public static final String SYNC_PUBLISH_PROP_NAME = "sync_publish";
+
+    /**
+     * This value will be used in the following settings
+     * To calculate the SO_TIMEOUT option of the socket (2*idle_timeout)
+     * If this values is between the max and min values specified for heartbeat
+     * by the broker in TuneOK it will be used as the heartbeat interval.
+     * If not a warning will be printed and the max value specified for
+     * heartbeat in TuneOK will be used
+     * 
+     * The default idle timeout is set to 120 secs
+     */
+    public static final String IDLE_TIMEOUT_PROP_NAME = "idle_timeout";
+    public static final long DEFAULT_IDLE_TIMEOUT = 120000;
+    
+    public static final String HEARTBEAT = "qpid.heartbeat";
+    public static final int HEARTBEAT_DEFAULT = 120;
+    
+    /**
+     * This value will be used to determine the default destination syntax type.
+     * Currently the two types are Binding URL (java only) and the Addressing format (used by
+     * all clients). 
+     */
+    public static final String DEST_SYNTAX = "qpid.dest_syntax";
+    
+    public static final String USE_LEGACY_MAP_MESSAGE_FORMAT = "qpid.use_legacy_map_message";
+
+     /**
+     * ==========================================================
+     * Those properties are used when the io size should be bounded
+     * ==========================================================
+     */
+
+    /**
+     * When set to true the io layer throttle down producers and consumers
+     * when written or read messages are accumulating and exceeding a certain size.
+     * This is especially useful when a the producer rate is greater than the network
+     * speed.
+     * type: boolean
+     */
+    public static final String PROTECTIO_PROP_NAME = "protectio";
+
+    //=== The following properties are only used when the previous one is true.
+    /**
+     * Max size of read messages that can be stored within the MINA layer
+     * type: int
+     */
+    public static final String READ_BUFFER_LIMIT_PROP_NAME = "qpid.read.buffer.limit";
+    public static final String READ_BUFFER_LIMIT_DEFAULT = "262144";
+    /**
+     * Max size of written messages that can be stored within the MINA layer
+     * type: int
+     */
+    public static final String WRITE_BUFFER_LIMIT_PROP_NAME = "qpid.read.buffer.limit";
+    public static final String WRITE_BUFFER_LIMIT_DEFAULT = "262144";
+
+    public static final String AMQP_VERSION = "qpid.amqp.version";
+    
+    private static ClientProperties _instance = new ClientProperties();
+    
+    /*
+    public static final QpidProperty<Boolean>  IGNORE_SET_CLIENTID_PROP_NAME = 
+        QpidProperty.booleanProperty(false,"qpid.ignore_set_client_id","ignore_setclientID");
+    
+    public static final QpidProperty<Boolean> SYNC_PERSISTENT_PROP_NAME =
+        QpidProperty.booleanProperty(false,"qpid.sync_persistence","sync_persistence");
+    
+    
+    public static final QpidProperty<Integer> MAX_PREFETCH_PROP_NAME =
+        QpidProperty.intProperty(500,"qpid.max_prefetch","max_prefetch"); */
+    
+    
+}

Added: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/QpidProperty.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/QpidProperty.java?rev=906135&view=auto
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/QpidProperty.java (added)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/QpidProperty.java Wed Feb  3 17:27:28 2010
@@ -0,0 +1,181 @@
+/* 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.configuration;
+
+import org.apache.qpid.configuration.Accessor.SystemPropertyAccessor;
+
+abstract class QpidProperty<T>
+{
+    private T defValue;
+    private String[] names;
+    protected Accessor accessor;
+
+    QpidProperty(T defValue, String... names)
+    {
+        this(new SystemPropertyAccessor(),defValue,names);
+    }
+    
+    QpidProperty(Accessor accessor,T defValue, String... names)
+    {
+        this.accessor = accessor;
+        this.defValue = defValue;
+        this.names = names;
+    }
+
+    T get()
+    {
+        for (String name : names)
+        {
+            T obj = getByName(name);
+            if (obj != null)
+            {
+                return obj;
+            }
+        }
+
+        return defValue;
+    }
+
+    protected abstract T getByName(String name);
+
+    public static QpidProperty<Boolean> booleanProperty(Boolean defaultValue,
+            String... names)
+    {
+        return new QpidBooleanProperty(defaultValue, names);
+    }
+
+    public static QpidProperty<Boolean> booleanProperty(Accessor accessor,
+            Boolean defaultValue,String... names)
+    {
+        return new QpidBooleanProperty(accessor,defaultValue, names);
+    }
+    
+    public static QpidProperty<Integer> intProperty(Integer defaultValue,
+            String... names)
+    {
+        return new QpidIntProperty(defaultValue, names);
+    }
+
+    public static QpidProperty<Integer> intProperty(Accessor accessor,
+            Integer defaultValue, String... names)
+    {
+        return new QpidIntProperty(accessor,defaultValue, names);
+    }
+    
+    public static QpidProperty<Long> longProperty(Long defaultValue,
+            String... names)
+    {
+        return new QpidLongProperty(defaultValue, names);
+    }
+
+    public static QpidProperty<Long> longProperty(Accessor accessor,
+            Long defaultValue, String... names)
+    {
+        return new QpidLongProperty(accessor,defaultValue, names);
+    }
+    
+    public static QpidProperty<String> stringProperty(String defaultValue,
+            String... names)
+    {
+        return new QpidStringProperty(defaultValue, names);
+    }
+
+    public static QpidProperty<String> stringProperty(Accessor accessor,
+            String defaultValue,String... names)
+    {
+        return new QpidStringProperty(accessor,defaultValue, names);
+    }
+    
+    static class QpidBooleanProperty extends QpidProperty<Boolean>
+    {
+        QpidBooleanProperty(Boolean defValue, String... names)
+        {
+            super(defValue, names);
+        }
+        
+        QpidBooleanProperty(Accessor accessor,Boolean defValue, String... names)
+        {
+            super(accessor,defValue, names);
+        }
+
+        @Override
+        protected Boolean getByName(String name)
+        {
+            return accessor.getBoolean(name);
+        }
+    }
+
+    static class QpidIntProperty extends QpidProperty<Integer>
+    {
+        QpidIntProperty(Integer defValue, String... names)
+        {
+            super(defValue, names);
+        }
+
+        QpidIntProperty(Accessor accessor,Integer defValue, String... names)
+        {
+            super(accessor,defValue, names);
+        }
+        
+        @Override
+        protected Integer getByName(String name)
+        {
+            return accessor.getInt(name);
+        }
+    }
+
+    static class QpidLongProperty extends QpidProperty<Long>
+    {
+        QpidLongProperty(Long defValue, String... names)
+        {
+            super(defValue, names);
+        }
+
+        QpidLongProperty(Accessor accessor,Long defValue, String... names)
+        {
+            super(accessor,defValue, names);
+        }
+        
+        @Override
+        protected Long getByName(String name)
+        {
+            return accessor.getLong(name);
+        }
+    }
+
+    static class QpidStringProperty extends QpidProperty<String>
+    {
+        QpidStringProperty(String defValue, String... names)
+        {
+            super(defValue, names);
+        }
+
+        QpidStringProperty(Accessor accessor,String defValue, String... names)
+        {
+            super(accessor,defValue, names);
+        }
+        
+        @Override
+        protected String getByName(String name)
+        {
+            return accessor.getString(name);
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Validator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Validator.java?rev=906135&view=auto
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Validator.java (added)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/Validator.java Wed Feb  3 17:27:28 2010
@@ -0,0 +1,6 @@
+package org.apache.qpid.configuration;
+
+public interface Validator
+{
+    public void validate(Object value);
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org