geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1155993 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: ./ osgi/
Date Wed, 10 Aug 2011 01:37:18 GMT
Author: gawor
Date: Wed Aug 10 01:37:17 2011
New Revision: 1155993

URL: http://svn.apache.org/viewvc?rev=1155993&view=rev
Log:
GERONIMODEVTOOLS-765: Module state synchronization improvements: 1) synchronize state for
osgi bundles & java ee modules, 2) more efficient way of getting module state for java
ee modules

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/SynchronizeProjectOnServerTask.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/AbstractModuleHandler.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/AbstractModuleHandler.java?rev=1155993&r1=1155992&r2=1155993&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
Wed Aug 10 01:37:17 2011
@@ -45,6 +45,8 @@ public abstract class AbstractModuleHand
     
     abstract public void doRestartModule(IModule[] module, IProgressMonitor monitor) throws
Exception;
 
+    abstract public int getModuleState(IModule module) throws Exception;
+    
     public void serverStopped() {        
     }
     

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.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/DefaultModuleHandler.java?rev=1155993&r1=1155992&r2=1155993&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
Wed Aug 10 01:37:17 2011
@@ -22,6 +22,9 @@ import java.util.Map;
 import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.TargetModuleID;
 
+import org.apache.geronimo.deployment.plugin.jmx.ExtendedDeploymentManager;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.st.v30.core.commands.DeploymentCmdStatus;
 import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
 import org.apache.geronimo.st.v30.core.commands.IDeploymentCommand;
@@ -125,13 +128,8 @@ public class DefaultModuleHandler extend
         String configId = DeploymentUtils.getLastKnownConfigurationId(module, getServer());
         if (configId != null) {
             IModule[] rootModule = new IModule[] { module };
-            if (DeploymentUtils.isStartedModule(dm, configId) != null) {
-                setModuleState(rootModule, IServer.STATE_STARTED);
-            } else if (DeploymentUtils.isStoppedModule(dm, configId) != null) {
-                setModuleState(rootModule, IServer.STATE_STOPPED);
-            } else {
-                setModuleState(rootModule, IServer.STATE_UNKNOWN);
-            }
+            int state = doGetModuleState( (ExtendedDeploymentManager) dm, configId);
+            setModuleState(rootModule, state == -1 ? IServer.STATE_UNKNOWN : state);
             mapper.addArtifactEntry(getServer(), module, configId);
         } else {
             doAdded(module, null, monitor);
@@ -250,5 +248,36 @@ public class DefaultModuleHandler extend
         mapper.addArtifactEntry(getServer(), module, ids[0].getModuleID());
         return ids;
     }
+
+    @Override
+    public int getModuleState(IModule module) throws Exception {
+        ExtendedDeploymentManager dm = (ExtendedDeploymentManager) DeploymentCommandFactory.getDeploymentManager(getServer());
+        String configID = ModuleArtifactMapper.getInstance().resolveArtifact(getServer(),
module);
+        return doGetModuleState(dm, configID);
+    }
+    
+    private int doGetModuleState(ExtendedDeploymentManager dm, String configID) {
+        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doGetModuleState",
configID);
+        
+        int moduleState = IServer.STATE_UNKNOWN;
+        if (configID != null) {
+            try {
+                State state = dm.getModulesState(Artifact.create(configID));
+                if (state == null) {
+                    moduleState = -1;
+                } else if (state == State.RUNNING) {
+                    moduleState = IServer.STATE_STARTED;
+                } else if (state == State.STOPPED) {
+                    moduleState = IServer.STATE_STOPPED;
+                }
+            } catch (Exception e) {
+                moduleState = IServer.STATE_UNKNOWN;
+                Trace.trace(Trace.ERROR, "getModuleState() failed", e, Activator.traceCore);
+            }
+        }
+        
+        Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.doGetModuleState",
configID, moduleState);
+        return moduleState;
+    }
     
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.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/DeploymentUtils.java?rev=1155993&r1=1155992&r2=1155993&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
Wed Aug 10 01:37:17 2011
@@ -399,22 +399,6 @@ public class DeploymentUtils {
         return moduleId;
     }
     
-    public static TargetModuleID isStartedModule(DeploymentManager dm, String configId) throws
TargetException {
-        Trace.tracePoint("Entry", Activator.traceCore, "DeploymentUtils.isStartedModule",
dm, configId);
-        TargetModuleID[] ids = dm.getRunningModules(null, dm.getTargets());
-        TargetModuleID moduleId = getModuleId(ids, configId);
-        Trace.tracePoint("Exit", Activator.traceCore, "DeploymentUtils.isStartedModule",
moduleId);
-        return moduleId;
-    }
-    
-    public static TargetModuleID isStoppedModule(DeploymentManager dm, String configId) throws
TargetException {
-        Trace.tracePoint("Entry", Activator.traceCore, "DeploymentUtils.isStoppedModule",
dm, configId);
-        TargetModuleID[] ids = dm.getNonRunningModules(null, dm.getTargets());
-        TargetModuleID moduleId = getModuleId(ids, configId);
-        Trace.tracePoint("Exit", Activator.traceCore, "DeploymentUtils.isStoppedModule",
moduleId);
-        return moduleId;
-    }
-    
     private static TargetModuleID getModuleId(TargetModuleID[] ids, String configId) {
         if (ids != null) {
             for (int i = 0; i < ids.length; i++) {

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.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/GeronimoServerBehaviourDelegate.java?rev=1155993&r1=1155992&r2=1155993&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
Wed Aug 10 01:37:17 2011
@@ -33,9 +33,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.Timer;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 
 import javax.enterprise.deploy.spi.Target;
 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
@@ -135,7 +132,7 @@ public class GeronimoServerBehaviourDele
 
     private PublishStateListener publishStateListener;
     
-    private Lock publishLock = new ReentrantLock();
+    private volatile boolean publishing;
     
     private Set<IProject> knownSourceProjects = null; 
     
@@ -726,24 +723,14 @@ public class GeronimoServerBehaviourDele
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModule");
     }
     
-    public Lock getPublishLock() {
-        return publishLock;
+    public boolean isPublishing() {
+        return publishing;
     }
     
     @Override
     public void publishStart(IProgressMonitor monitor) throws CoreException {
-        doPublishStart(monitor);
-        try {
-            if (!publishLock.tryLock(120, TimeUnit.SECONDS)) {
-                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable
to obtain publish lock"));
-            }
-        } catch (InterruptedException e) {
-            // ignore
-        }
-    }
-    
-    private void doPublishStart(IProgressMonitor monitor) throws CoreException {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishStart",
monitor);
+        publishing = true;
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishStart");
     }
     
@@ -752,7 +739,7 @@ public class GeronimoServerBehaviourDele
         try {
             doPublishFinish(monitor);
         } finally {
-            publishLock.unlock();
+            publishing = false;
         }
     }
     
@@ -899,7 +886,7 @@ public class GeronimoServerBehaviourDele
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.resetModuleState");
     }
     
-    private AbstractModuleHandler getModuleHandler(IModule module) {
+    protected AbstractModuleHandler getModuleHandler(IModule module) {
         return (GeronimoUtils.isBundleModule(module) || GeronimoUtils.isFragmentBundleModule(module))
? osgiModuleHandler : defaultModuleHandler;
     }
     

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/SynchronizeProjectOnServerTask.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/SynchronizeProjectOnServerTask.java?rev=1155993&r1=1155992&r2=1155993&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/SynchronizeProjectOnServerTask.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/SynchronizeProjectOnServerTask.java
Wed Aug 10 01:37:17 2011
@@ -21,18 +21,9 @@
 package org.apache.geronimo.st.v30.core;
 
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import java.util.TimerTask;
-import java.util.concurrent.locks.Lock;
 
-import javax.enterprise.deploy.spi.DeploymentManager;
-import javax.enterprise.deploy.spi.Target;
-import javax.enterprise.deploy.spi.TargetModuleID;
-
-import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -41,7 +32,6 @@ import org.eclipse.wst.server.core.IModu
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.IServerWorkingCopy;
 import org.eclipse.wst.server.core.ServerCore;
-import org.eclipse.wst.server.core.ServerUtil;
 
 public class SynchronizeProjectOnServerTask extends TimerTask {
 
@@ -49,85 +39,47 @@ public class SynchronizeProjectOnServerT
 
     private IServer server;
     
-    private Lock publishLock;
-
     public SynchronizeProjectOnServerTask(GeronimoServerBehaviourDelegate delegate, IServer
server) {
         this.delegate = delegate;
         this.server = server;
-        this.publishLock = delegate.getPublishLock();
     }
 
     @Override
     public void run() {
-        Trace.tracePoint("Entry ", Activator.traceCore, "SynchronizeProjectOnServerTask.run");
+        Trace.tracePoint("Entry", Activator.traceCore, "SynchronizeProjectOnServerTask.run");
 
-        if (canUpdateState() && publishLock.tryLock()) {
-            try {
-                Map<String, String> projectsOnServer = ModuleArtifactMapper.getInstance().getServerArtifactsMap(server);
+        if (canUpdateState() && !delegate.isPublishing()) {
 
-                if (projectsOnServer != null && !projectsOnServer.isEmpty()) {
-                    synchronized (projectsOnServer) {
-                        List<IModule> removedModules = new ArrayList<IModule>();
-
-                        DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(server);
-                        Target[] targets = dm.getTargets();
-
-                        TargetModuleID[] runningIds = dm.getRunningModules(null, targets);
-                        Set<String> runningConfigIds = createSet(runningIds);
-
-                        TargetModuleID[] nonRunningIds = dm.getNonRunningModules(null, targets);
-                        Set<String> nonRunningConfigIds = createSet(nonRunningIds);
-                        
-                        TargetModuleID[] availableIds = dm.getAvailableModules(null, targets);
-                        Set<String> availableConfigIds = createSet(availableIds);
-
-                        for (Map.Entry<String, String> entry : projectsOnServer.entrySet())
{   
-                            String moduleID = entry.getKey();
-                            String configID = entry.getValue();
-
-                            IModule module = ServerUtil.getModule(moduleID);
-                            if (module != null && ServerUtil.containsModule(server,
module, null)) {
-                                if (runningConfigIds.contains(configID)) {
-                                    delegate.setModulesState(new IModule[] { module }, IServer.STATE_STARTED);
-                                } else if (nonRunningConfigIds.contains(configID)) {
-                                    delegate.setModulesState(new IModule[] { module }, IServer.STATE_STOPPED);
-                                } else if (!availableConfigIds.contains(configID)) {
-                                    // it's not running, stopped or available - so remove
it
-                                    removedModules.add(module);
-                                }
-                            }
-                        }                        
-
-                        if (!removedModules.isEmpty()) {
-                            removeModules(removedModules);
-                        } else {
-                            Trace.trace(Trace.INFO, "SynchronizeProjectOnServerTask: no configuration
is removed outside eclipse on server: " + this.server.getId(), Activator.traceCore);
-                        }
+            List<IModule> removedModules = new ArrayList<IModule>();
 
+            IModule[] modules = server.getModules();
+
+            try {
+                for (IModule module : modules) {
+                    int state = delegate.getModuleHandler(module).getModuleState(module);
+                    if (state == -1) {
+                        removedModules.add(module);
+                    } else {
+                        delegate.setModulesState(new IModule[] { module }, state);
                     }
+                }
 
+                if (!removedModules.isEmpty()) {
+                    if (!delegate.isPublishing()) {
+                        removeModules(removedModules);
+                    }
                 } else {
-                    Trace.trace(Trace.INFO, "SynchronizeProjectOnServerTask: no project has
been deployed on server: " + this.server.getId(), Activator.traceCore);
+                    Trace.trace(Trace.INFO, "SynchronizeProjectOnServerTask: no configuration
is removed outside eclipse on server: " + server.getId(), Activator.traceCore);
                 }
 
             } catch (Exception e) {
                 Trace.trace(Trace.WARNING, "Error in SynchronizeProjectOnServerTask.run",
e, Activator.logCore);
-            } finally {
-                publishLock.unlock();
             }
         }
 
-        Trace.tracePoint("Exit ", Activator.traceCore, "SynchronizeProjectOnServerTask.run");
+        Trace.tracePoint("Exit", Activator.traceCore, "SynchronizeProjectOnServerTask.run");
     }
-
-    private static Set<String> createSet(TargetModuleID[] ids) {
-        Set<String> moduleIds = new HashSet<String>();
-        for (TargetModuleID id : ids) {
-            moduleIds.add(id.getModuleID());
-        }
-        return moduleIds;
-    }
-
+   
     private void removeModules(List<IModule> removedModules) {
         Trace.tracePoint("Entry ", Activator.traceCore, "SynchronizeProjectOnServerTask.removeModules",
removedModules);
 

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=1155993&r1=1155992&r2=1155993&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
Wed Aug 10 01:37:17 2011
@@ -17,11 +17,13 @@
 package org.apache.geronimo.st.v30.core.osgi;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.management.MBeanException;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 
@@ -111,18 +113,8 @@ public class OSGiModuleHandler extends A
         
         long bundleId = getBundleId(module);
         if (bundleId != -1) {
-            try {
-                String state = getBundleState(bundleId);
-                if ("active".equalsIgnoreCase(state)) {
-                    setModuleState(new IModule [] {module}, IServer.STATE_STARTED);
-                } else if ("resolved".equalsIgnoreCase(state)) {
-                    setModuleState(new IModule [] {module}, IServer.STATE_STOPPED);
-                } else {
-                    setModuleState(new IModule [] {module}, IServer.STATE_UNKNOWN);
-                }
-            } catch (Exception e) {
-                setModuleState(new IModule [] {module}, IServer.STATE_UNKNOWN);
-            }
+            int state = doGetModuleState(bundleId);
+            setModuleState(new IModule [] {module}, state);
         } else {
             doAdded(module, monitor);
         }
@@ -274,6 +266,45 @@ public class OSGiModuleHandler extends A
     }
     
     private MBeanServerConnection getServerConnection() throws Exception {
-        return serverDelegate.getServerConnection();
+        RemoteDeploymentManager dm = (RemoteDeploymentManager) DeploymentCommandFactory.getDeploymentManager(this.getServer());
+        return dm.getJMXConnector().getMBeanServerConnection();
+    }
+
+    @Override
+    public int getModuleState(IModule module) throws Exception {
+        long bundleId = getBundleId(module);
+        return doGetModuleState(bundleId);
+    }
+    
+    private int doGetModuleState(long bundleId) {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doGetModuleState",
bundleId);
+        
+        int bundleState = IServer.STATE_UNKNOWN;
+        if (bundleId != -1) {
+            String state = null;
+            try {
+                state = getBundleState(bundleId);
+                if ("active".equalsIgnoreCase(state)) {
+                    bundleState = IServer.STATE_STARTED;
+                } else if ("resolved".equalsIgnoreCase(state)) {
+                    bundleState = IServer.STATE_STOPPED;
+                }
+            } catch (MBeanException e) {
+                // XXXX: per spec when bundle is not found IllegalArgumentException should

+                // be thrown but Aries implementation throws IOException.
+                if (e.getCause() instanceof IllegalArgumentException ||
+                    e.getCause() instanceof IOException) {
+                    bundleState = -1;  
+                } else {
+                    bundleState = IServer.STATE_UNKNOWN;
+                }
+            } catch (Exception e) {
+                bundleState = IServer.STATE_UNKNOWN;
+                Trace.trace(Trace.ERROR, "getModuleState() failed", e, Activator.traceCore);
+            }
+        }
+        
+        Trace.tracePoint("Exit", Activator.traceCore, "OSGiBundleHandler.doGetModuleState",
bundleId, bundleState);
+        return bundleState;
     }
 }



Mime
View raw message