You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/06/05 05:06:18 UTC
svn commit: r1489689 - in /manifoldcf/trunk/connectors:
dropbox/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/dropbox/
googledrive/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/googledrive/
Author: kwright
Date: Wed Jun 5 03:06:17 2013
New Revision: 1489689
URL: http://svn.apache.org/r1489689
Log:
Again, more rearrangement. This time make sure finishUp() is in a finally block, and merge it with abort().
Modified:
manifoldcf/trunk/connectors/dropbox/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/dropbox/DropboxRepositoryConnector.java
manifoldcf/trunk/connectors/googledrive/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/googledrive/GoogleDriveRepositoryConnector.java
Modified: manifoldcf/trunk/connectors/dropbox/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/dropbox/DropboxRepositoryConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/dropbox/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/dropbox/DropboxRepositoryConnector.java?rev=1489689&r1=1489688&r2=1489689&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/dropbox/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/dropbox/DropboxRepositoryConnector.java (original)
+++ manifoldcf/trunk/connectors/dropbox/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/dropbox/DropboxRepositoryConnector.java Wed Jun 5 03:06:17 2013
@@ -673,32 +673,23 @@ public class DropboxRepositoryConnector
}
getSession();
- XThreadStringBuffer seedBuffer = new XThreadStringBuffer();
- GetSeedsThread t = new GetSeedsThread(dropboxPath, seedBuffer);
+ GetSeedsThread t = new GetSeedsThread(dropboxPath);
try {
t.start();
-
- // Pick up the paths, and add them to the activities, before we join with the child thread.
- while (true) {
- // The only kind of exceptions this can throw are going to shut the process down.
- String docPath = seedBuffer.fetch();
- if (docPath == null)
- break;
- // Add the pageID to the queue
- activities.addSeedDocument(docPath);
- }
-
- t.join();
+ try {
+ XThreadStringBuffer seedBuffer = t.getBuffer();
- Throwable thr = t.getException();
- if (thr != null) {
- if (thr instanceof DropboxException) {
- throw (DropboxException) thr;
- } else if (thr instanceof RuntimeException) {
- throw (RuntimeException) thr;
- } else {
- throw (Error) thr;
+ // Pick up the paths, and add them to the activities, before we join with the child thread.
+ while (true) {
+ // The only kind of exceptions this can throw are going to shut the process down.
+ String docPath = seedBuffer.fetch();
+ if (docPath == null)
+ break;
+ // Add the pageID to the queue
+ activities.addSeedDocument(docPath);
}
+ } finally {
+ t.finishUp();
}
} catch (InterruptedException e) {
t.interrupt();
@@ -707,9 +698,6 @@ public class DropboxRepositoryConnector
} catch (DropboxException e) {
Logging.connectors.warn("DROPBOX: Error adding seed documents: " + e.getMessage(), e);
handleDropboxException(e);
- } finally {
- // Make SURE buffer is dead, otherwise child thread may well hang waiting on it
- seedBuffer.abandon();
}
}
@@ -719,10 +707,10 @@ public class DropboxRepositoryConnector
protected final String path;
protected final XThreadStringBuffer seedBuffer;
- public GetSeedsThread(String path, XThreadStringBuffer seedBuffer) {
+ public GetSeedsThread(String path) {
super();
this.path = path;
- this.seedBuffer = seedBuffer;
+ this.seedBuffer = new XThreadStringBuffer();
setDaemon(true);
}
@@ -735,8 +723,25 @@ public class DropboxRepositoryConnector
}
}
- public Throwable getException() {
- return exception;
+ public XThreadStringBuffer getBuffer() {
+ return seedBuffer;
+ }
+
+ public void finishUp()
+ throws InterruptedException, DropboxException {
+ seedBuffer.abandon();
+ join();
+ Throwable thr = exception;
+ if (thr != null) {
+ if (thr instanceof DropboxException)
+ throw (DropboxException) thr;
+ else if (thr instanceof RuntimeException)
+ throw (RuntimeException) thr;
+ else if (thr instanceof Error)
+ throw (Error) thr;
+ else
+ throw new RuntimeException("Unhandled exception of type: "+thr.getClass().getName(),thr);
+ }
}
}
@@ -856,13 +861,10 @@ public class DropboxRepositoryConnector
is.close();
}
} finally {
- // Abort, no matter what
- t.abort();
+ // This does a join
+ t.finishUp();
}
- // This does a join
- t.finishUp();
-
// No errors. Record the fact that we made it.
errorCode = "OK";
fileSize = new Long(fileLength);
@@ -1002,7 +1004,8 @@ public class DropboxRepositoryConnector
}
}
- public void abort()
+ public void finishUp()
+ throws InterruptedException, IOException, DropboxException
{
// This will be called during the finally
// block in the case where all is well (and
@@ -1014,12 +1017,9 @@ public class DropboxRepositoryConnector
}
abortThread = true;
}
- }
-
- public void finishUp()
- throws InterruptedException, IOException, DropboxException
- {
+
join();
+
checkException(responseException);
}
Modified: manifoldcf/trunk/connectors/googledrive/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/googledrive/GoogleDriveRepositoryConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/googledrive/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/googledrive/GoogleDriveRepositoryConnector.java?rev=1489689&r1=1489688&r2=1489689&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/googledrive/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/googledrive/GoogleDriveRepositoryConnector.java (original)
+++ manifoldcf/trunk/connectors/googledrive/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/googledrive/GoogleDriveRepositoryConnector.java Wed Jun 5 03:06:17 2013
@@ -717,11 +717,11 @@ public class GoogleDriveRepositoryConnec
}
getSession();
- XThreadStringBuffer seedBuffer = new XThreadStringBuffer();
- GetSeedsThread t = new GetSeedsThread(googleDriveQuery, seedBuffer);
+ GetSeedsThread t = new GetSeedsThread(googleDriveQuery);
try {
t.start();
try {
+ XThreadStringBuffer seedBuffer = t.getBuffer();
// Pick up the paths, and add them to the activities, before we join with the child thread.
while (true) {
// The only kind of exceptions this can throw are going to shut the process down.
@@ -732,11 +732,8 @@ public class GoogleDriveRepositoryConnec
activities.addSeedDocument(docPath);
}
} finally {
- t.abort();
+ t.finishUp();
}
-
- t.finishUp();
-
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
@@ -760,10 +757,10 @@ public class GoogleDriveRepositoryConnec
protected final String googleDriveQuery;
protected final XThreadStringBuffer seedBuffer;
- public GetSeedsThread(String googleDriveQuery, XThreadStringBuffer seedBuffer) {
+ public GetSeedsThread(String googleDriveQuery) {
super();
this.googleDriveQuery = googleDriveQuery;
- this.seedBuffer = seedBuffer;
+ this.seedBuffer = new XThreadStringBuffer();
setDaemon(true);
}
@@ -776,12 +773,13 @@ public class GoogleDriveRepositoryConnec
}
}
- public void abort() {
- seedBuffer.abandon();
+ public XThreadStringBuffer getBuffer() {
+ return seedBuffer;
}
public void finishUp()
throws InterruptedException, IOException {
+ seedBuffer.abandon();
join();
Throwable thr = exception;
if (thr != null) {
@@ -926,11 +924,11 @@ public class GoogleDriveRepositoryConnec
// adding all the children + subdirs for a folder
getSession();
- XThreadStringBuffer childBuffer = new XThreadStringBuffer();
- GetChildrenThread t = new GetChildrenThread(nodeId, childBuffer);
+ GetChildrenThread t = new GetChildrenThread(nodeId);
try {
t.start();
try {
+ XThreadStringBuffer childBuffer = t.getBuffer();
// Pick up the paths, and add them to the activities, before we join with the child thread.
while (true) {
// The only kind of exceptions this can throw are going to shut the process down.
@@ -941,9 +939,8 @@ public class GoogleDriveRepositoryConnec
activities.addDocumentReference(child, nodeId, RELATIONSHIP_CHILD);
}
} finally {
- t.abort();
+ t.finishUp();
}
- t.finishUp();
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
@@ -1015,10 +1012,8 @@ public class GoogleDriveRepositoryConnec
is.close();
}
} finally {
- t.abort();
+ t.finishUp();
}
-
- t.finishUp();
// No errors. Record the fact that we made it.
errorCode = "OK";
@@ -1076,18 +1071,14 @@ public class GoogleDriveRepositoryConnec
return stream;
}
- public void abort()
+ public void finishUp()
+ throws InterruptedException, IOException
{
// This will be called during the finally
// block in the case where all is well (and
// the stream completed) and in the case where
// there were exceptions.
stream.abort();
- }
-
- public void finishUp()
- throws InterruptedException, IOException
- {
join();
Throwable thr = exception;
if (thr != null) {
@@ -1120,10 +1111,10 @@ public class GoogleDriveRepositoryConnec
protected final String nodeId;
protected final XThreadStringBuffer childBuffer;
- public GetChildrenThread(String nodeId, XThreadStringBuffer childBuffer) {
+ public GetChildrenThread(String nodeId) {
super();
this.nodeId = nodeId;
- this.childBuffer = childBuffer;
+ this.childBuffer = new XThreadStringBuffer();
setDaemon(true);
}
@@ -1136,12 +1127,13 @@ public class GoogleDriveRepositoryConnec
}
}
- public void abort() {
- childBuffer.abandon();
+ public XThreadStringBuffer getBuffer() {
+ return childBuffer;
}
public void finishUp()
throws InterruptedException, IOException {
+ childBuffer.abandon();
join();
Throwable thr = exception;
if (thr != null) {