qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject svn commit: r1545067 - in /qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server: model/adapter/BrokerAdapter.java plugin/PluggableFactoryLoader.java plugin/PreferencesProviderFactory.java
Date Sun, 24 Nov 2013 20:20:31 GMT
Author: orudyy
Date: Sun Nov 24 20:20:31 2013
New Revision: 1545067

URL: http://svn.apache.org/r1545067
Log:
QPID-5372: Stop generation of an excessive amount of debug logging for PreferencesProviderFactory
when a Broker tab is opened in web management console

Added:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PluggableFactoryLoader.java
Modified:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java?rev=1545067&r1=1545066&r2=1545067&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
Sun Nov 24 20:20:31 2013
@@ -785,7 +785,7 @@ public class BrokerAdapter extends Abstr
         }
         else if (SUPPORTED_PREFERENCES_PROVIDERS_TYPES.equals(name))
         {
-            return PreferencesProviderFactory.TYPES.get();
+            return PreferencesProviderFactory.FACTORIES.getDescriptiveTypes();
         }
         else if (MODEL_VERSION.equals(name))
         {

Added: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PluggableFactoryLoader.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PluggableFactoryLoader.java?rev=1545067&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PluggableFactoryLoader.java
(added)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PluggableFactoryLoader.java
Sun Nov 24 20:20:31 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.server.plugin;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+public class PluggableFactoryLoader<T extends Pluggable>
+{
+    private final Map<String, T> _factoriesMap;
+    private final Set<String> _types;
+
+    public PluggableFactoryLoader(Class<T> factoryClass)
+    {
+        Map<String, T> fm = new HashMap<String, T>();
+        QpidServiceLoader<T> qpidServiceLoader = new QpidServiceLoader<T>();
+        Iterable<T> factories = qpidServiceLoader.atLeastOneInstanceOf(factoryClass);
+        for (T factory : factories)
+        {
+            String descriptiveType = factory.getType();
+            if (fm.containsKey(descriptiveType))
+            {
+                throw new IllegalStateException(factoryClass.getSimpleName() + " with type
name '" + descriptiveType
+                        + "' is already registered using class '" + fm.get(descriptiveType).getClass().getName()
+                        + "', can not register class '" + factory.getClass().getName() +
"'");
+            }
+            fm.put(descriptiveType, factory);
+        }
+        _factoriesMap = Collections.unmodifiableMap(fm);
+        _types = Collections.unmodifiableSortedSet(new TreeSet<String>(_factoriesMap.keySet()));
+    }
+
+    public T get(String type)
+    {
+        return _factoriesMap.get(type);
+    }
+
+    public Collection<String> getDescriptiveTypes()
+    {
+        return _types;
+    }
+}

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java?rev=1545067&r1=1545066&r2=1545067&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/plugin/PreferencesProviderFactory.java
Sun Nov 24 20:20:31 2013
@@ -18,10 +18,6 @@
  */
 package org.apache.qpid.server.plugin;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
@@ -30,46 +26,8 @@ import org.apache.qpid.server.model.Pref
 
 public interface PreferencesProviderFactory extends Pluggable
 {
-    PreferencesProvider createInstance(UUID id, Map<String, Object> attributes, AuthenticationProvider
authenticationProvider);
-
-    static final class TYPES
-    {
-        private TYPES()
-        {
-        }
-
-        public static Collection<String> get()
-        {
-            QpidServiceLoader<PreferencesProviderFactory> qpidServiceLoader = new QpidServiceLoader<PreferencesProviderFactory>();
-            Iterable<PreferencesProviderFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(PreferencesProviderFactory.class);
-            List<String> names = new ArrayList<String>();
-            for(PreferencesProviderFactory factory : factories)
-            {
-                names.add(factory.getType());
-            }
-            return Collections.unmodifiableCollection(names);
-        }
-    }
+    PluggableFactoryLoader<PreferencesProviderFactory> FACTORIES = new PluggableFactoryLoader<PreferencesProviderFactory>(PreferencesProviderFactory.class);
 
+    PreferencesProvider createInstance(UUID id, Map<String, Object> attributes, AuthenticationProvider
authenticationProvider);
 
-    static final class FACTORIES
-    {
-        private FACTORIES()
-        {
-        }
-
-        public static PreferencesProviderFactory get(String type)
-        {
-            QpidServiceLoader<PreferencesProviderFactory> qpidServiceLoader = new QpidServiceLoader<PreferencesProviderFactory>();
-            Iterable<PreferencesProviderFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(PreferencesProviderFactory.class);
-            for(PreferencesProviderFactory factory : factories)
-            {
-                if(factory.getType().equals(type))
-                {
-                    return factory;
-                }
-            }
-            return null;
-        }
-    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message