geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1296406 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: GeronimoServerBehaviourDelegate.java SynchronizeProjectOnServerTask.java
Date Fri, 02 Mar 2012 19:40:32 GMT
Author: gawor
Date: Fri Mar  2 19:40:32 2012
New Revision: 1296406

URL: http://svn.apache.org/viewvc?rev=1296406&view=rev
Log:
GERONIMODEVTOOLS-789: Improve SynchronizeProjectOnServerTask

Modified:
    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

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=1296406&r1=1296405&r2=1296406&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
Fri Mar  2 19:40:32 2012
@@ -126,7 +126,7 @@ public class GeronimoServerBehaviourDele
     
     protected Timer stateTimer = null;
     
-    protected Timer synchronizerTimer = null;
+    protected SynchronizeProjectOnServerTask synchronizerTask = null;
 
     protected PingThread pingThread;
 
@@ -136,8 +136,6 @@ public class GeronimoServerBehaviourDele
 
     private PublishStateListener publishStateListener;
     
-    private volatile boolean publishing;
-    
     private Set<IProject> knownSourceProjects = null; 
     
     private DefaultModuleHandler defaultModuleHandler;
@@ -791,24 +789,15 @@ public class GeronimoServerBehaviourDele
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModule");
     }
     
-    public boolean isPublishing() {
-        return publishing;
-    }
-    
     @Override
     public void publishStart(IProgressMonitor monitor) throws CoreException {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishStart",
monitor);
-        publishing = true;
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishStart");
     }
     
     @Override
     public void publishFinish(IProgressMonitor monitor) throws CoreException {
-        try {
-            doPublishFinish(monitor);
-        } finally {
-            publishing = false;
-        }
+        doPublishFinish(monitor);
     }
     
     private void doPublishFinish(IProgressMonitor monitor) throws CoreException  {
@@ -1387,12 +1376,12 @@ public class GeronimoServerBehaviourDele
     public void startSynchronizeProjectOnServerTask() {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.startSynchronizeProjectOnServerTask",
getServer().getName());
 
-        if (synchronizerTimer != null) {
-            synchronizerTimer.cancel();
+        if (synchronizerTask != null) {
+            synchronizerTask.stop();
         }
         
-        synchronizerTimer = new Timer(true);
-        synchronizerTimer.schedule(new SynchronizeProjectOnServerTask(this, getServer()),
0, TIMER_TASK_INTERVAL * 1000);
+        synchronizerTask = new SynchronizeProjectOnServerTask(this, getServer());
+        synchronizerTask.start();
         
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.startSynchronizeProjectOnServerTask");
     }
@@ -1411,9 +1400,9 @@ public class GeronimoServerBehaviourDele
     public void stopSynchronizeProjectOnServerTask() {
         Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.stopSynchronizeProjectOnServerTask",
Activator.traceCore);
         
-        if (synchronizerTimer != null) {
-            synchronizerTimer.cancel();
-            synchronizerTimer = null;
+        if (synchronizerTask != null) {
+            synchronizerTask.stop();
+            synchronizerTask = null;
         }
 
         Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.stopSynchronizeProjectOnServerTask",
Activator.traceCore);

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=1296406&r1=1296405&r2=1296406&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
Fri Mar  2 19:40:32 2012
@@ -22,35 +22,86 @@ package org.apache.geronimo.st.v30.core;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Timer;
 import java.util.TimerTask;
 
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IPublishListener;
 import org.eclipse.wst.server.core.IServer;
 import org.eclipse.wst.server.core.IServerWorkingCopy;
 import org.eclipse.wst.server.core.ServerCore;
 
-public class SynchronizeProjectOnServerTask extends TimerTask {
+public class SynchronizeProjectOnServerTask extends TimerTask implements IPublishListener
{
 
     private GeronimoServerBehaviourDelegate delegate;
-
     private IServer server;
     
+    private boolean checkForRemovedModules;
+    private boolean publishing;
+    private long publishCount;
+    
+    private Timer timer;
+    
     public SynchronizeProjectOnServerTask(GeronimoServerBehaviourDelegate delegate, IServer
server) {
         this.delegate = delegate;
         this.server = server;
+        this.checkForRemovedModules = getCheckForRemovedModules();
+        Trace.trace(Trace.INFO, "SynchronizeProjectOnServerTask: checkForRemovedModules:="
+ checkForRemovedModules, Activator.traceCore);
     }
 
+    private static boolean getCheckForRemovedModules() {
+        String property = System.getProperty(SynchronizeProjectOnServerTask.class.getName()
+ ".checkForRemovedModules");
+        return (property == null) ? true : "true".equalsIgnoreCase(property);
+    }
+    
+    public synchronized void start() {
+        server.addPublishListener(this);
+        if (timer != null) {
+            timer.cancel();
+        }
+        timer = new Timer(true);
+        timer.schedule(this, 0, GeronimoServerBehaviourDelegate.TIMER_TASK_INTERVAL * 1000);
+    }
+    
+    public synchronized void stop() {
+        server.removePublishListener(this);
+        if (timer != null) {
+            timer.cancel();
+            timer = null;
+        }
+    }
+    
+    @Override
+    public synchronized void publishStarted(IServer server) {
+        Trace.tracePoint("Entry", Activator.traceCore, "SynchronizeProjectOnServerTask.publishStarted",
server);
+        publishing = true;
+        publishCount++;
+        Trace.tracePoint("Exit ", Activator.traceCore, "SynchronizeProjectOnServerTask.publishStarted");
+    }
+    
+    @Override
+    public synchronized void publishFinished(IServer server, IStatus status) {
+        Trace.tracePoint("Entry", Activator.traceCore, "SynchronizeProjectOnServerTask.publishFinished",
server, status);
+        publishing = false;
+        Trace.tracePoint("Exit ", Activator.traceCore, "SynchronizeProjectOnServerTask.publishFinished");
+    }
+    
+    private synchronized long getPublishCount() {
+        return (publishing) ? -1 : publishCount;
+    }
+    
     @Override
     public void run() {
         Trace.tracePoint("Entry", Activator.traceCore, "SynchronizeProjectOnServerTask.run");
 
-        if (canUpdateState() && !delegate.isPublishing()) {
-
-            List<IModule> removedModules = new ArrayList<IModule>();
+        long startPublishCount = getPublishCount();
+        if (canUpdateState() && startPublishCount != -1) {
+            List<IModule> removedModules = null;
 
             IModule[] modules = server.getModules();
 
@@ -63,16 +114,20 @@ public class SynchronizeProjectOnServerT
                     }
                     int state = delegate.getModuleHandler(module).getModuleState(module);
                     if (state == -1) {
-                        removedModules.add(module);
+                        if (checkForRemovedModules) {
+                            if (removedModules == null) {
+                                removedModules = new ArrayList<IModule>();
+                            }
+                            removedModules.add(module);
+                        }
                     } else {
                         delegate.setModulesState(rootModule, state);
                     }
                 }
 
-                if (!removedModules.isEmpty()) {
-                    if (!delegate.isPublishing()) {
-                        removeModules(removedModules);
-                    }
+                long endPublishCount = getPublishCount();          
+                if (startPublishCount == endPublishCount && removedModules != null)
{
+                    removeModules(removedModules);                    
                 } else {
                     Trace.trace(Trace.INFO, "SynchronizeProjectOnServerTask: no configuration
is removed outside eclipse on server: " + server.getId(), Activator.traceCore);
                 }



Mime
View raw message