Return-Path: X-Original-To: apmail-karaf-commits-archive@minotaur.apache.org Delivered-To: apmail-karaf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DA9FA115D9 for ; Mon, 24 Mar 2014 16:34:09 +0000 (UTC) Received: (qmail 85882 invoked by uid 500); 24 Mar 2014 16:32:49 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 85461 invoked by uid 500); 24 Mar 2014 16:32:34 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 84719 invoked by uid 99); 24 Mar 2014 16:32:01 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Mar 2014 16:32:01 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BEAC88B51BC; Mon, 24 Mar 2014 16:31:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gnodet@apache.org To: commits@karaf.apache.org Date: Mon, 24 Mar 2014 16:32:11 -0000 Message-Id: <661f39ecb94643268dc7f781546ed2ee@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Sun Mar 23 14:44:53 2014 +0100 Committer: Guillaume Nodet 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 @@ - aries-blueprint mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.core/${project.version} mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.command/${project.version} 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 @@ + org.apache.karaf + org.apache.karaf.util + provided + + + org.apache.karaf.features org.apache.karaf.features.core @@ -87,8 +93,13 @@ * - org.apache.karaf.diagnostic.core.internal + org.apache.karaf.diagnostic.core.internal, + org.apache.karaf.diagnostic.core.internal.osgi, + org.apache.karaf.util.tracker + + org.apache.karaf.diagnostic.core.internal.osgi.Activator + 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 providers; + private final List providers = new CopyOnWriteArrayList(); /** * 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 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> registrations; + private ServiceRegistration featuresProviderRegistration; + private ServiceRegistration mbeanRegistration; + private SingleServiceTracker featuresServiceTracker; + private ServiceTracker providersTracker; + + @Override + public void start(final BundleContext context) throws Exception { + registrations = new ArrayList>(); + 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(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( + context, DumpProvider.class, new ServiceTrackerCustomizer() { + @Override + public DumpProvider addingService(ServiceReference reference) { + DumpProvider service = context.getService(reference); + diagnostic.registerProvider(service); + return service; + } + @Override + public void modifiedService(ServiceReference reference, DumpProvider service) { + } + @Override + public void removedService(ServiceReference reference, DumpProvider service) { + diagnostic.unregisterProvider(service); + context.ungetService(reference); + } + }); + providersTracker.open(); + + Hashtable props = new Hashtable(); + 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 reg : registrations) { + reg.unregister(); + } + } + + private String[] getInterfaceNames(Object object) { + List names = new ArrayList(); + 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 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -