Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -50,11 +49,15 @@ private static BrokerDTO createBrokerConfiguration(URI configURI,
throw new ConfigurationException("Invalid configuration URI, no scheme specified: " + configURI);
}

ServiceLoader<BrokerFactoryHandler> 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);
Expand Down Expand Up @@ -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<BrokerHandler> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@

public interface BrokerFactoryHandler {

String getName();

BrokerDTO createBroker(URI brokerURI, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@

public interface BrokerHandler {

String getName();

Broker createServer(ServerDTO brokerDTO, ActiveMQSecurityManager security, ActivateCallback activateCallback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -47,11 +46,15 @@ private static ManagementContextDTO createJmxAclConfiguration(URI configURI,
throw new ConfigurationException("Invalid configuration URI, no scheme specified: " + configURI);
}

ServiceLoader<JmxAclHandler> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@

public interface SecurityHandler {

String getName();

ActiveMQSecurityManager createSecurityManager(SecurityDTO securityDTO) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@
*/
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 {

public static ActiveMQSecurityManager create(SecurityDTO config) throws Exception {
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<SecurityHandler> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.activemq.artemis.cli.factory.xml.XmlBrokerFactoryHandler
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like these service definitions can still have Apache license headers added as the ServiceLoader javadocs indicates it will ignore anything following the '#' character

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.activemq.artemis.cli.factory.FileBrokerHandler
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.activemq.artemis.cli.factory.jmx.XmlJmxAclHandler
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.apache.activemq.artemis.cli.factory.security.JaasSecurityHandler
org.apache.activemq.artemis.cli.factory.security.SecurityManagerHandler

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.activemq.artemis.cli.factory.TestBrokerFactoryHandler

This file was deleted.

Loading