File logConfigFile = getConfigFile(options.getLogConfigFile(),
BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);
configureLogging(logConfigFile, options.getLogWatchFrequency());
ServerConfiguration serverConfig = new ServerConfiguration(configFile);
ApplicationRegistry config = new ApplicationRegistry(serverConfig);
if (options.getQpidWork() != null)
{
serverConfig.setQpidWork(options.getQpidWork());
}
if (options.getQpidHome() != null)
{
serverConfig.setQpidHome(options.getQpidHome());
}
updateManagementPorts(serverConfig, options.getJmxPortRegistryServer(), options.getJmxPortConnectorServer());
ApplicationRegistry.initialise(config);
// We have already loaded the BrokerMessages class by this point so we
// need to refresh the locale setting incase we had a different value in
// the configuration.
BrokerMessages.reload();
// AR.initialise() sets and removes its own actor so we now need to set the actor
// for the remainder of the startup, and the default actor if the stack is empty
CurrentActor.set(new BrokerActor(config.getCompositeStartupMessageLogger()));
CurrentActor.setDefault(new BrokerActor(config.getRootMessageLogger()));
GenericActor.setDefaultMessageLogger(config.getRootMessageLogger());
try
{
Set<Integer> ports = new HashSet<Integer>(options.getPorts());
if(ports.isEmpty())
{
parsePortList(ports, serverConfig.getPorts());
}
Set<Integer> sslPorts = new HashSet<Integer>(options.getSSLPorts());
if(sslPorts.isEmpty())
{
parsePortList(sslPorts, serverConfig.getSSLPorts());
}
//1-0 excludes and includes
Set<Integer> exclude_1_0 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v1_0));
if(exclude_1_0.isEmpty())
{
parsePortList(exclude_1_0, serverConfig.getPortExclude10());
}
Set<Integer> include_1_0 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v1_0));
if(include_1_0.isEmpty())
{
parsePortList(include_1_0, serverConfig.getPortInclude10());
}
//0-10 excludes and includes
Set<Integer> exclude_0_10 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_10));
if(exclude_0_10.isEmpty())
{
parsePortList(exclude_0_10, serverConfig.getPortExclude010());
}
Set<Integer> include_0_10 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_10));
if(include_0_10.isEmpty())
{
parsePortList(include_0_10, serverConfig.getPortInclude010());
}
//0-9-1 excludes and includes
Set<Integer> exclude_0_9_1 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_9_1));
if(exclude_0_9_1.isEmpty())
{
parsePortList(exclude_0_9_1, serverConfig.getPortExclude091());
}
Set<Integer> include_0_9_1 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_9_1));
if(include_0_9_1.isEmpty())
{
parsePortList(include_0_9_1, serverConfig.getPortInclude091());
}
//0-9 excludes and includes
Set<Integer> exclude_0_9 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_9));
if(exclude_0_9.isEmpty())
{
parsePortList(exclude_0_9, serverConfig.getPortExclude09());
}
Set<Integer> include_0_9 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_9));
if(include_0_9.isEmpty())
{
parsePortList(include_0_9, serverConfig.getPortInclude09());
}
//0-8 excludes and includes
Set<Integer> exclude_0_8 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_8));
if(exclude_0_8.isEmpty())
{
parsePortList(exclude_0_8, serverConfig.getPortExclude08());
}
Set<Integer> include_0_8 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_8));
if(include_0_8.isEmpty())
{
parsePortList(include_0_8, serverConfig.getPortInclude08());
}
String bindAddr = options.getBind();
if (bindAddr == null)
{
bindAddr = serverConfig.getBind();
}
InetAddress bindAddress;
if (bindAddr.equals(WILDCARD_ADDRESS))
{
bindAddress = null;
}
else
{
bindAddress = InetAddress.getByName(bindAddr);
}
final AmqpProtocolVersion defaultSupportedProtocolReply = serverConfig.getDefaultSupportedProtocolReply();
if (!serverConfig.getSSLOnly())
{
for(int port : ports)
{
final InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, port);
final Set<AmqpProtocolVersion> supported =
getSupportedVersions(port, exclude_1_0, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8,
include_1_0, include_0_10, include_0_9_1, include_0_9, include_0_8,serverConfig);
final NetworkTransportConfiguration settings =
new ServerNetworkTransportConfiguration(serverConfig, inetSocketAddress, Transport.TCP);
final IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
final MultiVersionProtocolEngineFactory protocolEngineFactory =
new MultiVersionProtocolEngineFactory(supported, defaultSupportedProtocolReply);
transport.accept(settings, protocolEngineFactory, null);
ApplicationRegistry.getInstance().addAcceptor(inetSocketAddress,
new QpidAcceptor(transport,QpidAcceptor.Transport.TCP, supported));
CurrentActor.get().message(BrokerMessages.LISTENING("TCP", port));
}
}
if (serverConfig.getEnableSSL())
{
final String keystorePath = serverConfig.getConnectorKeyStorePath();
final String keystorePassword = serverConfig.getConnectorKeyStorePassword();
final String keystoreType = serverConfig.getConnectorKeyStoreType();
final String keyManagerFactoryAlgorithm = serverConfig.getConnectorKeyManagerFactoryAlgorithm();
final SSLContext sslContext;
if(serverConfig.getConnectorTrustStorePath()!=null)
{
sslContext = SSLContextFactory.buildClientContext(serverConfig.getConnectorTrustStorePath(),
serverConfig.getConnectorTrustStorePassword(),
serverConfig.getConnectorTrustStoreType(),
serverConfig.getConnectorTrustManagerFactoryAlgorithm(),
keystorePath,
keystorePassword, keystoreType, keyManagerFactoryAlgorithm,
serverConfig.getCertAlias());
}
else
{
sslContext = SSLContextFactory.buildServerContext(keystorePath, keystorePassword, keystoreType, keyManagerFactoryAlgorithm);
}