diff options
Diffstat (limited to 'qpid/java')
4 files changed, 147 insertions, 1 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java new file mode 100644 index 0000000000..58dbe69fa1 --- /dev/null +++ b/qpid/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/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java index 4ae1ea6e08..8d78415056 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java +++ b/qpid/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/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPlugin.java new file mode 100644 index 0000000000..d3b97ff40c --- /dev/null +++ b/qpid/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/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugin/VirtualHostPluginFactory.java new file mode 100644 index 0000000000..bde60fc9ae --- /dev/null +++ b/qpid/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); +} |
