projects
/
jSite.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add possibility to stop a running insert.
[jSite.git]
/
src
/
de
/
todesbaum
/
jsite
/
application
/
ProjectInserter.java
diff --git
a/src/de/todesbaum/jsite/application/ProjectInserter.java
b/src/de/todesbaum/jsite/application/ProjectInserter.java
index
32c9c5b
..
756e121
100644
(file)
--- a/
src/de/todesbaum/jsite/application/ProjectInserter.java
+++ b/
src/de/todesbaum/jsite/application/ProjectInserter.java
@@
-88,6
+88,12
@@
public class ProjectInserter implements FileScannerListener, Runnable {
/** The temp directory. */
private String tempDirectory;
/** The temp directory. */
private String tempDirectory;
+ /** The current connection. */
+ private Connection connection;
+
+ /** Whether the insert is cancelled. */
+ private volatile boolean cancelled = false;
+
/**
* Adds a listener to the list of registered listeners.
*
/**
* Adds a listener to the list of registered listeners.
*
@@
-217,12
+223,25
@@
public class ProjectInserter implements FileScannerListener, Runnable {
* Starts the insert.
*/
public void start() {
* Starts the insert.
*/
public void start() {
+ cancelled = false;
fileScanner = new FileScanner(project);
fileScanner.addFileScannerListener(this);
new Thread(fileScanner).start();
}
/**
fileScanner = new FileScanner(project);
fileScanner.addFileScannerListener(this);
new Thread(fileScanner).start();
}
/**
+ * Stops the current insert.
+ */
+ public void stop() {
+ cancelled = true;
+ synchronized (lockObject) {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
* Creates an input stream that delivers the given file, replacing edition
* tokens in the file’s content, if necessary.
*
* Creates an input stream that delivers the given file, replacing edition
* tokens in the file’s content, if necessary.
*
@@
-462,7
+481,9
@@
public class ProjectInserter implements FileScannerListener, Runnable {
List<String> files = fileScanner.getFiles();
/* create connection to node */
List<String> files = fileScanner.getFiles();
/* create connection to node */
- Connection connection = freenetInterface.getConnection("project-insert-" + random + counter++);
+ synchronized (lockObject) {
+ connection = freenetInterface.getConnection("project-insert-" + random + counter++);
+ }
connection.setTempDirectory(tempDirectory);
boolean connected = false;
Throwable cause = null;
connection.setTempDirectory(tempDirectory);
boolean connected = false;
Throwable cause = null;
@@
-472,8
+493,8
@@
public class ProjectInserter implements FileScannerListener, Runnable {
cause = e1;
}
cause = e1;
}
- if (!connected) {
- fireProjectInsertFinished(false, cause);
+ if (!connected
|| cancelled
) {
+ fireProjectInsertFinished(false, ca
ncelled ? new AbortedException() : ca
use);
return;
}
return;
}
@@
-520,7
+541,7
@@
public class ProjectInserter implements FileScannerListener, Runnable {
boolean success = false;
boolean finished = false;
boolean disconnected = false;
boolean success = false;
boolean finished = false;
boolean disconnected = false;
- while (!finished) {
+ while (!finished
&& !cancelled
) {
Message message = client.readMessage();
finished = (message == null) || (disconnected = client.isDisconnected());
if (firstMessage) {
Message message = client.readMessage();
finished = (message == null) || (disconnected = client.isDisconnected());
if (firstMessage) {
@@
-556,7
+577,7
@@
public class ProjectInserter implements FileScannerListener, Runnable {
project.setEdition(newEdition);
project.setLastInsertionTime(System.currentTimeMillis());
}
project.setEdition(newEdition);
project.setLastInsertionTime(System.currentTimeMillis());
}
- fireProjectInsertFinished(success,
disconnected ? new IOException("Connection terminated") : null
);
+ fireProjectInsertFinished(success,
cancelled ? new AbortedException() : (disconnected ? new IOException("Connection terminated") : null)
);
}
//
}
//