public void execute() { while (!isTerminated()) { DocearLogger.info(this + " running."); int backupMinutes = uploadCtrl.getUploadInterval(); try { if (uploadCtrl.isBackupAllowed() || uploadCtrl.isInformationRetrievalAllowed()) { DocearLogger.info(this.toString() + ": uploading packages to the server ..."); File[] files; synchronized (uploadFiles) { files = uploadFiles.toArray(new File[] {}); // uploadCtrl.getUploadPackages(); } if (files != null && files.length > 0) { FiletransferClient client = CommunicationsController.getController().getFileTransferClient("mindmaps"); for (File file : files) { // boolean success = // CommunicationsController.getController().postFileToDocearService("mindmaps", file, // true); if (!file.exists()) { fileRemoved(file); continue; } boolean success = false; try { success = client.sendFile(file, true); } catch (Exception e) { DocearLogger.warn( "org.docear.plugin.services.upload.UploadThread.execute() -> sendFile: " + e.getMessage()); } if (success) { DocearLogger.info(this.toString() + ": synchronizing '" + file + "' successfull"); fileRemoved(file); } else { DocearLogger.info(this.toString() + ": synchronizing '" + file + "' failed"); } } } else { DocearLogger.info(this.toString() + ": nothing to do"); } } } catch (Exception e) { DocearLogger.warn( "org.docear.plugin.services.upload.UploadThread.execute(): " + e.getMessage()); } try { if (!isInterrupted()) { sleep(60000 * backupMinutes); } } catch (InterruptedException e) { } } }
private void loadOldFiles() { File[] files = uploadCtrl.getUploadPackages(); if (files == null) { return; } for (File file : files) { fileCreated(file); } }
public UploadThread(UploadController controller) { super("Docear Upload-Thread"); uploadCtrl = controller; uploadCtrl.addUploadDirectoryObserver(this); loadOldFiles(); }