ARTEMIS-793 Improvements to OSGi Integration

This commit is contained in:
Clebert Suconic 2016-10-19 16:51:03 -04:00
parent 2020dcd290
commit 128a505891
5 changed files with 30 additions and 54 deletions

View File

@ -96,13 +96,15 @@ public class OsgiBroker {
final ActiveMQServer server = (ActiveMQServer) components.get("core"); final ActiveMQServer server = (ActiveMQServer) components.get("core");
String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations()); String[] requiredProtocols = getRequiredProtocols(server.getConfiguration().getAcceptorConfigurations());
ProtocolTrackerCallBack callback = new ProtocolTrackerCallBackImpl(server, context, properties); ServerTrackerCallBack callback = new ServerTrackerCallBackImpl(server, context, properties);
StoreConfiguration storeConfiguration = server.getConfiguration().getStoreConfiguration(); StoreConfiguration storeConfiguration = server.getConfiguration().getStoreConfiguration();
String dataSourceName = String.class.cast(properties.get("dataSourceName")); String dataSourceName = String.class.cast(properties.get("dataSourceName"));
if (storeConfiguration.getStoreType() == StoreType.DATABASE && dataSourceName != null &&
if (storeConfiguration != null &&
storeConfiguration.getStoreType() == StoreType.DATABASE && dataSourceName != null &&
!dataSourceName.isEmpty()) { !dataSourceName.isEmpty()) {
callback = new ServerTrackerCallBackImpl(server, context, properties); callback.setDataSourceDependency(true);
String filter = "(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=" + dataSourceName + "))"; String filter = "(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=" + dataSourceName + "))";
DataSourceTracker trackerCust = DataSourceTracker trackerCust =
new DataSourceTracker(name, context, DatabaseStorageConfiguration.class.cast(storeConfiguration), new DataSourceTracker(name, context, DatabaseStorageConfiguration.class.cast(storeConfiguration),
@ -207,13 +209,15 @@ public class OsgiBroker {
} }
} }
private class ProtocolTrackerCallBackImpl implements ProtocolTrackerCallBack { private class ServerTrackerCallBackImpl implements ServerTrackerCallBack {
private volatile boolean dataSourceDependency = false;
private final ActiveMQServer server; private final ActiveMQServer server;
private final BundleContext context; private final BundleContext context;
private final Dictionary<String, Object> properties; private final Dictionary<String, Object> properties;
ProtocolTrackerCallBackImpl(ActiveMQServer server, BundleContext context, ServerTrackerCallBackImpl(ActiveMQServer server, BundleContext context,
Dictionary<String, Object> properties) { Dictionary<String, Object> properties) {
this.server = server; this.server = server;
this.context = context; this.context = context;
@ -242,37 +246,28 @@ public class OsgiBroker {
@Override @Override
public void start() throws Exception { public void start() throws Exception {
List<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components); if (!dataSourceDependency) {
for (ActiveMQComponent component : componentsByStartOrder) { List<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
component.start(); for (ActiveMQComponent component : componentsByStartOrder) {
component.start();
}
register(context, properties);
} }
register(context, properties);
} }
@Override @Override
public boolean isStarted() { public boolean isStarted() {
return server.isStarted(); return server.isStarted();
} }
}
private class ServerTrackerCallBackImpl extends ProtocolTrackerCallBackImpl implements ServerTrackerCallBack {
private volatile boolean dataSourceDependency = true;
ServerTrackerCallBackImpl(ActiveMQServer server, BundleContext context, Dictionary<String, Object> properties) {
super(server, context, properties);
}
@Override @Override
public void setDataSourceDependency(boolean dataSourceDependency) { public void setDataSourceDependency(boolean dataSourceDependency) {
this.dataSourceDependency = dataSourceDependency; this.dataSourceDependency = dataSourceDependency;
} }
@Override
public void start() throws Exception {
if (!dataSourceDependency) {
super.start();
}
}
} }
} }

View File

@ -43,12 +43,12 @@ public class ProtocolTracker implements ServiceTrackerCustomizer<ProtocolManager
private String name; private String name;
private BundleContext context; private BundleContext context;
private Map<String, Boolean> protocols; private Map<String, Boolean> protocols;
private ProtocolTrackerCallBack callback; private ServerTrackerCallBack callback;
public ProtocolTracker(String name, public ProtocolTracker(String name,
BundleContext context, BundleContext context,
String[] requiredProtocols, String[] requiredProtocols,
ProtocolTrackerCallBack callback) { ServerTrackerCallBack callback) {
this.name = name; this.name = name;
this.context = context; this.context = context;
this.callback = callback; this.callback = callback;

View File

@ -1,28 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.osgi;
import org.apache.activemq.artemis.api.core.Interceptor;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
public interface ProtocolTrackerCallBack extends ActiveMQComponent {
void addFactory(ProtocolManagerFactory<Interceptor> pmf);
void removeFactory(ProtocolManagerFactory<Interceptor> pmf);
}

View File

@ -16,7 +16,16 @@
*/ */
package org.apache.activemq.artemis.osgi; package org.apache.activemq.artemis.osgi;
public interface ServerTrackerCallBack extends ProtocolTrackerCallBack { import org.apache.activemq.artemis.api.core.Interceptor;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
public interface ServerTrackerCallBack extends ActiveMQComponent {
void addFactory(ProtocolManagerFactory<Interceptor> pmf);
void removeFactory(ProtocolManagerFactory<Interceptor> pmf);
void setDataSourceDependency(boolean dataSourceDependency); void setDataSourceDependency(boolean dataSourceDependency);
} }

View File

@ -34,7 +34,7 @@ public class ProtocolTrackerTest {
IMocksControl c = EasyMock.createControl(); IMocksControl c = EasyMock.createControl();
BundleContext context = c.createMock(BundleContext.class); BundleContext context = c.createMock(BundleContext.class);
String[] requiredProtocols = {"a", "b"}; String[] requiredProtocols = {"a", "b"};
ProtocolTrackerCallBack callback = c.createMock(ProtocolTrackerCallBack.class); ServerTrackerCallBack callback = c.createMock(ServerTrackerCallBack.class);
RefFact protA = new RefFact(c, context, new String[]{"a"}); RefFact protA = new RefFact(c, context, new String[]{"a"});
RefFact protB = new RefFact(c, context, new String[]{"b"}); RefFact protB = new RefFact(c, context, new String[]{"b"});