From 91ec63b012729bdfa5fb3854bf9e9dd5f6d6ac91 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 26 Jul 2009 17:37:27 +0000 Subject: [PATCH] Improve logging and monitoring git-svn-id: https://svn.argeo.org/slc/trunk@2770 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../slc/lib/detached/DetachedLauncher.java | 22 ++++++++++- runtime/org.argeo.slc.support.equinox/pom.xml | 3 +- .../main/resources/META-INF/spring/osgi.xml | 5 +++ .../org/argeo/slc/osgi/BundlesManager.java | 39 +++++++++++++++++-- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java b/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java index d0ceb56b7..825a9717d 100644 --- a/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java +++ b/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java @@ -1,6 +1,7 @@ package org.argeo.slc.lib.detached; import java.io.File; +import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -10,6 +11,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.osgi.context.BundleContextAware; @@ -88,7 +90,7 @@ public class DetachedLauncher extends JvmProcess implements BundleContextAware, protected Resource findOsgiboot(Bundle bundle) { String location = bundle.getLocation(); if (location.startsWith("initial@reference:file:")) - location = System.getProperty("osgi.install.area") + "/../" + location = System.getProperty("osgi.install.area") + location.substring("initial@reference:file:".length()); if (location.charAt(location.length() - 1) == '/') location.substring(0, location.length() - 1); @@ -96,7 +98,23 @@ public class DetachedLauncher extends JvmProcess implements BundleContextAware, } protected Resource asResource(String location) { - Resource res = resourceLoader.getResource(location); + // Resource res = resourceLoader.getResource(location); + + final Resource res; + if (location.startsWith("file:")) { + File file = new File(location.substring("file:".length())); + if (!file.exists()) + throw new SlcException("File " + file + " does not exist"); + + try { + res = new FileSystemResource(file.getCanonicalFile()); + } catch (IOException e) { + throw new SlcException("Cannot create resource based on " + + file, e); + } + } else + res = resourceLoader.getResource(location); + if (log.isDebugEnabled()) log.debug("Converted " + location + " to " + res); return res; diff --git a/runtime/org.argeo.slc.support.equinox/pom.xml b/runtime/org.argeo.slc.support.equinox/pom.xml index 9fed73946..a4d112a03 100644 --- a/runtime/org.argeo.slc.support.equinox/pom.xml +++ b/runtime/org.argeo.slc.support.equinox/pom.xml @@ -41,7 +41,8 @@ org.argeo.slc.* *, - org.springframework.beans.factory.config + org.springframework.beans.factory.config, + org.springframework.osgi.context.event diff --git a/runtime/org.argeo.slc.support.equinox/src/main/resources/META-INF/spring/osgi.xml b/runtime/org.argeo.slc.support.equinox/src/main/resources/META-INF/spring/osgi.xml index 0a9883828..9dab0f29e 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/resources/META-INF/spring/osgi.xml +++ b/runtime/org.argeo.slc.support.equinox/src/main/resources/META-INF/spring/osgi.xml @@ -9,4 +9,9 @@ + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java index a096a44d4..22d1e4b45 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java @@ -17,12 +17,17 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.osgi.context.BundleContextAware; +import org.springframework.osgi.context.event.OsgiBundleApplicationContextEvent; +import org.springframework.osgi.context.event.OsgiBundleApplicationContextListener; +import org.springframework.osgi.context.event.OsgiBundleContextClosedEvent; +import org.springframework.osgi.context.event.OsgiBundleContextFailedEvent; +import org.springframework.osgi.context.event.OsgiBundleContextRefreshedEvent; import org.springframework.osgi.util.OsgiFilterUtils; import org.springframework.util.Assert; /** Wraps low-level access to a {@link BundleContext} */ public class BundlesManager implements BundleContextAware, FrameworkListener, - InitializingBean, DisposableBean { + InitializingBean, DisposableBean, OsgiBundleApplicationContextListener { private final static Log log = LogFactory.getLog(BundlesManager.class); private BundleContext bundleContext; @@ -72,7 +77,9 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, + ")"; // Wait for application context to be ready // TODO: use service tracker - getServiceRefSynchronous(ApplicationContext.class.getName(), filter); + ServiceReference[] srs = getServiceRefSynchronous( + ApplicationContext.class.getName(), filter); + ServiceReference sr = srs[0]; long aAppContext = System.currentTimeMillis(); long end = aAppContext; @@ -83,11 +90,23 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, log.debug(" TOTAL\t: " + (aAppContext - bAppContext) + "ms"); } - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Bundle " + bundle.getSymbolicName() + " ready to be used at latest version." + " (upgrade performed in " + (end - begin) + "ms)."); - log.debug(" TOTAL\t: " + (end - begin) + "ms"); + log.debug(" TOTAL\t: " + (end - begin) + "ms"); + + ApplicationContext applicationContext = (ApplicationContext) bundleContext + .getService(sr); + int beanDefCount = applicationContext.getBeanDefinitionCount(); + log.debug(" " + beanDefCount + " beans in app context of " + + bundle.getSymbolicName() + + ", average init time per bean=" + (end - begin) + / beanDefCount + "ms"); + } + + bundleContext.ungetService(sr); + } catch (Exception e) { throw new SlcException("Cannot update bundle " + osgiBundle, e); } @@ -339,4 +358,16 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, this.pollingPeriod = pollingPeriod; } + public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) { + if (event instanceof OsgiBundleContextRefreshedEvent) { + log.debug("App context refreshed: " + event); + } else if (event instanceof OsgiBundleContextFailedEvent) { + log.debug("App context failed: " + event); + } + if (event instanceof OsgiBundleContextClosedEvent) { + log.debug("App context closed: " + event); + } + + } + } -- 2.39.2