geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwo...@apache.org
Subject svn commit: r1142905 - in /geronimo/server/trunk/framework/modules: geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/ geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/
Date Tue, 05 Jul 2011 07:11:03 GMT
Author: rwonly
Date: Tue Jul  5 07:11:03 2011
New Revision: 1142905

URL: http://svn.apache.org/viewvc?rev=1142905&view=rev
Log:
GERONIMO-6046 Add getBundleId API to geronimo-bundle-recorder so that GEP don't need use the
SLOW listBundles method of OSGi JMX API

Modified:
    geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorder.java
    geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorderGBean.java
    geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/Utils.java
    geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java

Modified: geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorder.java?rev=1142905&r1=1142904&r2=1142905&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorder.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorder.java
Tue Jul  5 07:11:03 2011
@@ -38,6 +38,16 @@ public interface BundleRecorder {
      * @throws IOException
      */
     public void eraseUninstall(long bundleId) throws IOException;
+    
+    
+    /**
+     * Get the bundle id according to its symbolic name and version.
+     * It is pretty slow to call listBundles of OSGi JMX API.
+     * @param symbolicName
+     * @param version
+     * @return the installed bundle id, return -1 if can not find.
+     */
+    public long getBundleId(String symbolicName, String version);
 }
 
 

Modified: geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorderGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorderGBean.java?rev=1142905&r1=1142904&r2=1142905&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorderGBean.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/BundleRecorderGBean.java
Tue Jul  5 07:11:03 2011
@@ -19,6 +19,7 @@ package org.apache.geronimo.system.bundl
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Properties;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
@@ -32,6 +33,7 @@ import org.apache.geronimo.kernel.Kernel
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.WritableListableRepository;
 import org.apache.geronimo.kernel.util.FileUtils;
+import org.apache.geronimo.kernel.util.IOUtils;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -155,12 +157,19 @@ public class BundleRecorderGBean impleme
         String recordKey = getRecordKey(artifact);
         
         Properties startupBundles = new Properties();
-        startupBundles.load(new FileInputStream(startupFile)); 
-        if (startupBundles.containsKey(recordKey.toString())) { // check if we have recorded
this
-            log.warn("This bundle has been recorded in startup.properties: "+ recordKey);
-        } else {
-            // record it
-            Utils.appendLine(startupFile, recordKey+"="+String.valueOf(startLevel));
+        InputStream is = null;
+        try{
+            is = new FileInputStream(startupFile);
+            startupBundles.load(is); 
+            if (startupBundles.containsKey(recordKey.toString())) { // check if we have recorded
this
+                log.warn("This bundle has been recorded in startup.properties: "+ recordKey);
+            } else {
+                // record it
+                Utils.appendLine(startupFile, recordKey+"="+String.valueOf(startLevel));
+            }
+        }finally{
+            if (is!=null)
+                IOUtils.close(is);
         }
             
         return bundle.getBundleId();
@@ -242,4 +251,13 @@ public class BundleRecorderGBean impleme
         return recordKey.toString();
     }
     
+    @Override
+    public long getBundleId(String symbolicName, String version) {
+        for (Bundle bundle : bundleContext.getBundles()) {
+            if (symbolicName.equals(bundle.getSymbolicName()) && version.equals(bundle.getVersion().toString())){
+                return bundle.getBundleId();
+            }
+        }
+        return -1;
+    }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/Utils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/Utils.java?rev=1142905&r1=1142904&r2=1142905&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/Utils.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/Utils.java
Tue Jul  5 07:11:03 2011
@@ -58,7 +58,7 @@ public class Utils {
         File tmpFile = new File(file.getAbsolutePath()+".tmpfile");
         try {
             reader = new BufferedReader(new FileReader(file));
-            writer = new BufferedWriter(new FileWriter(tmpFile,true));
+            writer = new BufferedWriter(new FileWriter(tmpFile));
             String line = null;
             while (( line = reader.readLine()) != null){
                 if (line.startsWith("#")) { // comments line
@@ -74,8 +74,8 @@ public class Utils {
             }
             
         } finally {
-            reader.close();
-            writer.close();
+            IOUtils.close(reader);
+            IOUtils.close(writer);
         }
         
         if (file.delete()){
@@ -99,7 +99,7 @@ public class Utils {
             }
             
         } finally {
-            reader.close();
+            IOUtils.close(reader);
         }
         
         return null;

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java?rev=1142905&r1=1142904&r2=1142905&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
Tue Jul  5 07:11:03 2011
@@ -339,4 +339,14 @@ public abstract class ExtendedDeployment
             kernel.getProxyManager().destroyProxy(recorder);
         }
     }
+    
+    @Override
+    public long getBundleId(String symbolicName, String version) {
+        BundleRecorder recorder = getBundleRecorder();
+        try {
+            return recorder.getBundleId(symbolicName, version);
+        } finally {
+            kernel.getProxyManager().destroyProxy(recorder);
+        }
+    }
 }



Mime
View raw message