/**
  * Performs a reconnect with plugin plg.
  *
  * @param retry
  * @param plg
  * @return
  * @throws InterruptedException
  * @throws ReconnectException
  */
 protected final boolean doReconnect(final RouterPlugin plg, LogSource logger)
     throws InterruptedException, ReconnectException {
   final int waittime = Math.max(this.getWaittimeBeforeFirstIPCheck(), 0);
   // make sure that we have the current ip
   logger.info("IP Before=" + IPController.getInstance().getIP());
   try {
     final ReconnectInvoker invoker = plg.getReconnectInvoker();
     if (invoker == null) {
       throw new ReconnectException(
           "Reconnect Plugin  \"" + plg.getName() + "\" is not set up correctly. Invoker==null");
     }
     invoker.setLogger(logger);
     invoker.run();
     logger.finer("Initial Waittime: " + waittime + " seconds");
     Thread.sleep(waittime * 1000);
     return IPController.getInstance()
         .validateAndWait(
             this.getWaitForIPTime(),
             Math.max(0, storage.getSecondsToWaitForOffline()),
             this.getIpCheckInterval());
   } catch (RuntimeException e) {
     logger.log(e);
     throw new ReconnectException(e);
   } finally {
     logger.info("IP AFTER=" + IPController.getInstance().getIP());
   }
 }
예제 #2
0
    protected ReconnectResult validate(ReconnectResult ret) throws InterruptedException, ReconnectException {
        ret.setInvoker(this);

        // Make sure that we are online

        if (IPController.getInstance().getIpState().isOffline()) {
            IPController.getInstance().invalidate();
            Thread.sleep(1000);
            IPController.getInstance().validate();
            if (IPController.getInstance().getIpState().isOffline()) {
                throw new ReconnectException(_GUI._.ReconnectInvoker_validate_offline_());
            }

        }
        logger.info("IP BEFORE=" + IPController.getInstance().getIP());

        try {
            IPController.getInstance().invalidate();
            ret.setStartTime(System.currentTimeMillis());
            testRun();
            Thread.sleep(1 * 1000);
            IPController ipc = IPController.getInstance();
            if (ipc.validate()) {
                // wow this hsa been fast
                logger.info("Successful: REconnect has been very fast!");
                ret.setSuccess(true);
                ret.setOfflineTime(System.currentTimeMillis());
                ret.setSuccessTime(System.currentTimeMillis());
                return ret;
            }
            logger.info("Script done. Wait for offline");
            do {
                // wait until we are offline
                Thread.sleep(1 * 1000);
                if (!ipc.validate() && !ipc.getIpState().isOffline() && (System.currentTimeMillis() - ret.getStartTime()) > OFFLINE_TIMEOUT) {
                    // we are not offline after 30 seconds
                    logger.info("Disconnect failed. Still online after " + OFFLINE_TIMEOUT + " ms");
                    return ret;
                }
            } while (!ipc.getIpState().isOffline() && ipc.isInvalidated());
            ret.setOfflineTime(System.currentTimeMillis());
            logger.info("Offline after " + ret.getOfflineDuration() + " ms");
            if (ipc.isInvalidated()) {
                logger.info("Wait for online status");
                // we have to wait LOOOONG here. reboot may take its time
                final long endTime = System.currentTimeMillis() + 450 * 1000;
                while (System.currentTimeMillis() < endTime) {
                    /* ip change detected then we can stop */
                    long s = System.currentTimeMillis();
                    if (Thread.currentThread().isInterrupted()) {
                        throw new InterruptedException();
                    }
                    if (ipc.validate()) {
                        ret.setSuccessTime(System.currentTimeMillis());
                        ret.setSuccess(true);
                        logger.info("Successful: REconnect after " + ret.getSuccessDuration() + " ms");

                        return ret;
                        //
                    }
                    if (!ipc.getIpState().isOffline()) {
                        logger.info("Failed. returned from offline. But no new ip");
                        return ret;

                    }

                    Thread.sleep(Math.max(0, 1000 - (System.currentTimeMillis() - s)));
                }
                logger.info("Connect failed! Maybe router restart is required. This should NEVER happen!");
                return ret;
            } else {
                ret.setSuccessTime(System.currentTimeMillis());
                ret.setSuccess(true);
                logger.info("Successful: REconnect after " + ret.getSuccessDuration() + " ms");
                return ret;
            }
        } finally {
            logger.info("IP AFTER=" + IPController.getInstance().getIP());
        }
    }
예제 #3
0
    public static String getReplacement(final String key, final DownloadLink dLink) {

        if (key.startsWith("LAST_FINISHED_") && dLink == null) { return ""; }

        if (key.equalsIgnoreCase("LAST_FINISHED_PACKAGE.PASSWORD")) { return dLink.getFilePackage().getPassword(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_PACKAGE.AUTO_PASSWORD")) { return dLink.getFilePackage().getPasswordAuto().toString(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_PACKAGE.FILELIST")) { return dLink.getFilePackage().getDownloadLinkList().toString(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_PACKAGE.PACKAGENAME")) {
            final String name = dLink.getFilePackage().getName();
            if (name == null || name.equals("") || name.equals(_JDT._.controller_packages_defaultname())) {
                return dLink.getName();
            } else {
                return dLink.getFilePackage().getName();
            }
        }

        if (key.equalsIgnoreCase("LAST_FINISHED_PACKAGE.COMMENT")) { return dLink.getFilePackage().getComment(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_PACKAGE.DOWNLOAD_DIRECTORY")) { return dLink.getFilePackage().getDownloadDirectory(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_FILE.DOWNLOAD_PATH")) { return dLink.getFileOutput(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_FILE.HOST")) { return dLink.getHost(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_FILE.NAME")) { return dLink.getName(); }

        if (key.equalsIgnoreCase("LAST_FINISHED_FILE.FILESIZE")) { return dLink.getDownloadSize() + ""; }

        if (key.equalsIgnoreCase("LAST_FINISHED_FILE.AVAILABLE")) { return dLink.isAvailable() ? "YES" : "NO"; }

        if (key.equals("LAST_FINISHED_FILE.BROWSER_URL")) { return dLink.getBrowserUrl(); }

        if (key.equals("LAST_FINISHED_FILE.DOWNLOAD_URL")) { return dLink.getLinkType() == DownloadLink.LINKTYPE_CONTAINER ? "[Not allowed]" : dLink.getDownloadURL(); }

        if (key.equals("LAST_FINISHED_FILE.CHECKSUM")) {
            final StringBuilder sb = new StringBuilder();
            if (dLink.getSha1Hash() != null) {
                sb.append("SHA1: ").append(dLink.getSha1Hash());
            }
            if (dLink.getMD5Hash() != null) {
                if (sb.length() > 0) {
                    sb.append(' ');
                }
                sb.append("MD5: ").append(dLink.getMD5Hash());
            }
            if (sb.length() > 0) { return sb.toString(); }
            return "[Not set]";
        }

        if (key.equalsIgnoreCase("SYSTEM.IP")) {
            if (JSonWrapper.get("DOWNLOAD").getBooleanProperty(Configuration.PARAM_GLOBAL_IP_DISABLE, false)) {
                return "IPCheck disabled";
            } else {
                return IPController.getInstance().getIP().toString();
            }
        }

        if (key.equalsIgnoreCase("SYSTEM.DATE")) {
            final Calendar c = Calendar.getInstance();
            return Formatter.fillInteger(c.get(Calendar.DATE), 2, "0") + "." + Formatter.fillInteger((c.get(Calendar.MONTH) + 1), 2, "0") + "." + c.get(Calendar.YEAR);
        }

        if (key.equalsIgnoreCase("SYSTEM.TIME")) {
            final Calendar c = Calendar.getInstance();
            return Formatter.fillInteger(c.get(Calendar.HOUR_OF_DAY), 2, "0") + ":" + Formatter.fillInteger(c.get(Calendar.MINUTE), 2, "0") + ":" + Formatter.fillInteger(c.get(Calendar.SECOND), 2, "0");
        }

        if (key.equalsIgnoreCase("SYSTEM.JAVA_VERSION")) { return Application.getJavaVersion() + ""; }

        if (key.equalsIgnoreCase("JD.REVISION")) { return JDUtilities.getRevision(); }

        if (key.equalsIgnoreCase("JD.HOME_DIR")) { return JDUtilities.getJDHomeDirectoryFromEnvironment().getAbsolutePath(); }

        return "";
    }