예제 #1
0
  public void run() {
    // each file is processed into a local hash table and then merged with the global results
    // this will cause much less contention on the global table, but still avoids a sequential
    // update
    Hashtable<String, Integer> local_results =
        new Hashtable<String, Integer>(WordCountJ.HASH_SIZE, WordCountJ.LF);
    // grab a file to work on
    String cf;
    while ((cf = files.poll()) != null) {
      try {
        BufferedReader input = new BufferedReader(new FileReader(cf));
        String text;
        // well go line-by-line... maybe this is not the fastest
        while ((text = input.readLine()) != null) {
          // parse words
          Matcher matcher = pattern.matcher(text);
          while (matcher.find()) {
            String word = matcher.group(1);
            if (local_results.containsKey(word)) {
              local_results.put(word, 1 + local_results.get(word));
            } else {
              local_results.put(word, 1);
            }
          }
        }
        input.close();
      } catch (Exception e) {
        System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
        return;
      }
      // merge local hashmap with shared one,could have a
      // seperate thread do this but that might be cheating

      Iterator<Map.Entry<String, Integer>> updates = local_results.entrySet().iterator();
      while (updates.hasNext()) {
        Map.Entry<String, Integer> kv = updates.next();
        String k = kv.getKey();
        Integer v = kv.getValue();
        synchronized (results) {
          if (results.containsKey(k)) {
            results.put(k, v + results.get(k));
          } else {
            results.put(k, v);
          }
        }
      }
      local_results.clear();
    }
  }
예제 #2
0
  /**
   * The dependent service is available and the bundle will start.
   *
   * @param dependentService the UIService this activator is waiting.
   */
  @Override
  public void start(Object dependentService) {
    if (logger.isDebugEnabled()) logger.debug("Update checker [STARTED]");

    ConfigurationService cfg = getConfiguration();

    if (OSUtils.IS_WINDOWS) {
      updateService = new Update();

      bundleContext.registerService(UpdateService.class.getName(), updateService, null);

      // Register the "Check for Updates" menu item if
      // the "Check for Updates" property isn't disabled.
      if (!cfg.getBoolean(CHECK_FOR_UPDATES_MENU_DISABLED_PROP, false)) {
        // Register the "Check for Updates" menu item.
        CheckForUpdatesMenuItemComponent checkForUpdatesMenuItemComponent =
            new CheckForUpdatesMenuItemComponent(Container.CONTAINER_HELP_MENU);

        Hashtable<String, String> toolsMenuFilter = new Hashtable<String, String>();
        toolsMenuFilter.put(Container.CONTAINER_ID, Container.CONTAINER_HELP_MENU.getID());

        bundleContext.registerService(
            PluginComponent.class.getName(), checkForUpdatesMenuItemComponent, toolsMenuFilter);
      }

      // Check for software update upon startup if enabled.
      if (cfg.getBoolean(UPDATE_ENABLED, true)) updateService.checkForUpdates(false);
    }

    if (cfg.getBoolean(CHECK_FOR_UPDATES_DAILY_ENABLED_PROP, false)) {
      logger.info("Scheduled update checking enabled");

      // Schedule a "check for updates" task that will run once a day
      int hoursToWait = calcHoursToWait();
      Runnable updateRunnable =
          new Runnable() {
            public void run() {
              logger.debug("Performing scheduled update check");
              getUpdateService().checkForUpdates(false);
            }
          };

      mUpdateExecutor = Executors.newSingleThreadScheduledExecutor();
      mUpdateExecutor.scheduleAtFixedRate(
          updateRunnable, hoursToWait, 24 * 60 * 60, TimeUnit.SECONDS);
    }

    if (logger.isDebugEnabled()) logger.debug("Update checker [REGISTERED]");
  }