You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/03/24 17:32:11 UTC
[13/24] git commit: [KARAF-2833] Make diagnostic/core independent of
blueprint
[KARAF-2833] Make diagnostic/core independent of blueprint
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/2a1815d3
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/2a1815d3
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/2a1815d3
Branch: refs/heads/master
Commit: 2a1815d333c168014a32135fa0e35f7dec5d7200
Parents: a1e5d4f
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sun Mar 23 14:44:53 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
diagnostic/core/pom.xml | 13 +-
.../core/internal/DiagnosticDumpMBeanImpl.java | 15 +--
.../core/internal/LogDumpProvider.java | 4 +-
.../core/internal/osgi/Activator.java | 131 +++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 70 ----------
6 files changed, 152 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 8df6409..9064d05 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -135,7 +135,6 @@
</feature>
<feature name="diagnostic" description="Provide Diagnostic support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/pom.xml
----------------------------------------------------------------------
diff --git a/diagnostic/core/pom.xml b/diagnostic/core/pom.xml
index aa3054b..9a0ea67 100644
--- a/diagnostic/core/pom.xml
+++ b/diagnostic/core/pom.xml
@@ -51,6 +51,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.core</artifactId>
</dependency>
@@ -87,8 +93,13 @@
*
</Import-Package>
<Private-Package>
- org.apache.karaf.diagnostic.core.internal
+ org.apache.karaf.diagnostic.core.internal,
+ org.apache.karaf.diagnostic.core.internal.osgi,
+ org.apache.karaf.util.tracker
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.diagnostic.core.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
index 5637e79..22e09c9 100644
--- a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
+++ b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/DiagnosticDumpMBeanImpl.java
@@ -15,6 +15,7 @@ package org.apache.karaf.diagnostic.core.internal;
import java.io.File;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import javax.management.MBeanException;
import javax.management.NotCompliantMBeanException;
@@ -34,7 +35,7 @@ public class DiagnosticDumpMBeanImpl extends StandardMBean implements Diagnostic
/**
* Dump providers.
*/
- private List<DumpProvider> providers;
+ private final List<DumpProvider> providers = new CopyOnWriteArrayList<DumpProvider>();
/**
* Creates new diagnostic mbean.
@@ -78,13 +79,11 @@ public class DiagnosticDumpMBeanImpl extends StandardMBean implements Diagnostic
}
}
- /**
- * Sets dump providers.
- *
- * @param providers Dump providers.
- */
- public void setProviders(List<DumpProvider> providers) {
- this.providers = providers;
+ public void registerProvider(DumpProvider provider) {
+ providers.add(provider);
}
+ public void unregisterProvider(DumpProvider provider) {
+ providers.add(provider);
+ }
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
index 3d280f5..64b45f1 100644
--- a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
+++ b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/LogDumpProvider.java
@@ -36,9 +36,9 @@ import org.osgi.service.cm.ConfigurationAdmin;
*/
public class LogDumpProvider implements DumpProvider {
- private BundleContext bundleContext;
+ private final BundleContext bundleContext;
- public void setBundleContext(BundleContext bundleContext) {
+ public LogDumpProvider(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java
new file mode 100644
index 0000000..7a01daf
--- /dev/null
+++ b/diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/internal/osgi/Activator.java
@@ -0,0 +1,131 @@
+/*
+ * 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.karaf.diagnostic.core.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.karaf.diagnostic.core.DumpProvider;
+import org.apache.karaf.diagnostic.core.internal.BundleDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.DiagnosticDumpMBeanImpl;
+import org.apache.karaf.diagnostic.core.internal.EnvironmentDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.FeaturesDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.HeapDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.LogDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.MemoryDumpProvider;
+import org.apache.karaf.diagnostic.core.internal.ThreadDumpProvider;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class Activator implements BundleActivator {
+
+ private List<ServiceRegistration<DumpProvider>> registrations;
+ private ServiceRegistration<DumpProvider> featuresProviderRegistration;
+ private ServiceRegistration mbeanRegistration;
+ private SingleServiceTracker<FeaturesService> featuresServiceTracker;
+ private ServiceTracker<DumpProvider, DumpProvider> providersTracker;
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ registrations = new ArrayList<ServiceRegistration<DumpProvider>>();
+ registrations.add(context.registerService(DumpProvider.class, new BundleDumpProvider(context), null));
+ registrations.add(context.registerService(DumpProvider.class, new EnvironmentDumpProvider(context), null));
+ registrations.add(context.registerService(DumpProvider.class, new HeapDumpProvider(), null));
+ registrations.add(context.registerService(DumpProvider.class, new LogDumpProvider(context), null));
+ registrations.add(context.registerService(DumpProvider.class, new MemoryDumpProvider(), null));
+ registrations.add(context.registerService(DumpProvider.class, new ThreadDumpProvider(), null));
+
+ featuresServiceTracker = new SingleServiceTracker<FeaturesService>(context, FeaturesService.class, new SingleServiceTracker.SingleServiceListener() {
+ @Override
+ public void serviceFound() {
+ featuresProviderRegistration =
+ context.registerService(
+ DumpProvider.class,
+ new FeaturesDumpProvider(featuresServiceTracker.getService()),
+ null);
+ }
+ @Override
+ public void serviceLost() {
+ }
+ @Override
+ public void serviceReplaced() {
+ featuresProviderRegistration.unregister();
+ }
+ });
+
+ final DiagnosticDumpMBeanImpl diagnostic = new DiagnosticDumpMBeanImpl();
+ providersTracker = new ServiceTracker<DumpProvider, DumpProvider>(
+ context, DumpProvider.class, new ServiceTrackerCustomizer<DumpProvider, DumpProvider>() {
+ @Override
+ public DumpProvider addingService(ServiceReference<DumpProvider> reference) {
+ DumpProvider service = context.getService(reference);
+ diagnostic.registerProvider(service);
+ return service;
+ }
+ @Override
+ public void modifiedService(ServiceReference<DumpProvider> reference, DumpProvider service) {
+ }
+ @Override
+ public void removedService(ServiceReference<DumpProvider> reference, DumpProvider service) {
+ diagnostic.unregisterProvider(service);
+ context.ungetService(reference);
+ }
+ });
+ providersTracker.open();
+
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=diagnostic,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(diagnostic),
+ diagnostic,
+ props
+ );
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ featuresServiceTracker.close();
+ providersTracker.close();
+ for (ServiceRegistration<DumpProvider> reg : registrations) {
+ reg.unregister();
+ }
+ }
+
+ private String[] getInterfaceNames(Object object) {
+ List<String> names = new ArrayList<String>();
+ for (Class cl = object.getClass(); cl != Object.class; cl = cl.getSuperclass()) {
+ addSuperInterfaces(names, cl);
+ }
+ return names.toArray(new String[names.size()]);
+ }
+
+ private void addSuperInterfaces(List<String> names, Class clazz) {
+ for (Class cl : clazz.getInterfaces()) {
+ names.add(cl.getName());
+ addSuperInterfaces(names, cl);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1815d3/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
deleted file mode 100644
index 46a3cf4..0000000
--- a/diagnostic/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder />
-
- <bean id="features" class="org.apache.karaf.diagnostic.core.internal.FeaturesDumpProvider">
- <argument>
- <reference interface="org.apache.karaf.features.FeaturesService"
- availability="optional" />
- </argument>
- </bean>
- <service ref="features" auto-export="interfaces" />
-
- <bean id="logs" class="org.apache.karaf.diagnostic.core.internal.LogDumpProvider">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
- <service ref="logs" auto-export="interfaces" />
-
- <bean id="bundles" class="org.apache.karaf.diagnostic.core.internal.BundleDumpProvider">
- <argument ref="blueprintBundleContext" />
- </bean>
- <service ref="bundles" auto-export="interfaces" />
-
- <bean id="threads" class="org.apache.karaf.diagnostic.core.internal.ThreadDumpProvider" />
- <service ref="threads" auto-export="interfaces" />
-
- <bean id="memory" class="org.apache.karaf.diagnostic.core.internal.MemoryDumpProvider" />
- <service ref="memory" auto-export="interfaces" />
-
- <bean id="heap" class="org.apache.karaf.diagnostic.core.internal.HeapDumpProvider" />
- <service ref="heap" auto-export="interfaces" />
-
- <reference-list id="providers" availability="optional"
- interface="org.apache.karaf.diagnostic.core.DumpProvider" />
-
- <bean id="diagnosticDumpMBean" class="org.apache.karaf.diagnostic.core.internal.DiagnosticDumpMBeanImpl">
- <property name="providers" ref="providers" />
- </bean>
-
- <service ref="diagnosticDumpMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=diagnostic,name=${karaf.name}"/>
- </service-properties>
- </service>
-
- <bean id="environment" class="org.apache.karaf.diagnostic.core.internal.EnvironmentDumpProvider" >
- <argument ref="blueprintBundleContext" />
- </bean>
- <service ref="environment" auto-export="interfaces" />
-</blueprint>