コード例 #1
0
  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);
    }
  }
コード例 #2
0
  /**
   * Create a new i nstance of AuthenticationController. This is a singleton class. Access the only
   * existing instance by using {@link #getInstance()}.
   */
  private AuthenticationController() {
    logger = LogController.getInstance().getLogger(AuthenticationController.class.getName());
    config = JsonConfig.create(AuthenticationControllerSettings.class);
    CopyOnWriteArrayList<AuthenticationInfo> list = cleanup(config.getList());
    if (list == null) {
      list = new CopyOnWriteArrayList<AuthenticationInfo>();
    }
    this.list = list;
    ShutdownController.getInstance()
        .addShutdownEvent(
            new ShutdownEvent() {
              @Override
              public void onShutdown(final ShutdownRequest shutdownRequest) {
                config.setList(AuthenticationController.this.list);
              }

              @Override
              public long getMaxDuration() {
                return 0;
              }

              @Override
              public String toString() {
                return "ShutdownEvent: Save AuthController";
              }
            });
  }
コード例 #3
0
    /**
     * Create a new instance of RecollController. This is a singleton class. Access the only existing instance by using
     * {@link #getInstance()}.
     */
    private RecollController() {

        logger = LogController.getInstance().getLogger(getClass().getName());

        queue = new Queue("RecollQueue") {

        };

    }
コード例 #4
0
 public void errLog(Throwable e, Browser br, CrawledLink link) {
   LogSource errlogger = LogController.getInstance().getLogger("PluginErrors");
   try {
     errlogger.severe("CrawlerPlugin out of date: " + this + " :" + getVersion());
     errlogger.severe("URL was: " + link.getURL());
     if (e != null) {
       errlogger.log(e);
     }
   } finally {
     errlogger.close();
   }
 }
コード例 #5
0
 ExtractionController(
     ExtractionExtension extractionExtension, Archive archiv, IExtraction extractor) {
   this.archive = archiv;
   logger = LogController.CL(false);
   logger.setAllowTimeoutFlush(false);
   logger.info("Extraction of" + archive);
   this.extractor = extractor;
   extractionProgress = new ExtractionProgress(this, 0, 0, null);
   extractor.setArchiv(archiv);
   extractor.setExtractionController(this);
   extension = extractionExtension;
   extractor.setLogger(logger);
   passwordList = new CopyOnWriteArrayList<String>();
   archive.onControllerAssigned(this);
 }
コード例 #6
0
  protected AbstractStreamFactory() {
    logger = LogController.getInstance().getLogger(getClass().getName());
    exceptions = new ArrayList<Throwable>();
    this.closer =
        new DelayedRunnable(EXECUTER, 5 * 1000l) {
          @Override
          public void delayedrun() {
            synchronized (activeStreams) {
              if (activeStreams.size() > 0) return;
              System.out.println("CLOSED " + AbstractStreamFactory.this);

              close();
            }
          }
        };
  }
コード例 #7
0
 private void save(List<LazyHostPlugin> save, final AtomicLong lastFolderModification) {
   if (save != null) {
     LOCK.writeLock();
     final File cache = Application.getTempResource(getCache());
     try {
       LazyHostPluginCache.write(save, cache, lastFolderModification);
     } catch (final Throwable e) {
       final LogSource log = LogController.CL(false);
       log.log(e);
       log.close();
       cache.delete();
     } finally {
       LOCK.writeUnlock();
       FileCreationManager.getInstance()
           .delete(Application.getTempResource(TMP_INVALIDPLUGINS), null);
     }
   }
 }
コード例 #8
0
ファイル: LinkInfo.java プロジェクト: amicom/my-project
  public static Icon getIcon(final String name, final ExtensionsFilterInterface extension) {
    Icon newIcon = null;
    final String ext = Files.getExtension(name);
    if (CrossSystem.isWindows() && ext != null) {
      try {
        newIcon = CrossSystem.getMime().getFileIcon(ext, 16, 16);

      } catch (Throwable e) {
        LogController.CL().log(e);
      }
    }
    if (newIcon == null) {
      String iconID = null;
      if (extension != null && extension.getIconID() != null) {
        iconID = extension.getIconID();
      }
      if (StringUtils.isEmpty(iconID)) {
        iconID = "file";
      }
      newIcon = NewTheme.I().getIcon(iconID, 16);
    }
    return newIcon;
  }
コード例 #9
0
ファイル: Circle.java プロジェクト: sn0w/jdownloader
  private void addCircles(PixelObject pixelObject, java.util.List<PixelObject> obnew) {
    if (pixelObject.getArea() < minArea) {
      return;
    }
    int[] bounds = getBounds(pixelObject);
    int r = 0;
    if (bounds != null) {
      r = (bounds[1] - pixelObject.getLocation()[1]) / 2;

      // System.out.println(r + ":" + bounds[0] + ":" + bounds[1]);
      // System.out.println(pixelObject.getHeight() / 2);

      PixelObject object = getCircle(bounds[0], bounds[1] - r, r);

      if (object != null) {
        int ratio = object.getHeight() * 100 / object.getWidth();
        // BasicWindow.showImage(object.toColoredLetter().getImage(),""+ratio);

        if (ratio > 90 && ratio < 110) {
          obnew.add(object);
          int oldArea = pixelObject.getArea();
          // BasicWindow.showImage(object.toColoredLetter().getImage(),""+pixelObject.getArea());

          pixelObject.del(object);

          if (oldArea != pixelObject.getArea()) {
            addCircles(pixelObject, obnew);
          }
        }
      }
    } else {
      LogController.CL().warning("can not detect circle bounds");
      // BasicWindow.showImage(pixelObject.toColoredLetter().getImage(),""+pixelObject.getArea());

    }
  }
コード例 #10
0
  /** Scans for reconnection plugins */
  private void scan() {
    try {
      final File[] files =
          JDUtilities.getResourceFile("reconnect")
              .listFiles(new JDFileFilter(null, ".reconnect", false));
      this.plugins = new ArrayList<RouterPlugin>();
      this.plugins.add(DummyRouterPlugin.getInstance());
      plugins.add(new ExternBatchReconnectPlugin());
      plugins.add(new ExternReconnectPlugin());
      plugins.add(new UPNPRouterPlugin());
      plugins.add(new LiveHeaderReconnect());
      plugins.add(new SpeedPortHybrid());
      plugins.add(new EasyBox804());
      final java.util.List<URL> urls = new ArrayList<URL>();
      if (files != null) {
        final int length = files.length;

        for (int i = 0; i < length; i++) {
          try {
            urls.add(files[i].toURI().toURL());
            Application.addUrlToClassPath(files[i].toURI().toURL(), getClass().getClassLoader());
          } catch (final Throwable e) {
            LogController.CL().log(e);
          }
        }
      }

      Enumeration<URL> found =
          getClass()
              .getClassLoader()
              .getResources(ReconnectPluginController.JD_CONTROLLING_RECONNECT_PLUGINS);
      Pattern pattern =
          Pattern.compile(Pattern.quote(JD_CONTROLLING_RECONNECT_PLUGINS) + "(\\w+)/");
      while (found.hasMoreElements()) {
        URL url = found.nextElement();

        if (url.getProtocol().equalsIgnoreCase("jar")) {
          // // jarred addon (JAR)
          String path = url.getPath();
          File jarFile = new File(new URL(path.substring(0, path.lastIndexOf('!'))).toURI());
          JarInputStream jis = null;
          try {
            jis = new JarInputStream(new FileInputStream(jarFile));
            JarEntry e;

            while ((e = jis.getNextJarEntry()) != null) {

              // try {
              Matcher matcher = pattern.matcher(e.getName());
              while (matcher.find()) {
                try {
                  String pkg = matcher.group(1);
                  load(pkg);

                  System.out.println(pkg);
                } catch (Exception e1) {
                  e1.printStackTrace();
                }
              }
            }
          } finally {
            try {
              jis.close();
            } catch (final Throwable e) {
            }
          }
        } else {

          for (File dir :
              new File(url.toURI())
                  .listFiles(
                      new FileFilter() {

                        public boolean accept(File pathname) {
                          return pathname.isDirectory();
                        }
                      })) {
            File file = new File(dir, "info.json");
            if (file.exists()) {
              load(dir.getName());
            }
          }
          //
        }
      }
    } catch (Throwable e) {
      LogController.CL().log(e);
    }
  }
コード例 #11
0
  public synchronized Map<String, LazyHostPlugin> init() {
    final LogSource logger = LogController.CL(false);
    logger.info("HostPluginController: init");
    logger.setAllowTimeoutFlush(false);
    logger.setAutoFlushOnThrowable(true);
    LogController.setRebirthLogger(logger);
    final long completeTimeStamp = System.currentTimeMillis();
    try {
      /* try to load from cache */
      long timeStamp = System.currentTimeMillis();
      if (lastKnownPlugins == null || lastModification.get() <= 0) {
        try {
          lastKnownPlugins = loadFromCache(lastModification);
        } catch (Throwable e) {
          if (lastModification != null) {
            lastModification.set(-1l);
          }
          logger.log(e);
          logger.severe("@HostPluginController: cache failed!");
        } finally {
          if (lastKnownPlugins != null && lastKnownPlugins.size() > 0) {
            logger.info(
                "@HostPluginController: loadFromCache took "
                    + (System.currentTimeMillis() - timeStamp)
                    + "ms for "
                    + lastKnownPlugins.size());
          }
        }
      }
      List<LazyHostPlugin> plugins = null;
      timeStamp = System.currentTimeMillis();
      try {
        /* do a fresh scan */
        plugins = update(logger, lastKnownPlugins, lastModification);
      } catch (Throwable e) {
        if (lastModification != null) {
          lastModification.set(-1l);
        }
        logger.log(e);
        logger.severe("@HostPluginController: update failed!");
      } finally {
        if (plugins != null && plugins.size() > 0) {
          logger.info(
              "@HostPluginController: update took "
                  + (System.currentTimeMillis() - timeStamp)
                  + "ms for "
                  + plugins.size());
        }
      }
      if (plugins == null || plugins.size() == 0) {
        if (plugins == null) {
          plugins = new ArrayList<LazyHostPlugin>();
        }
        logger.severe("@HostPluginController: WTF, no plugins!");
      }
      lastKnownPlugins = new ArrayList<LazyHostPlugin>(plugins);
      timeStamp = System.currentTimeMillis();
      try {
        if (false) {
          Collections.sort(
              plugins,
              new Comparator<LazyHostPlugin>() {
                public final boolean smallestCharacter(char a, char b) {
                  return Character.toLowerCase(a) < Character.toLowerCase(b);
                }

                public int compare(LazyHostPlugin o1, LazyHostPlugin o2) {
                  char a = o1.getDisplayName().charAt(0);
                  char b = o2.getDisplayName().charAt(0);
                  if (a == b) {
                    return 0;
                  }
                  return smallestCharacter(a, b) ? -1 : 1;
                }
              });
        } else {
          Collections.sort(
              plugins,
              new Comparator<LazyHostPlugin>() {

                public int compare(LazyHostPlugin o1, LazyHostPlugin o2) {
                  return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
              });
        }
      } catch (final Throwable e) {
        logger.log(e);
        logger.severe("@HostPluginController: sort failed!");
      } finally {
        logger.info(
            "@HostPluginController: sort took "
                + (System.currentTimeMillis() - timeStamp)
                + "ms for "
                + plugins.size());
      }
      timeStamp = System.currentTimeMillis();
      final LinkedHashMap<String, LazyHostPlugin> retMap =
          new LinkedHashMap<String, LazyHostPlugin>();
      LazyHostPlugin fallBackPlugin = null;
      for (final LazyHostPlugin plugin : plugins) {
        plugin.setPluginClass(null);
        plugin.setClassLoader(null);
        if (fallBackPlugin == null && "UpdateRequired".equalsIgnoreCase(plugin.getDisplayName())) {
          fallBackPlugin = plugin;
          this.fallBackPlugin = plugin;
          continue;
        }
        final String pluginID = plugin.getDisplayName().toLowerCase(Locale.ENGLISH);
        final LazyHostPlugin existingPlugin = retMap.put(pluginID, plugin);
        if (existingPlugin != null) {
          if (existingPlugin.getLazyPluginClass().getInterfaceVersion()
              > plugin.getLazyPluginClass().getInterfaceVersion()) {
            retMap.put(pluginID, existingPlugin);
            // logger.finest("@HostPlugin keep:" + existingPlugin.getLazyPluginClass() + ":" +
            // existingPlugin.getVersion() +
            // " instead " + plugin.getLazyPluginClass() + ":" + plugin.getVersion());
          } else {
            // logger.finest("@HostPlugin replaced:" + existingPlugin.getLazyPluginClass() + ":" +
            // existingPlugin.getVersion() +
            // " with " + plugin.getLazyPluginClass() + ":" + plugin.getVersion());
          }
        }
      }
      logger.info(
          "@HostPluginController: mapping took "
              + (System.currentTimeMillis() - timeStamp)
              + "ms for "
              + plugins.size());
      list = retMap;
    } finally {
      final Map<String, LazyHostPlugin> llist = list;
      if (llist != null) {
        logger.info(
            "@HostPluginController: init took "
                + (System.currentTimeMillis() - completeTimeStamp)
                + "ms for "
                + llist.size());
      } else {
        logger.info(
            "@HostPluginController: init took " + (System.currentTimeMillis() - completeTimeStamp));
      }
      LogController.setRebirthLogger(null);
      validateCache();
      final List<LazyHostPlugin> lLastKnownPlugins = lastKnownPlugins;
      if (lLastKnownPlugins != null) {
        final AtomicLong lastModification = new AtomicLong(this.lastModification.get());
        final Thread saveThread =
            new Thread("@HostPluginController:save") {
              public void run() {
                save(lLastKnownPlugins, lastModification);
              };
            };
        saveThread.setDaemon(true);
        saveThread.start();
      }
      logger.close();
      System.gc();
    }
    if (SecondLevelLaunch.HOST_PLUGINS_COMPLETE.isReached()) {
      SecondLevelLaunch.INIT_COMPLETE.executeWhenReached(
          new Runnable() {

            @Override
            public void run() {
              TaskQueue.getQueue()
                  .add(
                      new QueueAction<Void, RuntimeException>() {

                        @Override
                        protected Void run() throws RuntimeException {
                          LinkCollector.getInstance().checkPluginUpdates();
                          DownloadController.getInstance().checkPluginUpdates();
                          AccountController.getInstance().checkPluginUpdates();
                          HosterRuleController.getInstance().checkPluginUpdates();
                          return null;
                        }
                      });
            }
          });
    }
    return list;
  }
コード例 #12
0
 /**
  * Create a new instance of ChallengeResponseController. This is a singleton class. Access the
  * only existing instance by using {@link #getInstance()}.
  */
 private ChallengeResponseController() {
   logger = LogController.getInstance().getLogger(getClass().getName());
   eventSender = new ChallengeResponseEventSender(logger);
 }
コード例 #13
0
 public <T> SolverJob<T> handle(final Challenge<T> c) throws InterruptedException, SkipException {
   LogSource logger = LogController.getInstance().getPreviousThreadLogSource();
   if (logger == null) {
     logger = this.logger;
   }
   logger.info("Log to " + logger.getName());
   logger.info("Handle Challenge: " + c);
   final ArrayList<ChallengeSolver<T>> solver = createList(c);
   logger.info("Solver: " + solver);
   if (solver.size() == 0) {
     logger.info("No solver available!");
     throw new SkipException(SkipRequest.BLOCK_HOSTER);
   }
   final SolverJob<T> job = new SolverJob<T>(this, c, solver);
   job.setLogger(logger);
   final Plugin plugin = c.getPlugin();
   if (plugin != null) {
     if (plugin instanceof PluginForHost) {
       ((PluginForHost) plugin).setLastSolverJob(job);
     } else if (plugin instanceof PluginForDecrypt) {
       ((PluginForDecrypt) plugin).setLastSolverJob(job);
     }
   }
   final UniqueAlltimeID jobID = c.getId();
   synchronized (activeJobs) {
     activeJobs.add(job);
     idToJobMap.put(jobID, job);
   }
   try {
     for (final ChallengeSolver<T> cs : solver) {
       logger.info("Send to solver: " + cs + " " + job);
       cs.enqueue(job);
     }
     logger.info("Fire New Job Event");
     fireNewJobEvent(job);
     logger.info("Wait");
     while (!job.isSolved() && !job.isDone()) {
       synchronized (job) {
         if (!job.isSolved() && !job.isDone()) {
           job.wait(10000);
         }
       }
     }
     if (job.getSkipRequest() != null) {
       throw new SkipException(job.getSkipRequest());
     }
     final ResponseList<T> response = job.getResponseAndKill();
     logger.info("All Responses: " + job.getResponses());
     logger.info("Solving Done. Result: " + response);
     return job;
   } catch (InterruptedException e) { // for example downloads have been stopped
     job.kill();
     throw e;
   } finally {
     try {
       synchronized (activeJobs) {
         activeJobs.remove(job);
         idToJobMap.remove(jobID);
       }
     } finally {
       fireJobDone(job);
     }
   }
 }