qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ritch...@apache.org
Subject svn commit: r942112 - in /qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server: plugins/ virtualhost/ virtualhost/plugin/
Date Fri, 07 May 2010 15:13:23 GMT
Author: ritchiem
Date: Fri May  7 15:13:23 2010
New Revision: 942112

URL: http://svn.apache.org/viewvc?rev=942112&view=rev
Log:
QPID-2584 : Updated VirtualHost to load VirtualHost Plugins and not hard code SCD

Added:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java?rev=942112&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
(added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
Fri May  7 15:13:23 2010
@@ -0,0 +1,26 @@
+/*
+ *
+ * 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.plugins;
+
+public interface PluginFactory
+{
+    public String getPluginName();
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java?rev=942112&r1=942111&r2=942112&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
(original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
Fri May  7 15:13:23 2010
@@ -28,6 +28,8 @@ import org.apache.qpid.AMQException;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.FieldTable;
 import org.apache.qpid.server.AMQBrokerManagerMBean;
+import org.apache.qpid.server.virtualhost.plugin.VirtualHostPluginFactory;
+import org.apache.qpid.server.virtualhost.plugin.VirtualHostPlugin;
 import org.apache.qpid.server.binding.BindingFactory;
 import org.apache.qpid.server.configuration.BrokerConfig;
 import org.apache.qpid.server.configuration.ConfigStore;
@@ -72,8 +74,10 @@ import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.UUID;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 public class VirtualHostImpl implements Accessable, VirtualHost
 {
@@ -321,6 +325,54 @@ public class VirtualHostImpl implements 
                     _connectionRegistry.expireClosedChannels();
                 }
             }
+
+            Map<String, VirtualHostPluginFactory> plugins =
+                    ApplicationRegistry.getInstance().
+                            getPluginManager().getVirtualHostPlugins();
+
+            if (plugins != null)
+            {
+                ScheduledThreadPoolExecutor vhostTasks = new ScheduledThreadPoolExecutor(plugins.size());
+
+                for (String pluginName : plugins.keySet())
+                {
+                    try
+                    {
+                        VirtualHostPlugin plugin = plugins.get(pluginName).newInstance(this);
+
+                        TimeUnit units = TimeUnit.MILLISECONDS;
+
+                        if (plugin.getTimeUnit() != null)
+                        {
+                            try
+                            {
+                                units = TimeUnit.valueOf(plugin.getTimeUnit());
+                            }
+                            catch (IllegalArgumentException iae)
+                            {
+                                _logger.warn("Plugin:" + pluginName +
+                                             " provided an illegal TimeUnit value:"
+                                             + plugin.getTimeUnit());
+                                // Warn and use default of millseconds
+                                // Should not occur in a well behaved plugin
+                            }
+                        }
+
+                        vhostTasks.scheduleAtFixedRate(plugin, plugin.getDelay() / 2,
+                                                       plugin.getDelay(), units);
+
+                        _logger.info("Loaded VirtualHostPlugin:" + plugin);
+                    }
+                    catch (IllegalArgumentException iae)
+                    {
+                        _logger.warn("VirtualHostPlugin:" + pluginName + " has not been configured
for this virtualhost(" + getName() + ")");
+                    }
+                    catch (Exception e)
+                    {
+                        _logger.error("Unable to load VirtualHostPlugin:" + pluginName +
" due to:" + e.getMessage(), e);
+                    }
+                }
+            }
         }
     }
 

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java?rev=942112&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java
(added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java
Fri May  7 15:13:23 2010
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.virtualhost.plugin;
+
+public interface VirtualHostPlugin extends Runnable
+{
+    public void run();
+
+    /**
+     * Long value representing the delay between repeats
+     *
+     * @return
+     */
+    public long getDelay();
+
+    /**
+     * Option to specify what the delay value represents
+     * @see java.util.concurrent.TimeUnit for valid value.
+     * @return
+     */
+    public String getTimeUnit();
+}

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java?rev=942112&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java
(added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java
Fri May  7 15:13:23 2010
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.virtualhost.plugin;
+
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public interface VirtualHostPluginFactory
+{
+    public VirtualHostPlugin newInstance(VirtualHost vhost);
+}



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


Mime
View raw message