You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2013/10/24 16:05:44 UTC
svn commit: r1535386 - in /karaf/trunk/bundle/springstate: ./
src/main/java/org/apache/karaf/bundle/springstate/
src/main/java/org/apache/karaf/bundle/state/
src/main/java/org/apache/karaf/bundle/state/spring/
src/main/java/org/apache/karaf/bundle/stat...
Author: cschneider
Date: Thu Oct 24 14:05:44 2013
New Revision: 1535386
URL: http://svn.apache.org/r1535386
Log:
KARAF-2526 Adding diagnostics for spring dm and made the bundle independent of blueprint
Added:
karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/
karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/
karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/
karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java (with props)
karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java
- copied, changed from r1534943, karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/springstate/SpringApplicationListener.java
Removed:
karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/springstate/
karaf/trunk/bundle/springstate/src/main/resources/
Modified:
karaf/trunk/bundle/springstate/pom.xml
Modified: karaf/trunk/bundle/springstate/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/bundle/springstate/pom.xml?rev=1535386&r1=1535385&r2=1535386&view=diff
==============================================================================
--- karaf/trunk/bundle/springstate/pom.xml (original)
+++ karaf/trunk/bundle/springstate/pom.xml Thu Oct 24 14:05:44 2013
@@ -42,7 +42,6 @@
<dependency>
<groupId>org.apache.karaf.bundle</groupId>
<artifactId>org.apache.karaf.bundle.core</artifactId>
- <version>${project.version}</version>
<scope>provided</scope>
</dependency>
@@ -97,17 +96,10 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
<configuration>
- <instructions>
- <Export-Package>
- </Export-Package>
- <Import-Package>
- org.apache.felix.service.command;status=provisional,
- *
- </Import-Package>
- <Private-Package>
- org.apache.karaf.bundle.springstate
- </Private-Package>
+ <instructions>
+ <Bundle-Activator>org.apache.karaf.bundle.state.spring.internal.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
Added: karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java
URL: http://svn.apache.org/viewvc/karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java?rev=1535386&view=auto
==============================================================================
--- karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java (added)
+++ karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java Thu Oct 24 14:05:44 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.bundle.state.spring.internal;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.karaf.bundle.core.BundleStateService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.context.event.OsgiBundleApplicationContextListener;
+
+public class Activator implements BundleActivator {
+
+ public void start(BundleContext bundleContext) {
+ registerSpringBundleStateService(bundleContext);
+ }
+
+ private void registerSpringBundleStateService(BundleContext bundleContext) {
+ SpringStateService springStateService = new SpringStateService(bundleContext);
+ Dictionary<String, ?> properties = new Hashtable<String, String>();
+ String[] classes2 = new String[] {
+ OsgiBundleApplicationContextListener.class.getName(),
+ BundleStateService.class.getName()
+ };
+ bundleContext.registerService(classes2, springStateService, properties);
+ }
+
+ public void stop(BundleContext context) {
+ }
+
+}
\ No newline at end of file
Propchange: karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/Activator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java (from r1534943, karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/springstate/SpringApplicationListener.java)
URL: http://svn.apache.org/viewvc/karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java?p2=karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java&p1=karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/springstate/SpringApplicationListener.java&r1=1534943&r2=1535386&rev=1535386&view=diff
==============================================================================
--- karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/springstate/SpringApplicationListener.java (original)
+++ karaf/trunk/bundle/springstate/src/main/java/org/apache/karaf/bundle/state/spring/internal/SpringStateService.java Thu Oct 24 14:05:44 2013
@@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.karaf.bundle.springstate;
+package org.apache.karaf.bundle.state.spring.internal;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -33,14 +37,14 @@ import org.springframework.osgi.context.
import org.springframework.osgi.context.event.OsgiBundleContextRefreshedEvent;
import org.springframework.osgi.extender.event.BootstrappingDependencyEvent;
-public class SpringApplicationListener implements OsgiBundleApplicationContextListener,
+public class SpringStateService implements OsgiBundleApplicationContextListener,
BundleListener, BundleStateService {
- private static final Logger LOG = LoggerFactory.getLogger(SpringApplicationListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SpringStateService.class);
private final Map<Long, OsgiBundleApplicationContextEvent> states;
- public SpringApplicationListener(BundleContext bundleContext) {
+ public SpringStateService(BundleContext bundleContext) {
this.states = new ConcurrentHashMap<Long, OsgiBundleApplicationContextEvent>();
}
@@ -55,7 +59,40 @@ public class SpringApplicationListener i
}
public String getDiag(Bundle bundle) {
- return null;
+ OsgiBundleApplicationContextEvent event = states.get(bundle.getBundleId());
+ if (event == null) {
+ return null;
+ }
+
+ StringBuilder message = new StringBuilder();
+ Date date = new Date(event.getTimestamp());
+ SimpleDateFormat df = new SimpleDateFormat();
+ message.append(df.format(date) + "\n");
+ Throwable ex = getException(event);
+ if (ex != null) {
+ message.append("Exception: \n");
+ addMessages(message, ex);
+ }
+ return message.toString();
+ }
+
+ private void addMessages(StringBuilder message, Throwable ex) {
+ if (ex != null) {
+ message.append(ex.getMessage());
+ message.append("\n");
+ StringWriter errorWriter = new StringWriter();
+ ex.printStackTrace(new PrintWriter(errorWriter));
+ message.append(errorWriter.toString());
+ message.append("\n");
+ }
+ }
+
+ private Throwable getException(OsgiBundleApplicationContextEvent event) {
+ if (!(event instanceof OsgiBundleContextFailedEvent)) {
+ return null;
+ }
+ OsgiBundleContextFailedEvent failureEvent = (OsgiBundleContextFailedEvent) event;
+ return failureEvent.getFailureCause();
}
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {