jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1670401 - /jackrabbit/commons/filevault/trunk/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpTask.java
Date Tue, 31 Mar 2015 17:24:31 GMT
Author: tripod
Date: Tue Mar 31 17:24:31 2015
New Revision: 1670401

URL: http://svn.apache.org/r1670401
Log:
adding better threading control

Modified:
    jackrabbit/commons/filevault/trunk/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpTask.java

Modified: jackrabbit/commons/filevault/trunk/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpTask.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpTask.java?rev=1670401&r1=1670400&r2=1670401&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpTask.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpTask.java
Tue Mar 31 17:24:31 2015
@@ -53,6 +53,7 @@ public class RcpTask implements Runnable
         NEW,
         RUNNING,
         ENDED,
+        STOPPING,
         STOPPED
     }
     private final RcpTaskManagerImpl mgr;
@@ -71,6 +72,8 @@ public class RcpTask implements Runnable
 
     private volatile STATE state = STATE.NEW;
 
+    private Exception error = null;
+
     private List<String> excludes = new ArrayList<String>();
 
     private Thread thread;
@@ -107,20 +110,24 @@ public class RcpTask implements Runnable
 
     public boolean stop() {
         // wait for thread
-        if (state != STATE.STOPPED) {
-            if (state == STATE.RUNNING) {
-                rcp.abort();
-            }
-            state = STATE.STOPPED;
-            log.info("Stopping task {}...", id);
-            if (thread != null) {
+        if (state != STATE.STOPPED && state != STATE.STOPPING) {
+            rcp.abort();
+            int cnt = 3;
+            while (thread != null && thread.isAlive() && cnt-- > 0) {
+                state = STATE.STOPPING;
+                log.info("Stopping task {}...", id);
                 try {
-                    thread.join();
+                    thread.join(10000);
                 } catch (InterruptedException e) {
                     log.error("Error while waiting for thread: " + thread.getName(), e);
                 }
-                thread = null;
+                if (thread.isAlive()) {
+                    // try to interrupt the thread
+                    thread.interrupt();
+                }
             }
+            state = STATE.STOPPED;
+            thread = null;
             if (srcSession != null) {
                 srcSession.logout();
                 srcSession = null;
@@ -189,8 +196,14 @@ public class RcpTask implements Runnable
         log.info("Starting repository copy task id={}. From {} to {}.", new Object[]{
                 id, src.toString(), dst
         });
-        rcp.copy(srcSession, src.getPath(), dstSession, dst, recursive);
-        state = STATE.ENDED;
+        try {
+            rcp.copy(srcSession, src.getPath(), dstSession, dst, recursive);
+            state = STATE.ENDED;
+        } catch (Exception e) {
+            error = e;
+        } finally {
+            state = STATE.ENDED;
+        }
         // todo: notify manager that we ended.
     }
 
@@ -250,6 +263,7 @@ public class RcpTask implements Runnable
         w.key("totalSize").value(rcp.getTotalSize());
         w.key("currentSize").value(rcp.getCurrentSize());
         w.key("currentNodes").value(rcp.getCurrentNumNodes());
+        w.key("error").value(error == null ? "" : error.toString());
         w.endObject();
         w.endObject();
     }



Mime
View raw message