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/25 12:54:33 UTC
[2/4] git commit: [KARAF-2833] Make wrapper/core independent of
blueprint
[KARAF-2833] Make wrapper/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/adea26ef
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/adea26ef
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/adea26ef
Branch: refs/heads/master
Commit: adea26ef783fe75349d3b8df429c31b330b742d6
Parents: d48f0fe
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Mar 25 11:31:43 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Mar 25 11:31:43 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
wrapper/core/pom.xml | 4 +
.../karaf/wrapper/internal/osgi/Activator.java | 82 ++++++++++++++++++++
.../OSGI-INF/blueprint/wrapper-core.xml | 39 ----------
4 files changed, 86 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/adea26ef/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 e5af831..932fa72 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -97,7 +97,6 @@
<!-- NB: this file is not the one really used. This file is used by the karaf-maven-plugin to define the start-level of bundles in the generated feature.xml -->
<feature name="wrapper" description="Provide OS integration" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30">mvn:org.apache.karaf.wrapper/org.apache.karaf.wrapper.core/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.wrapper/org.apache.karaf.wrapper.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/adea26ef/wrapper/core/pom.xml
----------------------------------------------------------------------
diff --git a/wrapper/core/pom.xml b/wrapper/core/pom.xml
index 961525c..7da4e0d 100644
--- a/wrapper/core/pom.xml
+++ b/wrapper/core/pom.xml
@@ -104,6 +104,7 @@
</Export-Package>
<Private-Package>
org.apache.karaf.wrapper.internal,
+ org.apache.karaf.wrapper.internal.osgi,
org.apache.karaf.wrapper.management.internal,
org.tanukisoftware.wrapper*,
org.apache.karaf.main*
@@ -114,6 +115,9 @@
!org.apache.karaf.info,
*
</Import-Package>
+ <Bundle-Activator>
+ org.apache.karaf.wrapper.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/adea26ef/wrapper/core/src/main/java/org/apache/karaf/wrapper/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/wrapper/core/src/main/java/org/apache/karaf/wrapper/internal/osgi/Activator.java b/wrapper/core/src/main/java/org/apache/karaf/wrapper/internal/osgi/Activator.java
new file mode 100644
index 0000000..8832533
--- /dev/null
+++ b/wrapper/core/src/main/java/org/apache/karaf/wrapper/internal/osgi/Activator.java
@@ -0,0 +1,82 @@
+/*
+ * 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.wrapper.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.wrapper.WrapperService;
+import org.apache.karaf.wrapper.internal.WrapperServiceImpl;
+import org.apache.karaf.wrapper.management.internal.WrapperMBeanImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+
+ ServiceRegistration<WrapperService> serviceRegistration;
+ ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ WrapperService wrapperService = new WrapperServiceImpl();
+ serviceRegistration = context.registerService(WrapperService.class, wrapperService, null);
+
+ try {
+ WrapperMBeanImpl wrapperMBean = new WrapperMBeanImpl();
+ wrapperMBean.setWrapperService(wrapperService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=wrapper,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(wrapperMBean),
+ wrapperMBean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating Wrapper mbean", e);
+ }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ serviceRegistration.unregister();
+ mbeanRegistration.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/adea26ef/wrapper/core/src/main/resources/OSGI-INF/blueprint/wrapper-core.xml
----------------------------------------------------------------------
diff --git a/wrapper/core/src/main/resources/OSGI-INF/blueprint/wrapper-core.xml b/wrapper/core/src/main/resources/OSGI-INF/blueprint/wrapper-core.xml
deleted file mode 100644
index 058b381..0000000
--- a/wrapper/core/src/main/resources/OSGI-INF/blueprint/wrapper-core.xml
+++ /dev/null
@@ -1,39 +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="wrapperService" class="org.apache.karaf.wrapper.internal.WrapperServiceImpl"/>
-
- <service ref="wrapperService" interface="org.apache.karaf.wrapper.WrapperService"/>
-
- <bean id="wrapperMBean" class="org.apache.karaf.wrapper.management.internal.WrapperMBeanImpl">
- <property name="wrapperService" ref="wrapperService" />
- </bean>
-
- <service ref="wrapperMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=wrapper,name=${karaf.name}"/>
- </service-properties>
- </service>
-</blueprint>
\ No newline at end of file