[jboss-cvs] JBossAS SVN: r100664 - in projects/jboss-osgi/projects: bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Feb 7 07:11:25 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-02-07 07:11:24 -0500 (Sun, 07 Feb 2010)
New Revision: 100664

Added:
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractInvoker.java
Removed:
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/OSGiInvoker.java
Modified:
   projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractConnector.java
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicRequest.java
   projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java
   projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java
   projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
Log:
Add more trace logging

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/pom.xml	2010-02-07 12:11:24 UTC (rev 100664)
@@ -216,7 +216,7 @@
                 </property>
                 <property>
                   <name>org.jboss.osgi.husky.Invoker</name>
-                  <value>org.jboss.osgi.husky.internal.OSGiInvoker</value>
+                  <value>org.jboss.osgi.husky.internal.AbstractInvoker</value>
                 </property>
                 <property>
                   <name>test.archive.directory</name>

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractConnector.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractConnector.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractConnector.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -37,6 +37,8 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * An abstract {@link Connector} implementation 
@@ -46,6 +48,9 @@
  */
 public abstract class AbstractConnector implements Connector
 {
+   // Provide logging
+   final Logger log = LoggerFactory.getLogger(AbstractConnector.class);
+   
    private BundleContext context;
 
    public AbstractConnector(BundleContext context)
@@ -138,6 +143,8 @@
          ObjectInputStream ois = new ObjectInputStream(reqStream);
          request = (Request)ois.readObject();
 
+         log.debug("Start invoke: " + request);
+         
          // Field the request through the abstract connector
          response = process(request);
       }
@@ -152,6 +159,10 @@
          }
          response.addFailure(failure);
       }
+      finally
+      {
+         log.debug("End invoke: " + response);
+      }
 
       // Marshall the Response
       try

Copied: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractInvoker.java (from rev 100650, projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/OSGiInvoker.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractInvoker.java	                        (rev 0)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/AbstractInvoker.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.husky.internal;
+
+// $Id$
+
+import java.util.ArrayList;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerFactory;
+
+import org.jboss.osgi.husky.Invoker;
+import org.jboss.osgi.husky.Request;
+import org.jboss.osgi.husky.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An {@link Invoker} suitable for OSGi bundle testing.
+ * 
+ * It delegates the invocation to 
+ * 
+ * #1 {@link SocketInvocation}
+ * #2 {@link JMXInvocation}
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-May-2009
+ */
+public class AbstractInvoker implements Invoker
+{
+   // Provide logging
+   final Logger log = LoggerFactory.getLogger(AbstractInvoker.class);
+   
+   public Response invoke(Request req)
+   {
+      log.debug("Start invoke: " + req);
+      
+      Response res = null;
+      try
+      {
+         MBeanServerConnection server = getMBeanServer();
+         if (SocketInvocation.isRemoteConnection())
+         {
+            res = new SocketInvocation().invoke(req);
+         }
+         else 
+         {
+            res = new JMXInvocation().invoke(server, req);
+         }
+         return res;
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception ex)
+      {
+         throw new IllegalStateException("Cannot invoke connector", ex);
+      }
+      finally
+      {
+         log.debug("End invoke: " + res);
+      }
+   }
+
+   @SuppressWarnings("unchecked")
+   private MBeanServerConnection getMBeanServer()
+   {
+      ArrayList<MBeanServer> serverArr = MBeanServerFactory.findMBeanServer(null);
+      if (serverArr.size() > 1)
+         throw new IllegalStateException("Multiple MBeanServer instances not supported");
+
+      MBeanServer server = null;
+      if (serverArr.size() == 1)
+         server = serverArr.get(0);
+
+      if (server == null)
+         server = MBeanServerFactory.createMBeanServer();
+
+      return server;
+   }
+
+}

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicRequest.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicRequest.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicRequest.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -40,6 +40,11 @@
 
    public BasicRequest(String className, String methodName)
    {
+      if (className == null)
+         throw new IllegalArgumentException("Null className");
+      if (methodName == null)
+         throw new IllegalArgumentException("Null methodName");
+      
       this.className = className;
       this.methodName = methodName;
    }
@@ -54,4 +59,14 @@
       return methodName;
    }
 
+   @Override
+   public String toString()
+   {
+      String testName = className;
+      int dotIndex = testName.lastIndexOf(".");
+      if (dotIndex > 0)
+         testName = testName.substring(dotIndex + 1);
+      testName = testName + "." + methodName;
+      return "BasicRequest[" + testName + "]";
+   }
 }

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -39,16 +39,28 @@
 public class BasicResponse implements Response
 {
    private static final long serialVersionUID = 1L;
-   
+
    private List<Failure> failures = new ArrayList<Failure>();
 
    public List<Failure> getFailures()
    {
       return Collections.unmodifiableList(failures);
    }
-   
+
    public void addFailure(Failure failure)
    {
       failures.add(failure);
    }
+
+   @Override
+   public String toString()
+   {
+      StringBuffer msgs = new StringBuffer();
+      for (int i = 0; i < failures.size(); i++)
+      {
+         Failure f = failures.get(i);
+         msgs.append((i > 0 ? "," : "") + f.getMessage());
+      }
+      return "BasicResponse[" + msgs + "]";
+   }
 }

Deleted: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/OSGiInvoker.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/OSGiInvoker.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/husky/internal/OSGiInvoker.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.husky.internal;
-
-// $Id$
-
-import java.util.ArrayList;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanServerFactory;
-
-import org.jboss.osgi.husky.Invoker;
-import org.jboss.osgi.husky.Request;
-import org.jboss.osgi.husky.Response;
-
-/**
- * An {@link Invoker} suitable for OSGi bundle testing.
- * 
- * It delegates the invocation to 
- * 
- * #1 {@link SocketInvocation}
- * #2 {@link JMXInvocation}
- * 
- * @author Thomas.Diesler at jboss.com
- * @since 16-May-2009
- */
-public class OSGiInvoker implements Invoker
-{
-   public Response invoke(Request req)
-   {
-      try
-      {
-         MBeanServerConnection server = getMBeanServer();
-         if (SocketInvocation.isRemoteConnection())
-         {
-            return new SocketInvocation().invoke(req);
-         }
-         else 
-         {
-            return new JMXInvocation().invoke(server, req);
-         }
-      }
-      catch (RuntimeException rte)
-      {
-         throw rte;
-      }
-      catch (Exception ex)
-      {
-         throw new IllegalStateException("Cannot invoke connector", ex);
-      }
-   }
-
-   @SuppressWarnings("unchecked")
-   private MBeanServerConnection getMBeanServer()
-   {
-      ArrayList<MBeanServer> serverArr = MBeanServerFactory.findMBeanServer(null);
-      if (serverArr.size() > 1)
-         throw new IllegalStateException("Multiple MBeanServer instances not supported");
-
-      MBeanServer server = null;
-      if (serverArr.size() == 1)
-         server = serverArr.get(0);
-
-      if (server == null)
-         server = MBeanServerFactory.createMBeanServer();
-
-      return server;
-   }
-
-}

Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -73,6 +73,9 @@
 
    private ManagedBundle register(Bundle bundle)
    {
+      if (log.isTraceEnabled())
+         log.trace("register(" + bundle + ")");
+
       try
       {
          ManagedBundle mb = new ManagedBundle(systemContext, bundle);
@@ -95,6 +98,9 @@
 
    private void unregister(Bundle bundle)
    {
+      if (log.isTraceEnabled())
+         log.trace("unregister(" + bundle + ")");
+
       try
       {
          ObjectName oname = ManagedBundle.getObjectName(bundle);

Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/ManagedFrameworkImpl.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -24,11 +24,12 @@
 //$Id$
 
 import static org.jboss.osgi.spi.OSGiConstants.DOMAIN_NAME;
+import static org.jboss.osgi.spi.management.ManagedBundle.PROPERTY_ID;
 import static org.jboss.osgi.spi.management.ManagedBundle.PROPERTY_SYMBOLIC_NAME;
 import static org.jboss.osgi.spi.management.ManagedBundle.PROPERTY_VERSION;
-import static org.jboss.osgi.spi.management.ManagedBundle.PROPERTY_ID;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -115,6 +116,9 @@
          }
       }
 
+      if (log.isTraceEnabled())
+         log.trace("getBundle(" + symbolicName + "," + version + ") => " + oname);
+
       return oname;
    }
 
@@ -129,6 +133,9 @@
       if (names.size() > 0)
          oname = names.iterator().next();
 
+      if (log.isTraceEnabled())
+         log.trace("getBundle(" + bundleId + ") => " + oname);
+      
       return oname;
    }
 
@@ -141,6 +148,10 @@
 
       ObjectName pattern = ObjectNameFactory.create(DOMAIN_NAME + ":*");
       Set<ObjectName> names = mbeanServer.queryNames(pattern, new IsBundleQueryExp());
+      
+      if (log.isTraceEnabled())
+         log.trace("getBundles() => " + names);
+      
       return names;
    }
 
@@ -156,7 +167,11 @@
          props.put(key, sref.getProperty(key));
       }
 
-      return new ManagedServiceReference(props);
+      ManagedServiceReference msref = new ManagedServiceReference(props);
+      if (log.isTraceEnabled())
+         log.trace("getServiceReference(" + clazz + ") => " + msref);
+      
+      return msref;
    }
 
    public ManagedServiceReference[] getServiceReferences(String clazz, String filter)
@@ -185,15 +200,21 @@
          }
       }
 
-      ManagedServiceReference[] manrefs = null;
+      ManagedServiceReference[] msrefs = null;
       if (foundRefs.size() > 0)
-         manrefs = foundRefs.toArray(new ManagedServiceReference[foundRefs.size()]);
+         msrefs = foundRefs.toArray(new ManagedServiceReference[foundRefs.size()]);
 
-      return manrefs;
+      if (log.isTraceEnabled())
+         log.trace("getServiceReferences(" + clazz + "," + filter +") => " + msrefs);
+      
+      return msrefs;
    }
 
    public void refreshPackages(ObjectName[] objectNames)
    {
+      if (log.isTraceEnabled())
+         log.trace("refreshPackages(" + Arrays.asList(objectNames) +")");
+      
       Bundle[] bundleArr = getBundles(objectNames);
       ServiceReference sref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
       PackageAdmin service = (PackageAdmin)getBundleContext().getService(sref);
@@ -202,6 +223,9 @@
 
    public boolean resolveBundles(ObjectName[] objectNames)
    {
+      if (log.isTraceEnabled())
+         log.trace("resolveBundles(" + Arrays.asList(objectNames) +")");
+      
       Bundle[] bundleArr = getBundles(objectNames);
       ServiceReference sref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
       PackageAdmin service = (PackageAdmin)getBundleContext().getService(sref);

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2010-02-07 12:10:17 UTC (rev 100663)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2010-02-07 12:11:24 UTC (rev 100664)
@@ -33,12 +33,15 @@
 
 import javax.management.ObjectName;
 
+import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.osgi.service.packageadmin.PackageAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The managed view of an OSGi Bundle
@@ -48,6 +51,9 @@
  */
 public class ManagedBundle implements ManagedBundleMBean
 {
+   // Provide logging
+   final Logger log = LoggerFactory.getLogger(ManagedBundle.class);
+   
    public static final String PROPERTY_ID = "id";
    public static final String PROPERTY_SYMBOLIC_NAME = "name";
    public static final String PROPERTY_VERSION = "version";
@@ -56,16 +62,19 @@
    private Bundle bundle;
    private ObjectName oname;
 
-   public ManagedBundle(BundleContext context, Bundle bundle)
+   public ManagedBundle(BundleContext syscontext, Bundle bundle)
    {
-      if (context == null)
+      if (syscontext == null)
          throw new IllegalArgumentException("Null system context");
       if (bundle == null)
          throw new IllegalArgumentException("Null bundle");
       
       this.bundle = bundle;
-      this.systemContext = context;
+      this.systemContext = syscontext;
       this.oname = getObjectName(bundle);
+      
+      if (log.isTraceEnabled())
+         log.trace("new ManagedBundle[" + oname + "]");
    }
 
    public static ObjectName getObjectName(Bundle bundle)
@@ -92,12 +101,22 @@
 
    public String getProperty(String key)
    {
-      return bundle.getBundleContext().getProperty(key);
+      String value = bundle.getBundleContext().getProperty(key);
+      
+      if (log.isTraceEnabled())
+         log.trace("getProperty[" + oname + "](" + key + ") => " + value);
+      
+      return value;
    }
 
    public int getState()
    {
-      return bundle.getState();
+      int state = bundle.getState();
+      
+      if (log.isTraceEnabled())
+         log.trace("getState[" + oname + "] => " + ConstantsHelper.bundleState(state));
+      
+      return state;
    }
 
    public long getBundleId()
@@ -112,7 +131,12 @@
 
    public String getLocation()
    {
-      return bundle.getLocation();
+      String location = bundle.getLocation();
+      
+      if (log.isTraceEnabled())
+         log.trace("getLocation[" + oname + "] => " + location);
+      
+      return location;
    }
 
    public Dictionary<String, String> getHeaders()
@@ -132,46 +156,79 @@
          String value = (String)bundleHeaders.get(key);
          retHeaders.put(key, value);
       }
+      
+      if (log.isTraceEnabled())
+         log.trace("getHeaders[" + oname + "](" + locale + ") => " + retHeaders);
+      
       return retHeaders;
    }
 
    public String getEntry(String path)
    {
       URL url = bundle.getEntry(path);
-      return url != null ? url.toExternalForm() : null;
+      String entry = url != null ? url.toExternalForm() : null;
+      
+      if (log.isTraceEnabled())
+         log.trace("getEntry[" + oname + "](" + path + ") => " + entry);
+      
+      return entry;
    }
 
    public String getResource(String name)
    {
       URL url = bundle.getResource(name);
-      return url != null ? url.toExternalForm() : null;
+      String resource = url != null ? url.toExternalForm() : null;
+      
+      if (log.isTraceEnabled())
+         log.trace("getResource[" + oname + "](" + name + ") => " + resource);
+      
+      return resource;
    }
 
    public ObjectName loadClass(String name) throws ClassNotFoundException
    {
       Class<?> clazz = bundle.loadClass(name);
       Bundle providingBundle = getPackageAdmin().getBundle(clazz);
-      return providingBundle != null ? getObjectName(providingBundle) : null;
+      ObjectName oname = providingBundle != null ? getObjectName(providingBundle) : null;
+
+      if (log.isTraceEnabled())
+         log.trace("loadClass[" + oname + "](" + name + ") => " + oname);
+      
+      return oname;
    }
    
    public File getDataFile(String filename)
    {
       BundleContext context = bundle.getBundleContext();
-      return context.getDataFile(filename);
+      File dataFile = context.getDataFile(filename);
+
+      if (log.isTraceEnabled())
+         log.trace("getDataFile[" + oname + "](" + filename + ") => " + dataFile);
+      
+      return dataFile;
    }
 
    public void start() throws BundleException
    {
+      if (log.isTraceEnabled())
+         log.trace("start[" + oname + "]");
+      
       bundle.start();
    }
 
    public void stop() throws BundleException
    {
+      if (log.isTraceEnabled())
+         log.trace("stop[" + oname + "]");
+      
       bundle.stop();
    }
 
    public void update() throws BundleException
    {
+      if (log.isTraceEnabled())
+         log.trace("update[" + oname + "]");
+      
       bundle.update();
    }
 




More information about the jboss-cvs-commits mailing list