summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2010-05-07 15:13:23 +0000
committerMartin Ritchie <ritchiem@apache.org>2010-05-07 15:13:23 +0000
commitd05cce46d268645cd45cb2f88fb6d1b511d6fa18 (patch)
treeb85e8c53df68e56b692ed202b44d7ead17d3b390 /java
parentbb15c5f4ac949e3ab0c6ef105719a0ee2163c4e8 (diff)
downloadqpid-python-d05cce46d268645cd45cb2f88fb6d1b511d6fa18.tar.gz
QPID-2584 : Updated VirtualHost to load VirtualHost Plugins and not hard code SCD
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@942112 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java26
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java54
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java28
4 files changed, 147 insertions, 1 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
new file mode 100644
index 0000000000..58dbe69fa1
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
@@ -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();
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
index 4ae1ea6e08..8d78415056 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
@@ -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 Accessable, VirtualHost
_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);
+ }
+ }
+ }
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java
new file mode 100644
index 0000000000..d3b97ff40c
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java
@@ -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();
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java
new file mode 100644
index 0000000000..bde60fc9ae
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java
@@ -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);
+}