private void load(String pkg) { try { URL infourl = Application.getRessourceURL(JD_CONTROLLING_RECONNECT_PLUGINS + pkg + "/info.json"); if (infourl == null) { LogController.CL().finer("Could not load Reconnect Plugin " + pkg); return; } ReconnectPluginInfo plgInfo = JSonStorage.restoreFromString( IO.readURLToString(infourl), new TypeRef<ReconnectPluginInfo>() {}, null); if (plgInfo == null) { LogController.CL().finer("Could not load Reconnect Plugin (no info.json)" + pkg); return; } Class<?> clazz = getClass() .getClassLoader() .loadClass( JD_CONTROLLING_RECONNECT_PLUGINS.replace("/", ".") + pkg + "." + plgInfo.getClassName()); for (RouterPlugin plg : plugins) { if (plg.getClass() == clazz) { LogController.CL().finer("Dupe found: " + pkg); return; } } plugins.add((RouterPlugin) clazz.newInstance()); } catch (Throwable e) { LogController.CL().log(e); } }
/** * 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()); } }
/** Returns the plugin that has the given ID. */ public RouterPlugin getPluginByID(final String activeID) { for (final RouterPlugin plg : this.plugins) { if (plg.getID().equals(activeID)) { return plg; } } return null; }
/** * returns the currently active routerplugin. Only one plugin may be active * * @return */ public RouterPlugin getActivePlugin() { // convert only once String id = storage.getActivePluginID(); if (id == null) { id = this.convertFromOldSystem(); this.storage.setActivePluginID(id); } RouterPlugin active = ReconnectPluginController.getInstance().getPluginByID(id); if (active == null) { active = DummyRouterPlugin.getInstance(); this.storage.setActivePluginID(active.getID()); } return active; }
public java.util.List<ReconnectResult> autoFind(final ProcessCallBack feedback) throws InterruptedException { StatsManager.I().track("reconnectAutoFind/start"); final java.util.List<ReconnectResult> scripts = new ArrayList<ReconnectResult>(); for (final RouterPlugin plg : ReconnectPluginController.this.plugins) { if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } if (plg instanceof UPNPRouterPlugin || plg instanceof LiveHeaderReconnect) { try { feedback.setStatus(plg, null); java.util.List<ReconnectResult> founds = plg.runDetectionWizard(feedback); if (founds != null) { scripts.addAll(founds); } if (scripts.size() > 0) { break; } } catch (InterruptedException e) { throw e; } catch (Exception e) { } } } if (scripts.size() > 0) { HashMap<String, String> map = new HashMap<String, String>(); map.put("plg", scripts.get(0).getInvoker().getPlugin().getID()); StatsManager.I().track("reconnectAutoFind/success", map); } else { StatsManager.I().track("reconnectAutoFind/failed"); } if (JsonConfig.create(ReconnectConfig.class).getOptimizationRounds() > 1 && scripts.size() > 0) { int i = 1; long bestTime = Long.MAX_VALUE; long optiduration = 0; for (ReconnectResult found : scripts) { bestTime = Math.min(bestTime, found.getSuccessDuration()); optiduration += found.getSuccessDuration() * (JsonConfig.create(ReconnectConfig.class).getOptimizationRounds() - 1) * 1.5; } try { Dialog.getInstance() .showConfirmDialog( 0, _GUI.T.AutoDetectAction_actionPerformed_dooptimization_title(), _GUI.T.AutoDetectAction_actionPerformed_dooptimization_msg( scripts.size(), TimeFormatter.formatMilliSeconds(optiduration, 0), TimeFormatter.formatMilliSeconds(bestTime, 0)), new AbstractIcon(IconKey.ICON_OK, 32), _GUI.T.AutoDetectAction_run_optimization(), _GUI.T.AutoDetectAction_skip_optimization()); feedback.setProgress(this, 0); for (int ii = 0; ii < scripts.size(); ii++) { ReconnectResult found = scripts.get(ii); feedback.setStatusString( this, _GUI.T.AutoDetectAction_run_optimize(found.getInvoker().getName())); final int step = ii; found.optimize( new ProcessCallBackAdapter() { public void setProgress(Object caller, int percent) { feedback.setProgress( caller, (step) * (100 / scripts.size()) + percent / scripts.size()); } public void setStatusString(Object caller, String string) { feedback.setStatusString(caller, _GUI.T.AutoDetectAction_run_optimize(string)); } }); } } catch (DialogNoAnswerException e) { } } try { Collections.sort( scripts, new Comparator<ReconnectResult>() { public int compare(ReconnectResult o1, ReconnectResult o2) { return new Long(o1.getAverageSuccessDuration()) .compareTo(new Long(o2.getAverageSuccessDuration())); } }); } catch (final Throwable e) { org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger().log(e); } return scripts; }
/** * Sets the active reconnect plugin * * @param selectedItem */ public void setActivePlugin(final RouterPlugin selectedItem) { this.storage.setActivePluginID(selectedItem.getID()); }