Ejemplo n.º 1
0
 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) {
     }
   }
 }
Ejemplo n.º 2
0
 private void loadOldFiles() {
   File[] files = uploadCtrl.getUploadPackages();
   if (files == null) {
     return;
   }
   for (File file : files) {
     fileCreated(file);
   }
 }
Ejemplo n.º 3
0
 public UploadThread(UploadController controller) {
   super("Docear Upload-Thread");
   uploadCtrl = controller;
   uploadCtrl.addUploadDirectoryObserver(this);
   loadOldFiles();
 }