broker/ProtocolProcessorBootstrapper: code formatter used

This commit is contained in:
Andreas Mager
2017-02-01 17:13:39 +01:00
parent db31f77f9b
commit e23ac97e8e
@@ -13,6 +13,7 @@
* *
* You may elect to redistribute this code under either of these licenses. * You may elect to redistribute this code under either of these licenses.
*/ */
package io.moquette.spi.impl; package io.moquette.spi.impl;
import io.moquette.BrokerConstants; import io.moquette.BrokerConstants;
@@ -35,7 +36,6 @@ import io.moquette.spi.security.IAuthenticator;
import io.moquette.spi.security.IAuthorizator; import io.moquette.spi.security.IAuthorizator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.text.ParseException; import java.text.ParseException;
@@ -68,17 +68,23 @@ public class ProtocolProcessorBootstrapper {
/** /**
* Initialize the processing part of the broker. * Initialize the processing part of the broker.
* @param props the properties carrier where some props like port end host could be loaded. *
* For the full list check of configurable properties check moquette.conf file. * @param props
* @param embeddedObservers a list of callbacks to be notified of certain events inside the broker. * the properties carrier where some props like port end host could be loaded. For
* Could be empty list of null. * the full list check of configurable properties check moquette.conf file.
* @param authenticator an implementation of the authenticator to be used, if null load that specified in config * @param embeddedObservers
* and fallback on the default one (permit all). * a list of callbacks to be notified of certain events inside the broker. Could be
* @param authorizator an implementation of the authorizator to be used, if null load that specified in config * empty list of null.
* and fallback on the default one (permit all). * @param authenticator
* @param server the serber to init. * an implementation of the authenticator to be used, if null load that specified in
* config and fallback on the default one (permit all).
* @param authorizator
* an implementation of the authorizator to be used, if null load that specified in
* config and fallback on the default one (permit all).
* @param server
* the serber to init.
* @return the processor created for the broker. * @return the processor created for the broker.
* */ */
public ProtocolProcessor init(IConfig props, List<? extends InterceptHandler> embeddedObservers, public ProtocolProcessor init(IConfig props, List<? extends InterceptHandler> embeddedObservers,
IAuthenticator authenticator, IAuthorizator authorizator, Server server) { IAuthenticator authenticator, IAuthorizator authorizator, Server server) {
subscriptions = new SubscriptionsStore(); subscriptions = new SubscriptionsStore();
@@ -136,8 +142,11 @@ public class ProtocolProcessorBootstrapper {
LOG.info("Parsing ACL file. Path = {}.", aclFilePath); LOG.info("Parsing ACL file. Path = {}.", aclFilePath);
authorizator = ACLFileParser.parse(resourceLoader.loadResource(aclFilePath)); authorizator = ACLFileParser.parse(resourceLoader.loadResource(aclFilePath));
} catch (ParseException pex) { } catch (ParseException pex) {
LOG.error("Unable to parse ACL file. Path = {}, cause = {}, errorMessage = {}.", aclFilePath, LOG.error(
pex.getCause(), pex.getMessage()); "Unable to parse ACL file. Path = {}, cause = {}, errorMessage = {}.",
aclFilePath,
pex.getCause(),
pex.getMessage());
} }
} else { } else {
authorizator = new PermitAllAuthorizator(); authorizator = new PermitAllAuthorizator();
@@ -149,9 +158,21 @@ public class ProtocolProcessorBootstrapper {
connectionDescriptors = new ConnectionDescriptorStore(m_sessionsStore); connectionDescriptors = new ConnectionDescriptorStore(m_sessionsStore);
LOG.info("Initializing MQTT protocol processor..."); LOG.info("Initializing MQTT protocol processor...");
boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, "true")); boolean allowAnonymous = Boolean
boolean allowZeroByteClientId = Boolean.parseBoolean(props.getProperty(BrokerConstants.ALLOW_ZERO_BYTE_CLIENT_ID_PROPERTY_NAME, "false")); .parseBoolean(props.getProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, "true"));
m_processor.init(connectionDescriptors, subscriptions, messagesStore, m_sessionsStore, authenticator, allowAnonymous, allowZeroByteClientId, authorizator, m_interceptor, props.getProperty(BrokerConstants.PORT_PROPERTY_NAME)); boolean allowZeroByteClientId = Boolean
.parseBoolean(props.getProperty(BrokerConstants.ALLOW_ZERO_BYTE_CLIENT_ID_PROPERTY_NAME, "false"));
m_processor.init(
connectionDescriptors,
subscriptions,
messagesStore,
m_sessionsStore,
authenticator,
allowAnonymous,
allowZeroByteClientId,
authorizator,
m_interceptor,
props.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
return m_processor; return m_processor;
} }
@@ -165,38 +186,58 @@ public class ProtocolProcessorBootstrapper {
// check if method getInstance exists // check if method getInstance exists
Method method = clazz.getMethod("getInstance", new Class[]{}); Method method = clazz.getMethod("getInstance", new Class[]{});
try { try {
LOG.info("Invoking getInstance() method. ClassName = {}, interfaceName = {}.", className, LOG.info(
"Invoking getInstance() method. ClassName = {}, interfaceName = {}.",
className,
iface.getName()); iface.getName());
instance = (T) method.invoke(null, new Object[]{}); instance = (T) method.invoke(null, new Object[]{});
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) { } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) {
LOG.error( LOG.error(
"Unable to invoke getInstance() method. ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.", "Unable to invoke getInstance() method. "
className, iface.getName(), ex.getCause(), ex.getMessage()); + "ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.",
className,
iface.getName(),
ex.getCause(),
ex.getMessage());
return null; return null;
} }
} catch (NoSuchMethodException nsmex) { } catch (NoSuchMethodException nsmex) {
try { try {
// check if constructor with constructor arg class parameter // check if constructor with constructor arg class parameter
// exists // exists
LOG.info("Invoking constructor with {} argument. ClassName = {}, interfaceName = {}.", LOG.info(
constructorArgClass.getName(), className, iface.getName()); "Invoking constructor with {} argument. ClassName = {}, interfaceName = {}.",
constructorArgClass.getName(),
className,
iface.getName());
instance = this.getClass().getClassLoader().loadClass(className).asSubclass(iface) instance = this.getClass().getClassLoader().loadClass(className).asSubclass(iface)
.getConstructor(constructorArgClass).newInstance(props); .getConstructor(constructorArgClass).newInstance(props);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) { } catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
LOG.warn( LOG.warn(
"Unable to invoke constructor with {} argument. ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.", "Unable to invoke constructor with {} argument. "
constructorArgClass.getName(), className, iface.getName(), ex.getCause(), ex.getMessage()); + "ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.",
constructorArgClass.getName(),
className,
iface.getName(),
ex.getCause(),
ex.getMessage());
return null; return null;
} catch (NoSuchMethodException | InvocationTargetException e) { } catch (NoSuchMethodException | InvocationTargetException e) {
try { try {
LOG.info("Invoking default constructor. ClassName = {}, interfaceName = {}.", className, LOG.info(
"Invoking default constructor. ClassName = {}, interfaceName = {}.",
className,
iface.getName()); iface.getName());
// fallback to default constructor // fallback to default constructor
instance = this.getClass().getClassLoader().loadClass(className).asSubclass(iface).newInstance(); instance = this.getClass().getClassLoader().loadClass(className).asSubclass(iface).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) { } catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
LOG.error( LOG.error(
"Unable to invoke default constructor. ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.", "Unable to invoke default constructor. "
className, iface.getName(), ex.getCause(), ex.getMessage()); + "ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.",
className,
iface.getName(),
ex.getCause(),
ex.getMessage());
return null; return null;
} }
} }
@@ -205,8 +246,12 @@ public class ProtocolProcessorBootstrapper {
return null; return null;
} catch (SecurityException ex) { } catch (SecurityException ex) {
LOG.error( LOG.error(
"Unable to load class due to a security violation. ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.", "Unable to load class due to a security violation. "
className, iface.getName(), ex.getCause(), ex.getMessage()); + "ClassName = {}, interfaceName = {}, cause = {}, errorMessage = {}.",
className,
iface.getName(),
ex.getCause(),
ex.getMessage());
return null; return null;
} }