import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
*/
public class ProjectInserter implements FileScannerListener, Runnable {
+ /** The logger. */
+ private static final Logger logger = Logger.getLogger(ProjectInserter.class.getName());
+
/** Random number for FCP instances. */
private static final int random = (int) (Math.random() * Integer.MAX_VALUE);
/** Counter for FCP connection identifier. */
private static int counter = 0;
- /** Whether debug mode is set. */
- private boolean debug = false;
-
/** The list of insert listeners. */
private List<InsertListener> insertListeners = new ArrayList<InsertListener>();
/** Object used for synchronization. */
protected final Object lockObject = new Object();
+ /** The temp directory. */
+ private String tempDirectory;
+
/**
* Adds a listener to the list of registered listeners.
*
/**
* Notifies all listeners that the insert has made some progress.
*
+ * @see InsertListener#projectUploadFinished(Project)
+ */
+ protected void fireProjectUploadFinished() {
+ for (InsertListener insertListener : insertListeners) {
+ insertListener.projectUploadFinished(project);
+ }
+ }
+
+ /**
+ * Notifies all listeners that the insert has made some progress.
+ *
* @see InsertListener#projectInsertProgress(Project, int, int, int, int,
* boolean)
* @param succeeded
}
/**
- * Sets the debug mode.
- *
- * @param debug
- * <code>true</code> to activate debug mode, <code>false</code>
- * to deactivate
- */
- public void setDebug(boolean debug) {
- this.debug = debug;
- }
-
- /**
* Sets the project to insert.
*
* @param project
}
/**
+ * Sets the temp directory to use.
+ *
+ * @param tempDirectory
+ * The temp directory to use, or {@code null} to use the system
+ * default
+ */
+ public void setTempDirectory(String tempDirectory) {
+ this.tempDirectory = tempDirectory;
+ }
+
+ /**
* Starts the insert.
*/
public void start() {
* if an I/O error occurs
*/
private InputStream createContainerInputStream(Map<String, List<String>> containerFiles, String containerName, int edition, long[] containerLength) throws IOException {
- File tempFile = File.createTempFile("jsite", ".zip");
+ File tempFile = File.createTempFile("jsite", ".zip", (tempDirectory == null) ? null : new File(tempDirectory));
tempFile.deleteOnExit();
FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
/* create connection to node */
Connection connection = freenetInterface.getConnection("project-insert-" + random + counter++);
+ connection.setTempDirectory(tempDirectory);
boolean connected = false;
Throwable cause = null;
try {
/* collect files */
int edition = project.getEdition();
String dirURI = "USK@" + project.getInsertURI() + "/" + project.getPath() + "/" + edition + "/";
- ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI);
- putDir.setDefaultName(project.getIndexFile());
+ ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI, tempDirectory);
+ if ((project.getIndexFile() != null) && (project.getIndexFile().length() > 0)) {
+ putDir.setDefaultName(project.getIndexFile());
+ }
putDir.setVerbosity(Verbosity.ALL);
putDir.setMaxRetries(-1);
for (String filename : files) {
/* parse progress and success messages */
String finalURI = null;
+ boolean firstMessage = true;
boolean success = false;
boolean finished = false;
boolean disconnected = false;
while (!finished) {
Message message = client.readMessage();
finished = (message == null) || (disconnected = client.isDisconnected());
- if (debug) {
- System.out.println(message);
+ if (firstMessage) {
+ fireProjectUploadFinished();
+ firstMessage = false;
}
+ logger.log(Level.FINE, "Received message: " + message);
if (!finished) {
@SuppressWarnings("null")
String messageName = message.getName();