From a4f4bc5a11d571b50f1ff40e3726d7fb2277972e Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Sat, 28 Mar 2026 23:04:53 -0500 Subject: [PATCH] ARTEMIS-5974 replace FactoryFinder with Java ServiceLoader --- .../artemis/cli/factory/BrokerFactory.java | 29 ++-- .../cli/factory/BrokerFactoryHandler.java | 2 + .../artemis/cli/factory/BrokerHandler.java | 2 + .../cli/factory/FileBrokerHandler.java | 5 + .../cli/factory/jmx/JmxAclHandler.java | 3 + .../cli/factory/jmx/ManagementFactory.java | 15 +- .../cli/factory/jmx/XmlJmxAclHandler.java | 6 + .../factory/security/JaasSecurityHandler.java | 5 + .../cli/factory/security/SecurityHandler.java | 2 + .../security/SecurityManagerFactory.java | 16 +- .../security/SecurityManagerHandler.java | 5 + .../factory/xml/XmlBrokerFactoryHandler.java | 5 + ...q.artemis.cli.factory.BrokerFactoryHandler | 18 +++ ...activemq.artemis.cli.factory.BrokerHandler | 18 +++ ...vemq.artemis.cli.factory.jmx.JmxAclHandler | 18 +++ ...temis.cli.factory.security.SecurityHandler | 19 +++ .../apache/activemq/artemis/broker/jmx/xml | 17 -- .../artemis/broker/security/jaas-security | 17 -- .../artemis/broker/security/security-manager | 17 -- .../activemq/artemis/broker/server/file | 17 -- .../org/apache/activemq/artemis/broker/xml | 17 -- .../cli/factory/TestBrokerFactoryHandler.java | 5 + ...q.artemis.cli.factory.BrokerFactoryHandler | 1 + .../org/apache/activemq/artemis/broker/test | 17 -- .../activemq/artemis/utils/FactoryFinder.java | 153 ------------------ 25 files changed, 154 insertions(+), 275 deletions(-) create mode 100644 artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler create mode 100644 artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerHandler create mode 100644 artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.jmx.JmxAclHandler create mode 100644 artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.security.SecurityHandler delete mode 100644 artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/jmx/xml delete mode 100644 artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/jaas-security delete mode 100644 artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/security-manager delete mode 100644 artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/server/file delete mode 100644 artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/xml create mode 100644 artemis-cli/src/test/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler delete mode 100644 artemis-cli/src/test/resources/META-INF/services/org/apache/activemq/artemis/broker/test delete mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/utils/FactoryFinder.java diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactory.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactory.java index 181207239e8..7aa65d52c25 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactory.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactory.java @@ -16,12 +16,12 @@ */ package org.apache.activemq.artemis.cli.factory; -import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.Objects; import java.util.Optional; import java.util.Properties; +import java.util.ServiceLoader; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.cli.ConfigurationException; @@ -33,7 +33,6 @@ import org.apache.activemq.artemis.dto.ServerDTO; import org.apache.activemq.artemis.integration.Broker; import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; -import org.apache.activemq.artemis.utils.FactoryFinder; public class BrokerFactory { @@ -50,11 +49,15 @@ private static BrokerDTO createBrokerConfiguration(URI configURI, throw new ConfigurationException("Invalid configuration URI, no scheme specified: " + configURI); } + ServiceLoader loader = ServiceLoader.load(BrokerFactoryHandler.class, BrokerFactory.class.getClassLoader()); BrokerFactoryHandler factory = null; - try { - FactoryFinder finder = new FactoryFinder("META-INF/services/org/apache/activemq/artemis/broker/"); - factory = (BrokerFactoryHandler) finder.newInstance(configURI.getScheme()); - } catch (IOException ioe) { + for (BrokerFactoryHandler handler : loader) { + if (handler.getName().equals(configURI.getScheme())) { + factory = handler; + break; + } + } + if (factory == null) { throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme()); } BrokerDTO broker = factory.createBroker(configURI, artemisHome, artemisInstance, artemisURIInstance); @@ -104,13 +107,17 @@ public static BrokerDTO createBrokerConfiguration(String configuration, public static Broker createServer(ServerDTO brokerDTO, ActiveMQSecurityManager security, ActivateCallback activateCallback) throws Exception { if (brokerDTO.configuration != null) { - BrokerHandler handler; URI configURI = brokerDTO.getConfigurationURI(); - try { - FactoryFinder finder = new FactoryFinder("META-INF/services/org/apache/activemq/artemis/broker/server/"); - handler = (BrokerHandler) finder.newInstance(configURI.getScheme()); - } catch (IOException ioe) { + ServiceLoader loader = ServiceLoader.load(BrokerHandler.class, BrokerFactory.class.getClassLoader()); + BrokerHandler handler = null; + for (BrokerHandler h : loader) { + if (h.getName().equals(configURI.getScheme())) { + handler = h; + break; + } + } + if (handler == null) { throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme()); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactoryHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactoryHandler.java index 2d16c3ae0dc..71a56787742 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactoryHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerFactoryHandler.java @@ -22,5 +22,7 @@ public interface BrokerFactoryHandler { + String getName(); + BrokerDTO createBroker(URI brokerURI, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerHandler.java index 513206c1ea9..12ae9f425cd 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/BrokerHandler.java @@ -23,5 +23,7 @@ public interface BrokerHandler { + String getName(); + Broker createServer(ServerDTO brokerDTO, ActiveMQSecurityManager security, ActivateCallback activateCallback); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/FileBrokerHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/FileBrokerHandler.java index 2b5faecd75e..9054a1d94d5 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/FileBrokerHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/FileBrokerHandler.java @@ -24,6 +24,11 @@ public class FileBrokerHandler implements BrokerHandler { + @Override + public String getName() { + return "file"; + } + @Override public Broker createServer(ServerDTO brokerDTO, ActiveMQSecurityManager security, ActivateCallback activateCallback) { return new FileBroker(brokerDTO, security, activateCallback); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/JmxAclHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/JmxAclHandler.java index 95ee33d2f6e..44344320dc5 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/JmxAclHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/JmxAclHandler.java @@ -21,5 +21,8 @@ import java.net.URI; public interface JmxAclHandler { + + String getName(); + ManagementContextDTO createJmxAcl(URI configURI, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/ManagementFactory.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/ManagementFactory.java index 687e67140ef..618c2853f1c 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/ManagementFactory.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/ManagementFactory.java @@ -31,11 +31,10 @@ import org.apache.activemq.artemis.core.server.management.JMXAccessControlList; import org.apache.activemq.artemis.dto.WhiteListDTO; import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; -import org.apache.activemq.artemis.utils.FactoryFinder; -import java.io.IOException; import java.net.URI; import java.util.List; +import java.util.ServiceLoader; public class ManagementFactory { @@ -47,11 +46,15 @@ private static ManagementContextDTO createJmxAclConfiguration(URI configURI, throw new ConfigurationException("Invalid configuration URI, no scheme specified: " + configURI); } + ServiceLoader loader = ServiceLoader.load(JmxAclHandler.class, ManagementFactory.class.getClassLoader()); JmxAclHandler factory = null; - try { - FactoryFinder finder = new FactoryFinder("META-INF/services/org/apache/activemq/artemis/broker/jmx/"); - factory = (JmxAclHandler) finder.newInstance(configURI.getScheme()); - } catch (IOException ioe) { + for (JmxAclHandler handler : loader) { + if (handler.getName().equals(configURI.getScheme())) { + factory = handler; + break; + } + } + if (factory == null) { throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme()); } return factory.createJmxAcl(configURI, artemisHome, artemisInstance, artemisURIInstance); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/XmlJmxAclHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/XmlJmxAclHandler.java index 41a0b1c23a9..7a4d6840490 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/XmlJmxAclHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/jmx/XmlJmxAclHandler.java @@ -25,6 +25,12 @@ import java.net.URI; public class XmlJmxAclHandler implements JmxAclHandler { + + @Override + public String getName() { + return "xml"; + } + @Override public ManagementContextDTO createJmxAcl(URI configURI, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception { File file = new File(configURI.getSchemeSpecificPart()); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/JaasSecurityHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/JaasSecurityHandler.java index a096567b4e2..84629307db8 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/JaasSecurityHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/JaasSecurityHandler.java @@ -23,6 +23,11 @@ public class JaasSecurityHandler implements SecurityHandler { + @Override + public String getName() { + return "jaas-security"; + } + @Override public ActiveMQSecurityManager createSecurityManager(SecurityDTO security) throws Exception { JaasSecurityDTO jaasSecurity = (JaasSecurityDTO) security; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityHandler.java index df905178eb9..7aecda8e036 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityHandler.java @@ -21,5 +21,7 @@ public interface SecurityHandler { + String getName(); + ActiveMQSecurityManager createSecurityManager(SecurityDTO securityDTO) throws Exception; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerFactory.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerFactory.java index 3ebf8c3faef..05a63803617 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerFactory.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerFactory.java @@ -16,11 +16,11 @@ */ package org.apache.activemq.artemis.cli.factory.security; +import java.util.ServiceLoader; import javax.xml.bind.annotation.XmlRootElement; import org.apache.activemq.artemis.dto.SecurityDTO; import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; -import org.apache.activemq.artemis.utils.FactoryFinder; public class SecurityManagerFactory { @@ -28,8 +28,18 @@ public static ActiveMQSecurityManager create(SecurityDTO config) throws Exceptio if (config == null) { throw new Exception("No security manager configured!"); } - FactoryFinder finder = new FactoryFinder("META-INF/services/org/apache/activemq/artemis/broker/security/"); - SecurityHandler securityHandler = (SecurityHandler) finder.newInstance(config.getClass().getAnnotation(XmlRootElement.class).name()); + String name = config.getClass().getAnnotation(XmlRootElement.class).name(); + ServiceLoader loader = ServiceLoader.load(SecurityHandler.class, SecurityManagerFactory.class.getClassLoader()); + SecurityHandler securityHandler = null; + for (SecurityHandler handler : loader) { + if (handler.getName().equals(name)) { + securityHandler = handler; + break; + } + } + if (securityHandler == null) { + throw new Exception("Invalid security configuration, can't find security handler: " + name); + } return securityHandler.createSecurityManager(config); } } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerHandler.java index 166b8aa7597..b1791acd823 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/security/SecurityManagerHandler.java @@ -29,6 +29,11 @@ public class SecurityManagerHandler implements SecurityHandler { + @Override + public String getName() { + return "security-manager"; + } + @Override public ActiveMQSecurityManager createSecurityManager(SecurityDTO security) { SecurityManagerDTO customSecurity = (SecurityManagerDTO) security; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/xml/XmlBrokerFactoryHandler.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/xml/XmlBrokerFactoryHandler.java index 828425286fa..a2d4d5c91e4 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/xml/XmlBrokerFactoryHandler.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/factory/xml/XmlBrokerFactoryHandler.java @@ -26,6 +26,11 @@ public class XmlBrokerFactoryHandler implements BrokerFactoryHandler { + @Override + public String getName() { + return "xml"; + } + @Override public BrokerDTO createBroker(URI brokerURI, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception { File file = new File(brokerURI.getSchemeSpecificPart()); diff --git a/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler new file mode 100644 index 00000000000..f3091cf94c2 --- /dev/null +++ b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler @@ -0,0 +1,18 @@ +# 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. + +org.apache.activemq.artemis.cli.factory.xml.XmlBrokerFactoryHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerHandler b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerHandler new file mode 100644 index 00000000000..44767a961dd --- /dev/null +++ b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerHandler @@ -0,0 +1,18 @@ +# 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. + +org.apache.activemq.artemis.cli.factory.FileBrokerHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.jmx.JmxAclHandler b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.jmx.JmxAclHandler new file mode 100644 index 00000000000..589ab3ebf5b --- /dev/null +++ b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.jmx.JmxAclHandler @@ -0,0 +1,18 @@ +# 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. + +org.apache.activemq.artemis.cli.factory.jmx.XmlJmxAclHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.security.SecurityHandler b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.security.SecurityHandler new file mode 100644 index 00000000000..10696863420 --- /dev/null +++ b/artemis-cli/src/main/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.security.SecurityHandler @@ -0,0 +1,19 @@ +# 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. + +org.apache.activemq.artemis.cli.factory.security.JaasSecurityHandler +org.apache.activemq.artemis.cli.factory.security.SecurityManagerHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/jmx/xml b/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/jmx/xml deleted file mode 100644 index 3d2dd012fe8..00000000000 --- a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/jmx/xml +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.artemis.cli.factory.jmx.XmlJmxAclHandler \ No newline at end of file diff --git a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/jaas-security b/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/jaas-security deleted file mode 100644 index b05ff707ce5..00000000000 --- a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/jaas-security +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.artemis.cli.factory.security.JaasSecurityHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/security-manager b/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/security-manager deleted file mode 100644 index 128f2260e59..00000000000 --- a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/security/security-manager +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.artemis.cli.factory.security.SecurityManagerHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/server/file b/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/server/file deleted file mode 100644 index 59419dd2023..00000000000 --- a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/server/file +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.artemis.cli.factory.FileBrokerHandler diff --git a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/xml b/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/xml deleted file mode 100644 index 4f7943d95ec..00000000000 --- a/artemis-cli/src/main/resources/META-INF/services/org/apache/activemq/artemis/broker/xml +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.artemis.cli.factory.xml.XmlBrokerFactoryHandler diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/factory/TestBrokerFactoryHandler.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/factory/TestBrokerFactoryHandler.java index 7bae00bc59c..44dd6b883ce 100644 --- a/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/factory/TestBrokerFactoryHandler.java +++ b/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/factory/TestBrokerFactoryHandler.java @@ -76,6 +76,11 @@ public static void clear() { broker = null; } + @Override + public String getName() { + return "test"; + } + @Override public BrokerDTO createBroker(URI brokerURI, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception { TestBrokerFactoryHandler.brokerURI = brokerURI; diff --git a/artemis-cli/src/test/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler b/artemis-cli/src/test/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler new file mode 100644 index 00000000000..1edbe842ab2 --- /dev/null +++ b/artemis-cli/src/test/resources/META-INF/services/org.apache.activemq.artemis.cli.factory.BrokerFactoryHandler @@ -0,0 +1 @@ +org.apache.activemq.artemis.cli.factory.TestBrokerFactoryHandler diff --git a/artemis-cli/src/test/resources/META-INF/services/org/apache/activemq/artemis/broker/test b/artemis-cli/src/test/resources/META-INF/services/org/apache/activemq/artemis/broker/test deleted file mode 100644 index 4259e4bb648..00000000000 --- a/artemis-cli/src/test/resources/META-INF/services/org/apache/activemq/artemis/broker/test +++ /dev/null @@ -1,17 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -class=org.apache.activemq.artemis.cli.factory.TestBrokerFactoryHandler diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/FactoryFinder.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/FactoryFinder.java deleted file mode 100644 index 2373d5748f6..00000000000 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/FactoryFinder.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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.utils; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -public class FactoryFinder { - - /** - * The strategy that the FactoryFinder uses to find load and instantiate Objects can be changed out by calling the - * setObjectFactory method with a custom implementation of ObjectFactory. - *

- * The default ObjectFactory is typically changed out when running in a specialized container environment where - * service discovery needs to be done via the container system. For example, in an OSGi scenario. - */ - public interface ObjectFactory { - - /** - * Creates an {@code Object} based on the input - * - * @param path the full service path - * @return {@code Object} - * @throws IllegalAccessException illegal access - * @throws InstantiationException on instantiation error - * @throws IOException On IO Error - * @throws ClassNotFoundException On class not found error - */ - Object create(String path) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException; - - } - - /** - * The default implementation of Object factory which works well in standalone applications. - */ - protected static class StandaloneObjectFactory implements ObjectFactory { - - final ConcurrentMap classMap = new ConcurrentHashMap<>(); - - @Override - public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException { - Class clazz = classMap.get(path); - if (clazz == null) { - clazz = loadClass(loadProperties(path)); - classMap.put(path, clazz); - } - try { - return clazz.getDeclaredConstructor().newInstance(); - } catch (NoSuchMethodException | InvocationTargetException e) { - throw new IOException(e); - } - } - - static Class loadClass(Properties properties) throws ClassNotFoundException, IOException { - - String className = properties.getProperty("class"); - if (className == null) { - throw new IOException("Expected property is missing: class"); - } - Class clazz = null; - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - if (loader != null) { - try { - clazz = loader.loadClass(className); - } catch (ClassNotFoundException e) { - // ignore - } - } - if (clazz == null) { - clazz = FactoryFinder.class.getClassLoader().loadClass(className); - } - - return clazz; - } - - public Properties loadProperties(String uri) throws IOException { - // lets try the thread context class loader first - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = StandaloneObjectFactory.class.getClassLoader(); - } - InputStream in = classLoader.getResourceAsStream(uri); - if (in == null) { - in = FactoryFinder.class.getClassLoader().getResourceAsStream(uri); - if (in == null) { - throw new IOException("Could not find factory class for resource: " + uri); - } - } - - // lets load the file - try (BufferedInputStream reader = new BufferedInputStream(in)) { - Properties properties = new Properties(); - properties.load(reader); - return properties; - } - } - } - - // ================================================================ - // Class methods and properties - // ================================================================ - private static ObjectFactory objectFactory = new StandaloneObjectFactory(); - - public static ObjectFactory getObjectFactory() { - return objectFactory; - } - - public static void setObjectFactory(ObjectFactory objectFactory) { - FactoryFinder.objectFactory = objectFactory; - } - - // ================================================================ - // Instance methods and properties - // ================================================================ - private final String path; - - public FactoryFinder(String path) { - this.path = path; - } - - /** - * Creates a new instance of the given key - * - * @param key is the key to add to the path to find a text file containing the factory name - * @return a newly created instance - * @throws IllegalAccessException On illegal access - * @throws InstantiationException On can not instantiate exception - * @throws IOException On IOException - * @throws ClassNotFoundException When class not on class path - */ - public Object newInstance(String key) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException { - return objectFactory.create(path + key); - } -}