Search in sources :

Example 1 with StoreConfiguration

use of org.apache.activemq.artemis.core.config.StoreConfiguration in project activemq-artemis by apache.

the class OsgiBroker method activate.

@Activate
public void activate(ComponentContext cctx) throws Exception {
    final BundleContext context = cctx.getBundleContext();
    final Dictionary<String, Object> properties = cctx.getProperties();
    configurationUrl = getMandatory(properties, "config");
    name = getMandatory(properties, "name");
    rolePrincipalClass = (String) properties.get("rolePrincipalClass");
    String domain = getMandatory(properties, "domain");
    ActiveMQJAASSecurityManager security = new ActiveMQJAASSecurityManager(domain);
    if (rolePrincipalClass != null) {
        security.setRolePrincipalClass(rolePrincipalClass);
    }
    String brokerInstance = null;
    String karafDataDir = System.getProperty("karaf.data");
    if (karafDataDir != null) {
        brokerInstance = karafDataDir + "/artemis/" + name;
    }
    // todo if we start to pullout more configs from the main config then we
    // should pull out the configuration objects from factories if available
    FileConfiguration configuration = new FileConfiguration();
    if (brokerInstance != null) {
        configuration.setBrokerInstance(new File(brokerInstance));
    }
    FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
    FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
    fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration).readConfiguration();
    components = fileDeploymentManager.buildService(security, ManagementFactory.getPlatformMBeanServer());
    final ActiveMQServer server = (ActiveMQServer) components.get("core");
    String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations());
    ServerTrackerCallBack callback = new ServerTrackerCallBackImpl(server, context, properties);
    StoreConfiguration storeConfiguration = server.getConfiguration().getStoreConfiguration();
    String dataSourceName = String.class.cast(properties.get("dataSourceName"));
    if (storeConfiguration != null && storeConfiguration.getStoreType() == StoreType.DATABASE && dataSourceName != null && !dataSourceName.isEmpty()) {
        callback.setDataSourceDependency(true);
        String filter = "(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=" + dataSourceName + "))";
        DataSourceTracker trackerCust = new DataSourceTracker(name, context, DatabaseStorageConfiguration.class.cast(storeConfiguration), (ServerTrackerCallBack) callback);
        dataSourceTracker = new ServiceTracker(context, context.createFilter(filter), trackerCust);
        dataSourceTracker.open();
    }
    ProtocolTracker trackerCust = new ProtocolTracker(name, context, requiredProtocols, callback);
    tracker = new ServiceTracker(context, ProtocolManagerFactory.class, trackerCust);
    tracker.open();
}
Also used : ProtocolManagerFactory(org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) FileConfiguration(org.apache.activemq.artemis.core.config.impl.FileConfiguration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) FileJMSConfiguration(org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

File (java.io.File)1 FileDeploymentManager (org.apache.activemq.artemis.core.config.FileDeploymentManager)1 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)1 FileConfiguration (org.apache.activemq.artemis.core.config.impl.FileConfiguration)1 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 FileJMSConfiguration (org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration)1 ProtocolManagerFactory (org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory)1 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)1 BundleContext (org.osgi.framework.BundleContext)1 Activate (org.osgi.service.component.annotations.Activate)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1