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:15 UTC
[17/24] git commit: [KARAF-2833] Make system/core independent of
blueprint
[KARAF-2833] Make system/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/42b676bb
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/42b676bb
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/42b676bb
Branch: refs/heads/master
Commit: 42b676bb5408810a571276166bebee8c0e02f1c6
Parents: 8e129bf
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Sat Mar 22 11:58:34 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Mon Mar 24 17:30:13 2014 +0100
----------------------------------------------------------------------
.../standard/src/main/feature/feature.xml | 1 -
system/core/pom.xml | 4 +
.../karaf/system/internal/osgi/Activator.java | 83 ++++++++++++++++++++
.../OSGI-INF/blueprint/system-core.xml | 42 ----------
4 files changed, 87 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/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 6a71520..2b0f6c4 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -180,7 +180,6 @@
</feature>
<feature name="system" description="Provide System support" version="${project.version}">
- <feature version="${project.version}">aries-blueprint</feature>
<bundle start-level="30" start="true">mvn:org.apache.karaf.system/org.apache.karaf.system.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.system/org.apache.karaf.system.command/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/system/core/pom.xml
----------------------------------------------------------------------
diff --git a/system/core/pom.xml b/system/core/pom.xml
index cfe46bf..f5a9507 100644
--- a/system/core/pom.xml
+++ b/system/core/pom.xml
@@ -85,9 +85,13 @@
</Export-Package>
<Private-Package>
org.apache.karaf.system.internal,
+ org.apache.karaf.system.internal.osgi,
org.apache.karaf.system.management.internal,
org.apache.felix.utils.properties
</Private-Package>
+ <Bundle-Activator>
+ org.apache.karaf.system.internal.osgi.Activator
+ </Bundle-Activator>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/42b676bb/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java b/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java
new file mode 100644
index 0000000..b734253
--- /dev/null
+++ b/system/core/src/main/java/org/apache/karaf/system/internal/osgi/Activator.java
@@ -0,0 +1,83 @@
+/*
+ * 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.system.internal.osgi;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.NotCompliantMBeanException;
+
+import org.apache.karaf.system.SystemService;
+import org.apache.karaf.system.internal.SystemServiceImpl;
+import org.apache.karaf.system.management.internal.SystemMBeanImpl;
+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);
+
+ private ServiceRegistration<SystemService> serviceRegistration;
+ private ServiceRegistration mbeanRegistration;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ SystemServiceImpl systemService = new SystemServiceImpl();
+ systemService.setBundleContext(context);
+ serviceRegistration = context.registerService(SystemService.class, systemService, null);
+ try {
+ SystemMBeanImpl mbean = new SystemMBeanImpl();
+ mbean.setBundleContext(context);
+ mbean.setSystemService(systemService);
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put("jmx.objectname", "org.apache.karaf:type=system,name=" + System.getProperty("karaf.name"));
+ mbeanRegistration = context.registerService(
+ getInterfaceNames(mbean),
+ mbean,
+ props
+ );
+ } catch (NotCompliantMBeanException e) {
+ LOGGER.warn("Error creating System mbean", e);
+ }
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ mbeanRegistration.unregister();
+ serviceRegistration.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/42b676bb/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
----------------------------------------------------------------------
diff --git a/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml b/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
deleted file mode 100644
index f96a08f..0000000
--- a/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
+++ /dev/null
@@ -1,42 +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:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
-
- <ext:property-placeholder />
-
- <bean id="systemService" class="org.apache.karaf.system.internal.SystemServiceImpl">
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="systemService" interface="org.apache.karaf.system.SystemService"/>
-
- <bean id="systemMBean" class="org.apache.karaf.system.management.internal.SystemMBeanImpl">
- <property name="systemService" ref="systemService" />
- <property name="bundleContext" ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="systemMBean" auto-export="interfaces">
- <service-properties>
- <entry key="jmx.objectname" value="org.apache.karaf:type=system,name=${karaf.name}"/>
- </service-properties>
- </service>
-
-</blueprint>
\ No newline at end of file