- Fixed findbugs errors. Cleaned imports.
- Use a temporal service dependency over the LogService in order to ignore temporary log service
outage.
- Use BundleDependency instead of SynchronousBundleListener, when tracking annotated bundles.
- Improved logging.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1064329 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/runtime/findbugs.xml b/dependencymanager/runtime/findbugs.xml
new file mode 100644
index 0000000..10368c3
--- /dev/null
+++ b/dependencymanager/runtime/findbugs.xml
@@ -0,0 +1,13 @@
+<FindBugsFilter>
+ <!--
+ The m_logService field of the Log" class is injected by the Activator.
+ -->
+ <Match>
+ <Class name="org.apache.felix.dm.runtime.Log" />
+ <Bug pattern="UWF_UNWRITTEN_FIELD" />
+ </Match>
+ <Match>
+ <Class name="org.apache.felix.dm.runtime.Log" />
+ <Bug pattern="NP_UNWRITTEN_FIELD" />
+ </Match>
+</FindBugsFilter>
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AbstractBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AbstractBuilder.java
index cc70226..44cad26 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AbstractBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AbstractBuilder.java
@@ -24,10 +24,9 @@
import org.apache.felix.dm.Dependency;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
/**
- * base class for all kind of DM component builders (for Component, Aspect, Adapters ...).
+ * Base class for all kind of DM component builders (for Component, Aspect, Adapters ...).
*/
public abstract class AbstractBuilder
{
@@ -46,7 +45,7 @@
throws Exception;
/**
- * Set common Service parameters, if provided from our Component descriptor
+ * Sets common Service parameters, if provided from our Component descriptor
*/
protected void setCommonServiceParams(Component service, MetaData serviceMetaData)
throws Exception
@@ -77,8 +76,7 @@
String name = dependency.getString(Params.name, null);
if (name == null) {
DependencyBuilder depBuilder = new DependencyBuilder(dependency);
- Log.instance().log(LogService.LOG_INFO,
- "ServiceLifecycleHandler.init: adding dependency %s into service %s",
+ Log.instance().info("ServiceLifecycleHandler.init: adding dependency %s into service %s",
dependency, srvMeta);
Dependency d = depBuilder.build(b, dm, false);
s.add(d);
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
index d973497..826516d 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
@@ -20,6 +20,8 @@
import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.ServiceDependency;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogService;
@@ -31,24 +33,39 @@
*/
public class Activator extends DependencyActivatorBase
{
+ private final static String CONF_LOG = "dm.runtime.log";
+
/**
- * Our bundle is starting: initialize our DependencyManager Runtime service.
+ * Initialize our DependencyManager Runtime service.
+ *
+ * We depend on the OSGi LogService, and we track all started bundles which do have a
+ * "DependencyManager-Component" Manifest header.
+ * If the "dm.runtime.log=true" parameter is configured in the Felix config.properties
+ * then we'll use a required/temporal service dependency over the log service.
+ * This temporal dependency avoids us to be restarted if the log service is temporarily
+ * unavailable (that is: when the log service is updating).
+ * if the "dm.runtime.log" is not configured of it it is set to false, then we'll use
+ * an optional dependency over the log service, in order to use a NullObject in case
+ * the log service is not available.
*/
@Override
public void init(BundleContext context, DependencyManager dm) throws Exception
{
- // If the "dm.log=true" parameter is configured in the OSGi config.properties
- // then, we'll wait for the LogService, else we'll use an optional dependency over it,
- // and we'll eventually use a Null LogService Object.
-
- boolean logActive = "true".equals(context.getProperty("dm.runtime.log"));
+ boolean logActive = "true".equalsIgnoreCase(context.getProperty(CONF_LOG));
+ ServiceDependency logDep = logActive ?
+ createTemporalServiceDependency() : createServiceDependency().setRequired(false);
+ logDep.setService(LogService.class).setAutoConfig(true);
+
dm.add(createComponent()
.setImplementation(DependencyManagerRuntime.class)
- .add(createServiceDependency()
- .setService(LogService.class)
- .setRequired(logActive)
- .setAutoConfig("m_log")
- .setCallbacks("bind", null)));
+ .setComposition("getComposition")
+ .add(logDep)
+ .add(createBundleDependency()
+ .setRequired(false)
+ .setAutoConfig(false)
+ .setStateMask(Bundle.ACTIVE)
+ .setFilter("(DependencyManager-Component=*)")
+ .setCallbacks("bundleStarted", "bundleStopped")));
}
/**
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
index 7bf20e2..98bd244 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
@@ -21,8 +21,8 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
/**
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
index 89703dd..9c0c42a 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
@@ -21,10 +21,9 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
public class AspectServiceBuilder extends AbstractBuilder
{
@@ -37,37 +36,39 @@
}
@Override
- public void build(MetaData srvMeta, List<MetaData> depsMeta, Bundle b, DependencyManager dm)
+ public void build(MetaData srvMeta, List<MetaData> depsMeta, Bundle b, DependencyManager dm)
throws Exception
{
- Log.instance().log(LogService.LOG_INFO,
- "AspectServiceBuilder: building aspect service: %s with dependencies %s",
- srvMeta, depsMeta);
+ Log.instance().info("AspectServiceBuilder: building aspect service: %s with dependencies %s",
+ srvMeta,
+ depsMeta);
Class<?> serviceInterface = b.loadClass(srvMeta.getString(Params.service));
String serviceFilter = srvMeta.getString(Params.filter, null);
Dictionary<String, Object> aspectProperties = srvMeta.getDictionary(Params.properties, null);
int ranking = srvMeta.getInt(Params.ranking, 1);
String implClassName = srvMeta.getString(Params.impl);
- Object implClass = b.loadClass(implClassName);
- String field = srvMeta.getString(Params.field, null);
+ Object implClass = b.loadClass(implClassName);
+ String field = srvMeta.getString(Params.field, null);
String factoryMethod = srvMeta.getString(Params.factoryMethod, null);
- Component service = dm.createAspectService(serviceInterface, serviceFilter, ranking, field)
- .setServiceProperties(aspectProperties);
+ Component service =
+ dm.createAspectService(serviceInterface, serviceFilter, ranking, field)
+ .setServiceProperties(aspectProperties);
if (factoryMethod == null)
{
service.setImplementation(implClass);
- }
+ }
else
{
service.setFactory(implClass, factoryMethod);
}
-
+
service.setComposition(srvMeta.getString(Params.composition, null));
ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(service, b, dm, srvMeta, depsMeta);
// The dependencies will be plugged by our lifecycle handler.
service.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
- // Adds dependencies (except named dependencies, which are managed by the lifecycle handler).
+ // Adds dependencies (except named dependencies, which are managed by the lifecycle
+ // handler).
addUnamedDependencies(b, dm, service, srvMeta, depsMeta);
dm.add(service);
}
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
index b2938da..087b638 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
@@ -21,8 +21,8 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
public class BundleAdapterServiceBuilder extends AbstractBuilder
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ComponentBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ComponentBuilder.java
index de3cc65..734188f 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ComponentBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ComponentBuilder.java
@@ -23,10 +23,9 @@
import java.util.List;
import java.util.Set;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
/**
* Builds a DependencyManager Component.
@@ -52,9 +51,9 @@
// Check if we must provide a Set Factory.
if (factory == null)
{
- Log.instance().log(LogService.LOG_INFO,
- "ComponentBuilder: building service %s with dependencies %s",
- srvMeta, depsMeta);
+ Log.instance().info("ComponentBuilder: building service %s with dependencies %s",
+ srvMeta,
+ depsMeta);
String impl = srvMeta.getString(Params.impl);
String composition = srvMeta.getString(Params.composition, null);
@@ -62,18 +61,21 @@
if (factoryMethod == null)
{
service.setImplementation(b.loadClass(impl));
- } else
+ }
+ else
{
service.setFactory(b.loadClass(impl), factoryMethod);
}
service.setComposition(composition);
-
- // Adds dependencies (except named dependencies, which are managed by the lifecycle handler).
+
+ // Adds dependencies (except named dependencies, which are managed by the lifecycle
+ // handler).
addUnamedDependencies(b, dm, service, srvMeta, depsMeta);
// Creates a ServiceHandler, which will filter all service lifecycle callbacks.
- ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(service, b, dm, srvMeta, depsMeta);
+ ServiceLifecycleHandler lfcleHandler =
+ new ServiceLifecycleHandler(service, b, dm, srvMeta, depsMeta);
service.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
-
+
// Set the provided services
Dictionary<String, Object> properties = srvMeta.getDictionary(Params.properties, null);
String[] services = srvMeta.getStrings(Params.provides, null);
@@ -81,14 +83,15 @@
}
else
{
- Log.instance().log(LogService.LOG_INFO,
- "ComponentBuilder: providing factory set for service %s with dependencies %s",
- srvMeta, depsMeta);
+ Log.instance()
+ .info("ComponentBuilder: providing factory set for service %s with dependencies %s",
+ srvMeta,
+ depsMeta);
// We don't instantiate the service, but instead we provide a Set in the registry.
// This Set will act as a factory and another component may registers some
// service configurations into it in order to fire some service instantiations.
- FactorySet factorySet = new FactorySet(b, srvMeta, depsMeta);
+ FactorySet factorySet = new FactorySet(b, srvMeta, depsMeta);
service.setImplementation(factorySet);
service.setCallbacks(null, "start", "stop", null);
Hashtable<String, String> props = new Hashtable<String, String>();
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
index 5fc5410..482d2c3 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
@@ -26,36 +26,26 @@
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.SynchronousBundleListener;
-import org.osgi.service.log.LogService;
/**
* This class parses service descriptors generated by the annotation bnd processor.
* The descriptors are located under OSGI-INF/dependencymanager directory. Such files are actually
* referenced by a specific "DependendencyManager-Component" manifest header.
*/
-public class DependencyManagerRuntime implements SynchronousBundleListener
+public class DependencyManagerRuntime
{
- private ConcurrentHashMap<Bundle, DependencyManager> m_managers = new ConcurrentHashMap<Bundle, DependencyManager>();
- private static LogService m_log; // Injected
- private BundleContext m_bctx; // Injected
+ private ConcurrentHashMap<Bundle, DependencyManager> m_managers =
+ new ConcurrentHashMap<Bundle, DependencyManager>();
private DescriptorParser m_parser;
/**
- * Starts our Service (at this point, we have been injected with our bundle context, as well
- * as with our log service. We'll listen to bundle start/stop events (we implement the
- * SynchronousBundleListener interface).
+ * Our constructor. We'll initialize here our DM component builders.
*/
- protected void start()
+ public DependencyManagerRuntime()
{
- // Register our log service.
- Log.instance().setLogService(m_log);
-
// Instantiates our descriptor parser, and register our service builders into it.
m_parser = new DescriptorParser();
m_parser.addBuilder(new ComponentBuilder());
@@ -64,18 +54,24 @@
m_parser.addBuilder(new BundleAdapterServiceBuilder());
m_parser.addBuilder(new FactoryConfigurationAdapterServiceBuilder());
m_parser.addBuilder(new ResourceAdapterServiceBuilder());
+ }
+
+ /**
+ * Return our Object Composition (the Activator will inject dependencies into it)
+ */
+ protected Object[] getComposition()
+ {
+ return new Object[] { this, Log.instance() };
+ }
- // Load already started bundles
- for (Bundle b: m_bctx.getBundles())
- {
- if (b.getState() == Bundle.ACTIVE)
- {
- bundleChanged(new BundleEvent(Bundle.ACTIVE, b));
- }
- }
-
- // Track bundles
- m_bctx.addBundleListener(this);
+ /**
+ * Starts our Service (at this point, we have been injected with our bundle context, as well
+ * as with our log service. We'll listen to bundle start/stop events (we implement the
+ * SynchronousBundleListener interface).
+ */
+ protected void start()
+ {
+ Log.instance().info("Starting Dependency Manager annotation runtime");
}
/**
@@ -84,12 +80,11 @@
@SuppressWarnings("unchecked")
protected void stop()
{
- m_log.log(LogService.LOG_INFO, "Runtime: stopping services");
-
- for (DependencyManager dm: m_managers.values())
+ Log.instance().info("Runtime: stopping services");
+ for (DependencyManager dm : m_managers.values())
{
List<Component> services = new ArrayList<Component>(dm.getServices());
- for (Component service: services)
+ for (Component service : services)
{
dm.remove(service);
}
@@ -99,35 +94,11 @@
}
/**
- * Register a LogService, so other components may use it
- */
- protected void bind(LogService logService) {
- m_log = logService;
- Log.instance().setLogService(logService);
- }
-
- /**
- * Handle a bundle event, and eventually parse started bundles.
- */
- public void bundleChanged(BundleEvent event)
- {
- Bundle b = event.getBundle();
- if (b.getState() == Bundle.ACTIVE)
- {
- bundleStarted(b);
- }
- else if (b.getState() == Bundle.STOPPING)
- {
- bundleStopping(b);
- }
- }
-
- /**
* Checks if a started bundle have some DependencyManager descriptors
* referenced in the "DependencyManager-Component" OSGi header.
* @param b the started bundle.
*/
- void bundleStarted(Bundle b)
+ protected void bundleStarted(Bundle b)
{
String descriptorPaths = (String) b.getHeaders().get("DependencyManager-Component");
if (descriptorPaths == null)
@@ -135,13 +106,13 @@
return;
}
- for (String descriptorPath: descriptorPaths.split(","))
+ for (String descriptorPath : descriptorPaths.split(","))
{
URL descriptorURL = b.getEntry(descriptorPath);
if (descriptorURL == null)
{
- m_log.log(LogService.LOG_ERROR, "Runtime: " +
- "DependencyManager component descriptor not found: " + descriptorPath);
+ Log.instance().error("Runtime: " + "DependencyManager component descriptor not found: %s",
+ descriptorPath);
continue;
}
loadDescriptor(b, descriptorURL);
@@ -153,18 +124,18 @@
* @param b
*/
@SuppressWarnings("unchecked")
- private void bundleStopping(Bundle b)
+ protected void bundleStopped(Bundle b)
{
- m_log.log(LogService.LOG_INFO, "Runtime: Removing services from stopping bundle: " + b.getSymbolicName());
+ Log.instance().info("Runtime: Removing services from stopping bundle: %s", b.getSymbolicName());
DependencyManager dm = m_managers.remove(b);
if (dm != null)
{
List<Component> services = new ArrayList(dm.getServices());
for (Component service : services)
{
- m_log.log(LogService.LOG_INFO, "Runtime: Removing service: " + service);
+ Log.instance().info("Runtime: Removing service: %s", service);
dm.remove(service);
- }
+ }
}
}
@@ -175,8 +146,9 @@
*/
private void loadDescriptor(Bundle b, URL descriptorURL)
{
- m_log.log(LogService.LOG_DEBUG, "Runtime: ++++ Parsing descriptor " + descriptorURL
- + " from bundle " + b.getSymbolicName());
+ Log.instance().debug("Runtime: ++++ Parsing descriptor %s from bundle %s",
+ descriptorURL,
+ b.getSymbolicName());
BufferedReader in = null;
try
@@ -195,8 +167,10 @@
catch (Throwable t)
{
- m_log.log(LogService.LOG_ERROR, "Runtime: Error while parsing descriptor "
- + descriptorURL + " from bundle " + b.getSymbolicName(), t);
+ Log.instance().error("Runtime: Error while parsing descriptor %s from bundle %s",
+ t,
+ descriptorURL,
+ b.getSymbolicName());
}
finally
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DescriptorParser.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DescriptorParser.java
index 6e18458..4f15fb0 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DescriptorParser.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DescriptorParser.java
@@ -27,7 +27,6 @@
import org.apache.felix.dm.DependencyManager;
import org.json.JSONObject;
import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
/**
* This class parses files generated in OSGI-INF/*.dm by the DependencyManager bnd plugin.
@@ -49,7 +48,7 @@
// The first line is a Service Component (a Service, an Aspect Service, etc ...)
line = reader.readLine();
- Log.instance().log(LogService.LOG_DEBUG, "DescriptorParser: parsing service %s", line);
+ Log.instance().debug("DescriptorParser: parsing service %s", line);
JSONObject json = new JSONObject(line);
JSONMetaData serviceMetaData = new JSONMetaData(json);
@@ -58,14 +57,14 @@
if (builder == null)
{
throw new IllegalArgumentException("Invalid descriptor"
- + ": no \"type\" parameter found in first line");
+ + ": no \"type\" parameter found in first line");
}
// Parse the rest of the lines (dependencies)
List<MetaData> serviceDependencies = new ArrayList<MetaData>();
while ((line = reader.readLine()) != null)
{
- Log.instance().log(LogService.LOG_DEBUG, "Parsing dependency Ms", line);
+ Log.instance().debug("Parsing dependency Ms", line);
JSONObject dep = new JSONObject(line);
serviceDependencies.add(new JSONMetaData(dep));
}
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
index fcab7ef..b91241b 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
@@ -21,8 +21,8 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
public class FactoryConfigurationAdapterServiceBuilder extends AbstractBuilder
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactorySet.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactorySet.java
index bcf5b8b..f43e969 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactorySet.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactorySet.java
@@ -27,11 +27,10 @@
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.felix.dm.Component;
import org.apache.felix.dm.Dependency;
import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.Component;
import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
/**
* This class implements a <code>java.util.Set</code> which acts as a service factory.
@@ -189,6 +188,7 @@
* Create or Update a Service.
*/
@Override
+ @SuppressWarnings("synthetic-access")
public boolean add(final Dictionary configuration)
{
// Check parameter validity
@@ -230,6 +230,7 @@
* (This avoid potential dead locks, especially when Service callback methods are invoked).
*/
@Override
+ @SuppressWarnings("synthetic-access")
public boolean remove(final Object configuration)
{
// Check parameter validity.
@@ -268,6 +269,7 @@
* (This avoid potential dead locks, especially when Service callback methods are invoked).
*/
@Override
+ @SuppressWarnings("synthetic-access")
public void clear()
{
if (!m_active)
@@ -383,17 +385,15 @@
if (name == null)
{
DependencyBuilder depBuilder = new DependencyBuilder(dependency);
- Log.instance().log(
- LogService.LOG_INFO,
- "ServiceLifecycleHandler.init: adding dependency %s into service %s",
- dependency, m_srvMeta);
+ Log.instance().info("ServiceLifecycleHandler.init: adding dependency %s into service %s",
+ dependency, m_srvMeta);
Dependency d = depBuilder.build(m_bundle, m_dm, false);
s.add(d);
}
}
// Register the Service instance, and keep track of it.
- Log.instance().log(LogService.LOG_INFO, "ServiceFactory: created service %s", m_srvMeta);
+ Log.instance().info("ServiceFactory: created service %s", m_srvMeta);
m_dm.add(s);
m_services.put(serviceKey, s);
}
@@ -401,8 +401,8 @@
{
// Make sure the SERVICE_CREATING flag is also removed
m_services.remove(serviceKey);
- Log.instance().log(LogService.LOG_ERROR, "ServiceFactory: could not instantiate service %s",
- t, m_srvMeta);
+ Log.instance().error("ServiceFactory: could not instantiate service %s",
+ t, m_srvMeta);
}
}
else
@@ -410,7 +410,7 @@
// Reconfigure an already existing Service.
if (m_configure != null)
{
- Log.instance().log(LogService.LOG_INFO, "ServiceFactory: updating service %s", m_impl);
+ Log.instance().info("ServiceFactory: updating service %s", m_impl);
invokeConfigure(m_impl, m_configure, configuration);
}
@@ -425,7 +425,7 @@
private void doRemove(Dictionary configuraton)
{
- Log.instance().log(LogService.LOG_INFO, "ServiceFactory: removing service %s", m_srvMeta);
+ Log.instance().info("ServiceFactory: removing service %s", m_srvMeta);
ServiceKey serviceKey = new ServiceKey(configuraton);
Object service = m_services.remove(serviceKey);
if (service != null && service != SERVICE_CREATING)
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/InvocationUtil.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/InvocationUtil.java
index f8ecef8..3480be8 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/InvocationUtil.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/InvocationUtil.java
@@ -22,18 +22,22 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
- * Class copied from DM core (but, ultimately, the core should export this class so we could then
- * import/reuse it).
+ * Java reflexion utility methods.
*/
public class InvocationUtil
{
- public static Object invokeCallbackMethod(Object instance, String methodName, Class[][] signatures,
- Object[][] parameters)
- throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
+ public static Object invokeCallbackMethod(Object instance,
+ String methodName,
+ Class<?>[][] signatures,
+ Object[][] parameters)
+ throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException
{
- Class currentClazz = instance.getClass();
+ Class<?> currentClazz = instance.getClass();
while (currentClazz != null)
{
try
@@ -49,9 +53,14 @@
throw new NoSuchMethodException(methodName);
}
- public static Object invokeMethod(Object object, Class clazz, String name, Class[][] signatures,
- Object[][] parameters, boolean isSuper)
- throws NoSuchMethodException, InvocationTargetException, IllegalArgumentException, IllegalAccessException
+ public static Object invokeMethod(Object object,
+ Class<?> clazz,
+ String name,
+ Class<?>[][] signatures,
+ Object[][] parameters,
+ boolean isSuper)
+ throws NoSuchMethodException, InvocationTargetException, IllegalArgumentException,
+ IllegalAccessException
{
if (object == null)
{
@@ -64,23 +73,29 @@
// If we're talking to a proxy here, dig one level deeper to expose the
// underlying invocation handler ...
-
+
if (Proxy.isProxyClass(clazz))
{
object = Proxy.getInvocationHandler(object);
clazz = object.getClass();
}
- Method m = null;
for (int i = 0; i < signatures.length; i++)
{
- Class[] signature = signatures[i];
+ Class<?>[] signature = signatures[i];
try
{
- m = clazz.getDeclaredMethod(name, signature);
+ final Method m = clazz.getDeclaredMethod(name, signature);
if (!(isSuper && Modifier.isPrivate(m.getModifiers())))
{
- m.setAccessible(true);
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ m.setAccessible(true);
+ return null;
+ }
+ });
return m.invoke(object, parameters[i]);
}
}
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Log.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Log.java
index dcd8bea..4366689 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Log.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Log.java
@@ -25,7 +25,7 @@
*/
public class Log
{
- /** The log service */
+ /** The wrap log service which is actually used (Injected by Activator) */
private volatile LogService m_logService;
/** Our sole instance */
@@ -36,17 +36,43 @@
return m_instance;
}
- public void setLogService(LogService logService) {
- m_logService = logService;
- }
-
- public void log(int level, String format, Object ... args)
+ public void error(String format, Object ... args)
{
- m_logService.log(level, String.format(format, args));
+ m_logService.log(LogService.LOG_ERROR, String.format(format, args));
}
- public void log(int level, String format, Throwable t, Object ... args)
+ public void error(String format, Throwable t, Object ... args)
{
- m_logService.log(level, String.format(format, args), t);
+ m_logService.log(LogService.LOG_ERROR, String.format(format, args), t);
+ }
+
+ public void warn(String format, Object ... args)
+ {
+ m_logService.log(LogService.LOG_WARNING, String.format(format, args));
+ }
+
+ public void warn(String format, Throwable t, Object ... args)
+ {
+ m_logService.log(LogService.LOG_WARNING, String.format(format, args), t);
+ }
+
+ public void info(String format, Object ... args)
+ {
+ m_logService.log(LogService.LOG_INFO, String.format(format, args));
+ }
+
+ public void info(String format, Throwable t, Object ... args)
+ {
+ m_logService.log(LogService.LOG_INFO, String.format(format, args), t);
+ }
+
+ public void debug(String format, Object ... args)
+ {
+ m_logService.log(LogService.LOG_DEBUG, String.format(format, args));
+ }
+
+ public void debug(String format, Throwable t, Object ... args)
+ {
+ m_logService.log(LogService.LOG_DEBUG, String.format(format, args), t);
}
}
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
index 929dc73..b39eca4 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
@@ -21,8 +21,8 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.Bundle;
public class ResourceAdapterServiceBuilder extends AbstractBuilder
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/SerialExecutor.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/SerialExecutor.java
index f985da4..b2bac54 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/SerialExecutor.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/SerialExecutor.java
@@ -31,7 +31,7 @@
*/
public final class SerialExecutor
{
- private final LinkedList m_workQueue = new LinkedList();
+ private final LinkedList<Runnable> m_workQueue = new LinkedList<Runnable>();
private Runnable m_active;
/**
@@ -44,6 +44,7 @@
{
m_workQueue.addLast(new Runnable()
{
+ @SuppressWarnings("synthetic-access")
public void run()
{
try
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java
index e177527..54df650 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java
@@ -31,18 +31,10 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.felix.dm.BundleDependency;
-import org.apache.felix.dm.ConfigurationDependency;
+import org.apache.felix.dm.Component;
import org.apache.felix.dm.Dependency;
import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.ResourceDependency;
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.ServiceDependency;
-import org.apache.felix.dm.TemporalServiceDependency;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.log.LogService;
/**
* Allow Services to configure dynamically their dependency filters from their init() method.
@@ -152,7 +144,7 @@
if (starter != null)
{
- Log.instance().log(LogService.LOG_DEBUG, "Setting up a lifecycle controller for service %s", serviceInstance);
+ Log.instance().debug("Setting up a lifecycle controller for service %s", serviceInstance);
String componentName = serviceInstance.getClass().getName();
m_toggle = new ToggleServiceDependency();
service.add(m_toggle);
@@ -178,9 +170,8 @@
}
}
- Log.instance().log(LogService.LOG_DEBUG,
- "ServiceLifecycleHandler.init: invoked init method from service %s " +
- ", returned map: %s", serviceInstance, customization);
+ Log.instance().debug("ServiceLifecycleHandler.init: invoked init method from service %s " +
+ ", returned map: %s", serviceInstance, customization);
for (MetaData dependency: m_depsMeta)
{
@@ -207,8 +198,7 @@
}
DependencyBuilder depBuilder = new DependencyBuilder(dependency);
- Log.instance().log(LogService.LOG_INFO,
- "ServiceLifecycleHandler.init: adding dependency %s into service %s",
+ Log.instance().info("ServiceLifecycleHandler.init: adding dependency %s into service %s",
dependency, m_srvMeta);
Dependency d = depBuilder.build(m_bundle, dm, true);
m_namedDeps.add(d);
@@ -281,7 +271,7 @@
}
catch (NoSuchMethodException e)
{
- Log.instance().log(LogService.LOG_ERROR, "Lifecycle handler could not reset instanceBound of dependency: %s", e, d);
+ Log.instance().error("Lifecycle handler could not reset instanceBound of dependency: %s", e, d);
}
}
}
@@ -351,10 +341,10 @@
/**
* Sets a field of an object by reflexion.
*/
- private void setField(Object instance, String fieldName, Class fieldClass, Object fieldValue)
+ private void setField(Object instance, String fieldName, Class<?> fieldClass, Object fieldValue)
{
Object serviceInstance = instance;
- Class serviceClazz = serviceInstance.getClass();
+ Class<?> serviceClazz = serviceInstance.getClass();
if (Proxy.isProxyClass(serviceClazz))
{
serviceInstance = Proxy.getInvocationHandler(serviceInstance);
@@ -366,7 +356,7 @@
for (int j = 0; j < fields.length; j++)
{
Field field = fields[j];
- Class type = field.getType();
+ Class<?> type = field.getType();
if (field.getName().equals(fieldName) && type.isAssignableFrom(fieldClass))
{
try
@@ -378,7 +368,7 @@
field.set(serviceInstance, fieldValue);
}
}
- catch (Exception e)
+ catch (Throwable e)
{
throw new RuntimeException("Could not set field " + field, e);
}
@@ -396,11 +386,12 @@
m_componentName = name;
}
+ @SuppressWarnings("synthetic-access")
public void run()
{
if (m_started.compareAndSet(false, true)) {
- Log.instance().log(LogService.LOG_DEBUG, "Lifecycle controller is activating the component %s",
- m_componentName);
+ Log.instance().debug("Lifecycle controller is activating the component %s",
+ m_componentName);
m_toggle.setAvailable(true);
}
}
@@ -414,11 +405,12 @@
m_componentName = componentName;
}
+ @SuppressWarnings("synthetic-access")
public void run()
{
if (m_started.compareAndSet(true, false)) {
- Log.instance().log(LogService.LOG_DEBUG, "Lifecycle controller is deactivating the component %s",
- m_componentName);
+ Log.instance().debug("Lifecycle controller is deactivating the component %s",
+ m_componentName);
m_toggle.setAvailable(false);
}
}
diff --git a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ToggleServiceDependency.java b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ToggleServiceDependency.java
index 2037f26..cfa0ad9 100644
--- a/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ToggleServiceDependency.java
+++ b/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ToggleServiceDependency.java
@@ -33,7 +33,7 @@
*/
public class ToggleServiceDependency implements Dependency, DependencyActivation
{
- private final List m_services = new ArrayList();
+ private final List<Object> m_services = new ArrayList<Object>();
private volatile boolean m_isAvailable;
private volatile boolean m_stopped;
@@ -106,11 +106,12 @@
return null;
}
- public Class getAutoConfigType()
+ public Class<?> getAutoConfigType()
{
return String.class;
}
+ @SuppressWarnings("unchecked")
public Dictionary getProperties()
{
return null;