use of org.wso2.broker.common.StartupContext in project carbon-apimgt by wso2.
the class BrokerManager method initConfigProvider.
/**
* Loads configurations during the broker start up.
* method will try to <br/>
* (1) Load the configuration file specified in 'broker.file' (e.g. -Dbroker.file=<FilePath>). <br/>
* (2) If -Dbroker.file is not specified, the broker.yaml file exists in current directory and load it. <br/>
* <p>
* <b>Note: </b> if provided configuration file cannot be read broker will not start.
*
* @param startupContext startup context of the broker
*/
private static void initConfigProvider(StartupContext startupContext) throws ConfigurationException {
Path brokerYamlFile;
String brokerFilePath = System.getProperty(BrokerConfiguration.SYSTEM_PARAM_BROKER_CONFIG_FILE);
if (brokerFilePath == null || brokerFilePath.trim().isEmpty()) {
// use current path.
brokerYamlFile = Paths.get("", BrokerConfiguration.BROKER_FILE_NAME).toAbsolutePath();
} else {
brokerYamlFile = Paths.get(brokerFilePath).toAbsolutePath();
}
ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(brokerYamlFile, null);
startupContext.registerService(BrokerConfigProvider.class, (BrokerConfigProvider) configProvider::getConfigurationObject);
}
use of org.wso2.broker.common.StartupContext in project carbon-apimgt by wso2.
the class BrokerManager method start.
/**
* Starting the broker
*/
public static void start() {
try {
StartupContext startupContext = new StartupContext();
initConfigProvider(startupContext);
BrokerConfigProvider service = startupContext.getService(BrokerConfigProvider.class);
BrokerConfiguration brokerConfiguration = service.getConfigurationObject(BrokerConfiguration.NAMESPACE, BrokerConfiguration.class);
DataSource dataSource = getDataSource(brokerConfiguration.getDataSource());
startupContext.registerService(DataSource.class, dataSource);
restServer = new BrokerRestServer(startupContext);
broker = new Broker(startupContext);
broker.startMessageDelivery();
amqpServer = new Server(startupContext);
amqpServer.start();
restServer.start();
loadUsers();
} catch (Exception e) {
log.error("Error while starting broker", e);
}
}
Aggregations