This commit is contained in:
Clebert Suconic 2017-05-08 11:59:41 -04:00
commit 117d92bc94
7 changed files with 212 additions and 1 deletions

View File

@ -69,6 +69,7 @@ import org.apache.activemq.artemis.core.server.JournalType;
import org.apache.activemq.artemis.core.server.SecuritySettingPlugin;
import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
import org.apache.activemq.artemis.core.server.group.impl.GroupingHandlerConfiguration;
import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin;
import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
@ -97,6 +98,10 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
public static final String SECURITY_ROLE_MAPPING_NAME = "role-mapping";
public static final String BROKER_PLUGINS_ELEMENT_NAME = "broker-plugins";
public static final String BROKER_PLUGIN_ELEMENT_NAME = "broker-plugin";
private static final String PERMISSION_ELEMENT_NAME = "permission";
private static final String SETTING_ELEMENT_NAME = "setting";
@ -600,6 +605,8 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
parseSecurity(e, config);
parseBrokerPlugins(e, config);
NodeList connectorServiceConfigs = e.getElementsByTagName("connector-service");
ArrayList<ConnectorServiceConfiguration> configs = new ArrayList<>();
@ -647,6 +654,31 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
}
}
private void parseBrokerPlugins(final Element e, final Configuration config) {
NodeList brokerPlugins = e.getElementsByTagName(BROKER_PLUGINS_ELEMENT_NAME);
if (brokerPlugins.getLength() != 0) {
Element node = (Element) brokerPlugins.item(0);
NodeList list = node.getElementsByTagName(BROKER_PLUGIN_ELEMENT_NAME);
for (int i = 0; i < list.getLength(); i++) {
ActiveMQServerPlugin plugin = parseActiveMQServerPlugin(list.item(i));
config.registerBrokerPlugin(plugin);
}
}
}
private ActiveMQServerPlugin parseActiveMQServerPlugin(Node item) {
final String clazz = item.getAttributes().getNamedItem("class-name").getNodeValue();
ActiveMQServerPlugin serverPlugin = AccessController.doPrivileged(new PrivilegedAction<ActiveMQServerPlugin>() {
@Override
public ActiveMQServerPlugin run() {
return (ActiveMQServerPlugin) ClassloadingUtil.newInstanceFromClassLoader(clazz);
}
});
return serverPlugin;
}
/**
* @param e
* @param config

View File

@ -853,6 +853,34 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="broker-plugins" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
a list of broker-plugins
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="broker-plugin" maxOccurs="unbounded" minOccurs="0">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
a broker plugin
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="class-name" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
the name of the broker plugin class to instantiate
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="address-settings" maxOccurs="1" minOccurs="0">
<xsd:annotation>
<xsd:documentation>

View File

@ -31,6 +31,7 @@ import java.util.Set;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
@ -45,12 +46,12 @@ import org.apache.activemq.artemis.core.config.HAPolicyConfiguration;
import org.apache.activemq.artemis.core.config.ha.LiveOnlyPolicyConfiguration;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.core.server.JournalType;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.SecuritySettingPlugin;
import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
import org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin;
import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin;
import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
import org.junit.Assert;
import org.junit.Test;
@ -618,6 +619,19 @@ public class FileConfigurationTest extends ConfigurationImplTest {
}
}
@Test
public void testBrokerPlugin() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager("brokerPlugin.xml");
deploymentManager.addDeployable(fc);
deploymentManager.readConfiguration();
List<ActiveMQServerPlugin> brokerPlugins = fc.getBrokerPlugins();
assertEquals(2, brokerPlugins.size());
assertTrue(brokerPlugins.get(0) instanceof EmptyPlugin1);
assertTrue(brokerPlugins.get(1) instanceof EmptyPlugin2);
}
@Override
protected Configuration createConfiguration() throws Exception {
FileConfiguration fc = new FileConfiguration();
@ -626,4 +640,12 @@ public class FileConfigurationTest extends ConfigurationImplTest {
deploymentManager.readConfiguration();
return fc;
}
public static class EmptyPlugin1 implements ActiveMQServerPlugin {
}
public static class EmptyPlugin2 implements ActiveMQServerPlugin {
}
}

View File

@ -0,0 +1,27 @@
<!--
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.
-->
<configuration
xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq ../../../../activemq-server/src/main/resources/schema/artemis-server.xsd">
<core xmlns="urn:activemq:core">
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$EmptyPlugin1" />
<broker-plugin class-name="org.apache.activemq.artemis.core.config.impl.FileConfigurationTest$EmptyPlugin2" />
</broker-plugins>
</core>
</configuration>

View File

@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@ -88,6 +89,10 @@ public class MethodCalledVerifier implements ActiveMQServerPlugin {
this.methodCalls = methodCalls;
}
public MethodCalledVerifier() {
this(new HashMap<String, AtomicInteger>());
}
@Override
public void afterCreateConnection(RemotingConnection connection) {
Preconditions.checkNotNull(connection);

View File

@ -0,0 +1,49 @@
/*
* 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.activemq.artemis.tests.integration.plugin;
import org.apache.activemq.artemis.core.config.FileDeploymentManager;
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.Test;
public class XmlConfigPluginTest extends ActiveMQTestBase {
@Test
public void testStopStart1() throws Exception {
FileConfiguration fc = new FileConfiguration();
FileJMSConfiguration fileConfiguration = new FileJMSConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager("broker-plugins-config.xml");
deploymentManager.addDeployable(fc);
deploymentManager.addDeployable(fileConfiguration);
deploymentManager.readConfiguration();
ActiveMQServer server = addServer(new ActiveMQServerImpl(fc));
try {
server.start();
assertEquals(1, server.getBrokerPlugins().size());
assertTrue(server.getBrokerPlugins().get(0) instanceof MethodCalledVerifier);
} finally {
if (server != null) {
server.stop();
}
}
}
}

View File

@ -0,0 +1,48 @@
<!--
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.
-->
<configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
<jms xmlns="urn:activemq:jms">
<queue name="myJMSQueue"/>
</jms>
<core xmlns="urn:activemq:core">
<connectors>
<connector name="netty-connector">tcp://localhost:61616</connector>
</connectors>
<journal-directory>./target/tmp/activemq-unit-test/broker-plugin-test/</journal-directory>
<acceptors>
<acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
</acceptors>
<security-enabled>false</security-enabled>
<queues>
<queue name="myQueue">
<address>myAddress</address>
</queue>
</queues>
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.tests.integration.plugin.MethodCalledVerifier" />
</broker-plugins>
</core>
</configuration>