geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hanhongf...@apache.org
Subject svn commit: r1172513 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: ModuleArtifactMapper.java base/Bundle.java base/ModuleSet.java osgi/OSGiModuleHandler.java
Date Mon, 19 Sep 2011 08:34:13 GMT
Author: hanhongfang
Date: Mon Sep 19 08:34:12 2011
New Revision: 1172513

URL: http://svn.apache.org/viewvc?rev=1172513&view=rev
Log:
remove bundle id from persistence. GERONIMODEVTOOLS-759 Using the new APIs to manage the bundles
status both in GEP and Server side. Thanks Yi Xiao for the patch.

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/Bundle.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/ModuleSet.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java?rev=1172513&r1=1172512&r2=1172513&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
Mon Sep 19 08:34:12 2011
@@ -87,7 +87,9 @@ public class ModuleArtifactMapper {
         if(bundles != null) {
             String symbolicName = AriesHelper.getSymbolicName(module);
             Version version = AriesHelper.getVersion(module);
-            bundles.add(new Bundle(getId(module), symbolicName, version, bundleId, bundleStartLevel));
+            Bundle bundle = new Bundle(getId(module), symbolicName, version, bundleId, bundleStartLevel);
+            bundles.remove(bundle);
+            bundles.add(bundle);
         }
     }
     
@@ -102,28 +104,43 @@ public class ModuleArtifactMapper {
         }       
     }
     
-    synchronized public void removeBundleEntry(IServer server, IModule module) {
+    synchronized public boolean removeBundleEntry(IServer server, IModule module) {
         ModuleSet<Bundle> bundles = getServerBundles(server);
         if(bundles != null) {
             try {
-                bundles.remove("projectName", getId(module));
+                return bundles.remove("projectName", getId(module));
             } catch (Exception e) {
                 Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCore);
             }
         }
+        return false;
+    }
+    synchronized public boolean removeBundleEntryBySymbolicNameAndVersion(IServer server,
String symbolicName, Version version) {
+        String[] fieldNames = {"symbolicName", "version"};
+        Object[] values = {symbolicName, version};
+        ModuleSet<Bundle> bundles = getServerBundles(server);
+        if(bundles != null) {
+            try {
+                return bundles.remove(fieldNames, values);
+            } catch (Exception e) {
+                Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCore);
+            }
+        }
+        return false;
     }
     
-    synchronized public void removeBundleEntryById(IServer server, long bundleId) {
+    synchronized public boolean removeBundleEntryById(IServer server, long bundleId) {
         if(bundleId != -1) {
             ModuleSet<Bundle> bundles = getServerBundles(server);
             if(bundles != null) {
                 try {
-                    bundles.remove("id", bundleId);
+                    return bundles.remove("id", bundleId);
                 } catch (Exception e) {
                     Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.logCore);
                 }
             }
         }
+        return false;
     }
     
     synchronized public String resolveArtifact(IServer server, IModule module) {  

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/Bundle.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/Bundle.java?rev=1172513&r1=1172512&r2=1172513&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/Bundle.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/Bundle.java
Mon Sep 19 08:34:12 2011
@@ -33,7 +33,7 @@ public class Bundle implements Serializa
     private String projectName;
     private String symbolicName;
     private transient Version version;
-    private long id;
+    private transient long id;
     private int startLevel;
     
     

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/ModuleSet.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/ModuleSet.java?rev=1172513&r1=1172512&r2=1172513&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/ModuleSet.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/base/ModuleSet.java
Mon Sep 19 08:34:12 2011
@@ -53,10 +53,36 @@ public class ModuleSet<E> extends HashSe
         return element;
     }
     
+    public E query(String[] fieldNames, Object[] values) throws Exception {
+        if(fieldNames.length != values.length || fieldNames.length == 0) throw new Exception("The
fieldNames length must be same as values'");
+        E element = null;
+        
+        Iterator<E> iter = this.iterator();
+        while(iter.hasNext()) {
+            E b = iter.next();
+            boolean match = true;
+            for(int i=0; i<values.length; ++i) {
+                if(! values[i].equals(Utils.getValueByFieldName(fieldNames[i], b))) {
+                    match = false;
+                    break;
+                }
+            }
+            if(match) {
+                element = b;
+                break;
+            }
+        }
+        return element;
+    }
+    
     public boolean remove(String fieldName, Object value) throws Exception {
         return this.remove(this.query(fieldName, value));
     }
 
+    public boolean remove(String[] fieldNames, Object[] values) throws Exception {
+        return this.remove(this.query(fieldNames, values));
+    }
+    
     public int getDefaultModuleStartLevel() {
         return defaultStartLevel;
     }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java?rev=1172513&r1=1172512&r2=1172513&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
Mon Sep 19 08:34:12 2011
@@ -57,15 +57,16 @@ public class OSGiModuleHandler extends A
     	Bundle bundle = null;
     	if(module != null && module.getProject() != null) {
     	    bundle = this.mapper.resolveBundle(getServer(), module);
+    	    AriesHelper.BundleInfo bInfo = AriesHelper.getBundleInfo(module.getProject());
     		if(bundle == null) {// find the bundle in server side
     			RemoteDeploymentManager dm = (RemoteDeploymentManager) DeploymentCommandFactory.getDeploymentManager(this.getServer());
-    			AriesHelper.BundleInfo bInfo = AriesHelper.getBundleInfo(module.getProject());
-    			
                 long id = dm.getBundleId(bInfo.getSymbolicName(), bInfo.getVersion().toString());
                 if (id != -1) {
                     this.mapper.addBundleEntry(getServer(), module, id, this._getBundleStartLevelFromServer(id));
                     bundle = this.mapper.resolveBundleById(getServer(), id);
                 }
+    		} else {// need to synchronize bundle id from server
+    		    bundle.setId(this.synchronizeBundleId(bundle));
     		}
     	}
     	
@@ -73,6 +74,10 @@ public class OSGiModuleHandler extends A
     	return bundle;
     }
     
+    private long synchronizeBundleId(Bundle bundle) throws Exception {
+        RemoteDeploymentManager dm = (RemoteDeploymentManager) DeploymentCommandFactory.getDeploymentManager(this.getServer());
+        return dm.getBundleId(bundle.getSymbolicName(), bundle.getVersion().toString());
+    }
     public long queryBundleIdFromServer(String symbolicName, String version) throws Exception
{
         RemoteDeploymentManager dm = (RemoteDeploymentManager) DeploymentCommandFactory.getDeploymentManager(this.getServer());
         return dm.getBundleId(symbolicName, version);
@@ -132,7 +137,7 @@ public class OSGiModuleHandler extends A
         
         long bundleId = getBundleId(module);
         if (bundleId != -1) {
-            int state = doGetModuleState(bundleId);
+            int state = doGetModuleState(module, bundleId);
             setModuleState(new IModule [] {module}, state);
         } else {
             doAdded(module, monitor);
@@ -300,10 +305,10 @@ public class OSGiModuleHandler extends A
     @Override
     public int getModuleState(IModule module) throws Exception {
         long bundleId = getBundleId(module);
-        return doGetModuleState(bundleId);
+        return doGetModuleState(module, bundleId);
     }
     
-    private int doGetModuleState(long bundleId) {
+    private int doGetModuleState(IModule module, long bundleId) throws Exception {
         Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doGetModuleState",
bundleId);
         
         int bundleState = IServer.STATE_UNKNOWN;
@@ -329,6 +334,12 @@ public class OSGiModuleHandler extends A
                 bundleState = IServer.STATE_UNKNOWN;
                 Trace.trace(Trace.ERROR, "getModuleState() failed", e, Activator.traceCore);
             }
+        } else {// need to remove the bundle from local cache
+            bundleState = -1;
+            if(!this.mapper.removeBundleEntry(getServer(), module)) {
+                AriesHelper.BundleInfo bInfo = AriesHelper.getBundleInfo(module.getProject());
+                this.mapper.removeBundleEntryBySymbolicNameAndVersion(getServer(), bInfo.getSymbolicName(),
bInfo.getVersion());
+            }
         }
         
         Trace.tracePoint("Exit", Activator.traceCore, "OSGiBundleHandler.doGetModuleState",
bundleId, bundleState);



Mime
View raw message