コード例 #1
0
 /** Called by org.lockss.config.MiscConfig */
 public static void setConfig(
     Configuration config, Configuration oldConfig, Configuration.Differences diffs) {
   if (diffs.contains(PREFIX)) {
     dirNodeCheckSlash =
         config.getBoolean(PARAM_DIR_NODE_CHECK_SLASH, DEFAULT_DIR_NODE_CHECK_SLASH);
   }
 }
コード例 #2
0
  /** Create LockssKeystore from a config subtree */
  LockssKeyStore createLockssKeyStore(Configuration config) {
    log.debug2("Creating LockssKeyStore from config: " + config);
    String name = config.get(KEYSTORE_PARAM_NAME);
    LockssKeyStore lk = new LockssKeyStore(name);

    String file = config.get(KEYSTORE_PARAM_FILE);
    String resource = config.get(KEYSTORE_PARAM_RESOURCE);
    String url = config.get(KEYSTORE_PARAM_URL);

    if (!StringUtil.isNullString(file)) {
      lk.setLocation(file, LocationType.File);
    } else if (!StringUtil.isNullString(resource)) {
      lk.setLocation(resource, LocationType.Resource);
    } else if (!StringUtil.isNullString(url)) {
      lk.setLocation(url, LocationType.Url);
    }

    lk.setType(config.get(KEYSTORE_PARAM_TYPE, defaultKeyStoreType));
    lk.setProvider(config.get(KEYSTORE_PARAM_PROVIDER, defaultKeyStoreProvider));
    lk.setPassword(config.get(KEYSTORE_PARAM_PASSWORD));
    lk.setKeyPassword(config.get(KEYSTORE_PARAM_KEY_PASSWORD));
    lk.setKeyPasswordFile(config.get(KEYSTORE_PARAM_KEY_PASSWORD_FILE));
    lk.setMayCreate(config.getBoolean(KEYSTORE_PARAM_CREATE, DEFAULT_CREATE));
    return lk;
  }
コード例 #3
0
 public boolean createShield(Location location, Player player) {
   // Creates a new shield.
   Configuration config = this.plugin.getConfiguration();
   // Make sure the shield is placable at this position.
   for (Shield intersect : this.getIntersects(location, config.getInt("shield.create.radius"))) {
     if (!intersect.isOwner(player)) {
       return false;
     }
   }
   if (!config.getBoolean("mechanics.blocks-above-crystal") && this.hasBlocksAbove(location)) {
     return false;
   }
   // Create shield.
   Shield shield =
       new Shield(
           location,
           this.plugin,
           config.getInt("shield.create.radius") * config.getInt("shield.health-multipler"),
           config.getInt("shield.create.radius"),
           false);
   shield.addOwner(player.getName());
   this.shields.add(shield);
   for (Location claimedLocation : this.getLocations(shield.getLocation(), shield.getRadius())) {
     this.plugin.getWorldHealer().removeLocation(claimedLocation);
   }
   return true;
 }
コード例 #4
0
 // Called by RegistryPlugin iff any config below RegistryPlugin.PREFIX
 // has changed
 protected void setConfig(
     Configuration config, Configuration prevConfig, Configuration.Differences changedKeys) {
   m_maxRefetchDepth =
       config.getInt(
           NewContentCrawler.PARAM_MAX_CRAWL_DEPTH, NewContentCrawler.DEFAULT_MAX_CRAWL_DEPTH);
   fetchRateLimiter = recomputeFetchRateLimiter(fetchRateLimiter);
   enablePolls = config.getBoolean(PARAM_ENABLE_REGISTRY_POLLS, DEFAULT_ENABLE_REGISTRY_POLLS);
 }
コード例 #5
0
  @SuppressWarnings("static-method")
  @Test
  public void testGetBoolean() {
    final Configuration configuration = new Configuration();
    configuration.setObject("A", Boolean.FALSE);
    configuration.setObject("B", Boolean.TRUE);
    configuration.setObject("C", Integer.valueOf(0));
    configuration.setObject("D", Integer.valueOf(1));
    configuration.setObject("E", "E");

    final OptionalBoolean a0 = configuration.getBoolean("A");
    final OptionalBoolean a1 = configuration.getBoolean("A", true);
    final OptionalBoolean b0 = configuration.getBoolean("B");
    final OptionalBoolean b1 = configuration.getBoolean("B", true);
    final OptionalBoolean c0 = configuration.getBoolean("C");
    final OptionalBoolean c1 = configuration.getBoolean("C", true);
    final OptionalBoolean d0 = configuration.getBoolean("D");
    final OptionalBoolean d1 = configuration.getBoolean("D", true);
    final OptionalBoolean e0 = configuration.getBoolean("E");
    final OptionalBoolean e1 = configuration.getBoolean("E", true);

    Assert.assertTrue(a0.isPresent());
    Assert.assertTrue(a1.isPresent());
    Assert.assertTrue(b0.isPresent());
    Assert.assertTrue(b1.isPresent());
    Assert.assertTrue(c0.isPresent());
    Assert.assertTrue(c1.isPresent());
    Assert.assertTrue(d0.isPresent());
    Assert.assertTrue(d1.isPresent());
    Assert.assertFalse(e0.isPresent());
    Assert.assertTrue(e1.isPresent());

    Assert.assertFalse(a0.getAsBoolean());
    Assert.assertFalse(a1.getAsBoolean());
    Assert.assertTrue(b0.getAsBoolean());
    Assert.assertTrue(b1.getAsBoolean());
    Assert.assertFalse(c0.getAsBoolean());
    Assert.assertFalse(c1.getAsBoolean());
    Assert.assertTrue(d0.getAsBoolean());
    Assert.assertTrue(d1.getAsBoolean());
    Assert.assertTrue(e1.getAsBoolean());
  }
コード例 #6
0
ファイル: AudioTranscoder.java プロジェクト: lelaurent/jAM-lp
  /**
   * Transcode the source file to target using the requested number of channels and sampling rate.
   *
   * @param source The path of the source file.
   * @param target The path of the target file.
   * @param channels The number of channels target should have. A stereo stream can be down mixed to
   *     a mono stream. Converting a mono stream to a stereo stream results in a file with two
   *     channels with the same data.
   * @param samplingRate The sampling rate the target file should have;
   */
  public static void transcode(
      final String source, final String target, final Attributes attributes)
      throws EncoderException {
    final File sourceFile = new File(source);
    final File targetFile = new File(target);

    // if transcoding is enabled transcode
    if (Configuration.getBoolean(ConfKey.transcode_audio)) {
      Transcoder.transcode(sourceFile, targetFile, attributes);
    } else {
      // if transcoding is disabled: copy the audio
      FileUtils.cp(source, target);
    }
  }
コード例 #7
0
  public synchronized void setConfig(
      Configuration config, Configuration prevConfig, Configuration.Differences changedKeys) {
    if (changedKeys.contains(PREFIX)) {
      defaultKeyStoreType = config.get(PARAM_DEFAULT_KEYSTORE_TYPE, DEFAULT_DEFAULT_KEYSTORE_TYPE);
      defaultKeyStoreProvider =
          config.get(PARAM_DEFAULT_KEYSTORE_PROVIDER, DEFAULT_DEFAULT_KEYSTORE_PROVIDER);
      paramExitIfMissingKeyStore =
          config.getBoolean(PARAM_EXIT_IF_MISSING_KEYSTORE, DEFAULT_EXIT_IF_MISSING_KEYSTORE);

      if (changedKeys.contains(PARAM_KEYSTORE)) {
        configureKeyStores(config);
        // defer initial set of keystore loading until startService
        if (isInited()) {
          // load any newly added keystores
          loadKeyStores();
        }
      }
    }
  }
コード例 #8
0
ファイル: ScreenSnapper.java プロジェクト: Codeusa/sleeksnap
  /** Load settings */
  private void loadSettings(final boolean resetConfig) throws Exception {
    final File configFile =
        new File(Util.getWorkingDirectory(), Application.NAME.toLowerCase() + ".conf");
    if (!configFile.exists() || resetConfig) {
      configuration.setFile(configFile);
      loadDefaultConfiguration();
    } else {
      configuration.load(configFile);
    }
    if (configuration.contains("uploaders")) {
      final JSONObject uploadConfig = configuration.getJSONObject("uploaders");

      if (convertUploadDefinition(uploadConfig, BufferedImage.class, ImageUpload.class)
          || convertUploadDefinition(uploadConfig, String.class, TextUpload.class)
          || convertUploadDefinition(uploadConfig, File.class, FileUpload.class)
          || convertUploadDefinition(uploadConfig, URL.class, URLUpload.class)) {
        logger.info("Converted upload definitions from old configuration.");
        configuration.save();
      }

      @SuppressWarnings("unchecked")
      final Iterator<Object> it$ = uploadConfig.keys();
      while (it$.hasNext()) {
        final String key = it$.next().toString();
        final String className = uploadConfig.getString(key);

        @SuppressWarnings("unchecked")
        final Class<? extends Upload> clType = (Class<? extends Upload>) Class.forName(key);
        if (clType != null) {
          setDefaultUploader(clType, className);
        }
      }
    }
    if (configuration.contains("startOnStartup") && configuration.getBoolean("startOnStartup")) {
      // Verify that the paths match, useful for upgrading since it won't
      // open the old file.
      final File current = FileUtils.getJarFile(ScreenSnapper.class);
      if (!current.isDirectory()) {
        Updater.verifyAutostart(current, VerificationMode.INSERT);
      }
    }
  }
コード例 #9
0
 public void testBooleanValues() throws IOException {
   out = new BufferedWriter(new FileWriter(CONFIG));
   startConfig();
   appendProperty("test.bool1", "true");
   appendProperty("test.bool2", "false");
   appendProperty("test.bool3", "  true ");
   appendProperty("test.bool4", " false ");
   appendProperty("test.bool5", "foo");
   appendProperty("test.bool6", "TRUE");
   appendProperty("test.bool7", "FALSE");
   appendProperty("test.bool8", "");
   endConfig();
   Path fileResource = new Path(CONFIG);
   conf.addResource(fileResource);
   assertEquals(true, conf.getBoolean("test.bool1", false));
   assertEquals(false, conf.getBoolean("test.bool2", true));
   assertEquals(true, conf.getBoolean("test.bool3", false));
   assertEquals(false, conf.getBoolean("test.bool4", true));
   assertEquals(true, conf.getBoolean("test.bool5", true));
   assertEquals(true, conf.getBoolean("test.bool6", false));
   assertEquals(false, conf.getBoolean("test.bool7", true));
   assertEquals(false, conf.getBoolean("test.bool8", false));
 }
コード例 #10
0
ファイル: ScreenSnapper.java プロジェクト: Codeusa/sleeksnap
  /** Upload content from the clipboard */
  public void clipboard() {
    try {
      final Object clipboard = ClipboardUtil.getClipboardContents();
      if (clipboard == null) {
        icon.displayMessage(
            Language.getString("invalidClipboard"),
            Language.getString("invalidClipboardTitle"),
            TrayIcon.MessageType.WARNING);
        return;
      }
      if (clipboard instanceof BufferedImage) {
        upload(new ImageUpload((BufferedImage) clipboard));
      } else if (clipboard instanceof File) {
        final File file = (File) clipboard;
        final String mime = FileUtils.getMimeType(file.getAbsolutePath());

        // A better way to upload images, it'll check the mime type!
        if (mime.startsWith("image")) {
          upload(new ImageUpload(ImageIO.read(file)));
        } else if (mime.startsWith("text") && configuration.getBoolean("plainTextUpload")) {
          upload(new TextUpload(FileUtils.readFile(file)));
        } else {
          upload(new FileUpload(file));
        }
      } else if (clipboard instanceof String) {
        final String string = clipboard.toString();
        if (string.matches("((mailto\\:|(news|(ht|f)tp(s?))\\://){1}\\S+)")) {
          upload(new URLUpload(clipboard.toString()));
        } else {
          upload(new TextUpload(string));
        }
      }
    } catch (final ClipboardException e) {
      logger.log(Level.SEVERE, "Unable to get clipboard contents", e);
      showException(e);
    } catch (final IOException e) {
      e.printStackTrace();
    }
  }
コード例 #11
0
ファイル: RPC.java プロジェクト: baeeq/hadoop-20
 /**
  * Construct an RPC server.
  *
  * @param instance the instance whose methods will be called
  * @param conf the configuration to use
  * @param bindAddress the address to bind on to listen for connection
  * @param port the port to listen for connections on
  * @param numHandlers the number of method handler threads to run
  * @param verbose whether each call should be logged
  * @param supportOldJobConf supports server to deserialize old job conf
  */
 public Server(
     Object instance,
     Configuration conf,
     String bindAddress,
     int port,
     int numHandlers,
     boolean verbose,
     boolean supportOldJobConf)
     throws IOException {
   super(
       bindAddress,
       port,
       Invocation.class,
       numHandlers,
       conf,
       classNameBase(instance.getClass().getName()),
       supportOldJobConf);
   this.instance = instance;
   this.verbose = verbose;
   this.authorize =
       conf.getBoolean(ServiceAuthorizationManager.SERVICE_AUTHORIZATION_CONFIG, false);
 }
コード例 #12
0
    FSVolume(File currentDir, Configuration conf) throws IOException {
      this.reserved = conf.getLong("dfs.datanode.du.reserved", 0);
      boolean supportAppends = conf.getBoolean("dfs.support.append", false);
      File parent = currentDir.getParentFile();

      this.detachDir = new File(parent, "detach");
      if (detachDir.exists()) {
        recoverDetachedBlocks(currentDir, detachDir);
      }

      // Files that were being written when the datanode was last shutdown
      // are now moved back to the data directory. It is possible that
      // in the future, we might want to do some sort of datanode-local
      // recovery for these blocks. For example, crc validation.
      //
      this.tmpDir = new File(parent, "tmp");
      if (tmpDir.exists()) {
        if (supportAppends) {
          recoverDetachedBlocks(currentDir, tmpDir);
        } else {
          FileUtil.fullyDelete(tmpDir);
        }
      }
      this.dataDir = new FSDir(currentDir);
      if (!tmpDir.mkdirs()) {
        if (!tmpDir.isDirectory()) {
          throw new IOException("Mkdirs failed to create " + tmpDir.toString());
        }
      }
      if (!detachDir.mkdirs()) {
        if (!detachDir.isDirectory()) {
          throw new IOException("Mkdirs failed to create " + detachDir.toString());
        }
      }
      this.usage = new DF(parent, conf);
      this.dfsUsage = new DU(parent, conf);
      this.dfsUsage.start();
    }
コード例 #13
0
ファイル: ScreenSnapper.java プロジェクト: Codeusa/sleeksnap
  /**
   * Execute an upload
   *
   * @param object The object to upload
   */
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void executeUpload(Upload object) {
    // Run the object through the filters
    if (filters.containsKey(object.getClass())) {
      for (final UploadFilter filter : filters.get(object.getClass())) {
        try {
          object = filter.filter(object);
        } catch (final FilterException e) {
          // FilterExceptions when thrown should interrupt the upload.
          showException(e, e.getErrorMessage());
          return;
        }
      }
    }
    // Then upload it
    final Uploader uploader = uploaderAssociations.get(object.getClass());
    if (uploader != null) {
      try {
        String url = uploader.upload(object);
        if (url != null) {
          if (configuration.getBoolean("shortenurls")) {
            final Uploader shortener = uploaderAssociations.get(URL.class);
            if (shortener != null) {
              url = shortener.upload(new URLUpload(url));
            }
          }
          if (object instanceof ImageUpload) {
            if (configuration.getBoolean("savelocal")
                && !(uploader instanceof ImageLocalFileUploader)) {
              final FileOutputStream output =
                  new FileOutputStream(getLocalFile(DateUtil.getCurrentDate() + ".png"));
              try {
                ImageIO.write(((ImageUpload) object).getImage(), "png", output);
              } finally {
                output.close();
              }
            }
            ((ImageUpload) object).getImage().flush();
            ((ImageUpload) object).setImage(null);
          }
          url = url.trim();

          retries = 0;

          ClipboardUtil.setClipboard(url);

          lastUrl = url;
          history.addEntry(new HistoryEntry(url, uploader.getName()));
          icon.displayMessage(
              Language.getString("uploadComplete"),
              Language.getString("uploadedTo", url),
              TrayIcon.MessageType.INFO);
          logger.info("Upload completed, url: " + url);
        } else {
          icon.displayMessage(
              Language.getString("uploadFailed"),
              Language.getString("uploadFailedError"),
              TrayIcon.MessageType.ERROR);
          logger.severe("Upload failed to execute due to an unknown error");
        }
      } catch (final UploaderConfigurationException e) {
        icon.displayMessage(
            Language.getString("uploaderConfigError"),
            Language.getString("uploaderConfigErrorMessage"),
            TrayIcon.MessageType.ERROR);
        logger.log(Level.SEVERE, "Upload failed to execute", e);
      } catch (final Exception e) {
        // Retry until retries > max
        final StringBuilder msg = new StringBuilder("The upload failed to execute: ");
        msg.append(e.getMessage());
        final int max =
            configuration.getInteger("max_retries", Constants.Configuration.DEFAULT_MAX_RETRIES);
        if (retries++ < max) {
          logger.info("Retrying upload (" + retries + " of " + max + " retries)...");
          msg.append("\nRetrying...");
          upload(object);
        } else {
          msg.append("\nReached retry limit, upload aborted.");
          logger.log(Level.SEVERE, "Upload failed to execute, retries: " + retries, e);
          retries = 0;
        }
        icon.displayMessage(
            Language.getString("uploadFailed"), msg.toString(), TrayIcon.MessageType.ERROR);
      }
    }
  }
コード例 #14
0
 public void setConfig(
     Configuration config, Configuration oldConfig, Configuration.Differences changedKeys) {
   //  Build list of repositories from list of disk (fs) paths).  Needs to
   //  be generalized if ever another repository implementation.
   if (changedKeys.contains(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST)) {
     List lst = new ArrayList();
     String dspace = config.get(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, "");
     List paths = StringUtil.breakAt(dspace, ';');
     if (paths != null) {
       for (Iterator iter = paths.iterator(); iter.hasNext(); ) {
         lst.add("local:" + (String) iter.next());
       }
     }
     repoList = lst;
   }
   if (changedKeys.contains(PARAM_MAX_PER_AU_CACHE_SIZE)) {
     paramNodeCacheSize =
         config.getInt(PARAM_MAX_PER_AU_CACHE_SIZE, DEFAULT_MAX_PER_AU_CACHE_SIZE);
     for (Iterator iter = getDaemon().getAllLockssRepositories().iterator(); iter.hasNext(); ) {
       LockssRepository repo = (LockssRepository) iter.next();
       if (repo instanceof LockssRepositoryImpl) {
         LockssRepositoryImpl repoImpl = (LockssRepositoryImpl) repo;
         repoImpl.setNodeCacheSize(paramNodeCacheSize);
       }
     }
   }
   if (changedKeys.contains(PARAM_MAX_SUSPECT_VERSIONS_CACHE_SIZE)) {
     paramSuspectVersionsCacheSize =
         config.getInt(
             PARAM_MAX_SUSPECT_VERSIONS_CACHE_SIZE, DEFAULT_MAX_SUSPECT_VERSIONS_CACHE_SIZE);
     suspectVersionsCache.setMaxSize(paramSuspectVersionsCacheSize);
   }
   if (changedKeys.contains(GLOBAL_CACHE_PREFIX)) {
     paramIsGlobalNodeCache =
         config.getBoolean(PARAM_GLOBAL_CACHE_ENABLED, DEFAULT_GLOBAL_CACHE_ENABLED);
     if (paramIsGlobalNodeCache) {
       paramGlobalNodeCacheSize =
           config.getInt(PARAM_MAX_GLOBAL_CACHE_SIZE, DEFAULT_MAX_GLOBAL_CACHE_SIZE);
       log.debug("global node cache size: " + paramGlobalNodeCacheSize);
       globalNodeCache.setMaxSize(paramGlobalNodeCacheSize);
     }
   }
   if (changedKeys.contains(DISK_PREFIX)) {
     int minMB = config.getInt(PARAM_DISK_WARN_FRRE_MB, DEFAULT_DISK_WARN_FRRE_MB);
     double minPer =
         config.getPercentage(PARAM_DISK_WARN_FRRE_PERCENT, DEFAULT_DISK_WARN_FRRE_PERCENT);
     paramDFWarn = PlatformUtil.DF.makeThreshold(minMB, minPer);
     minMB = config.getInt(PARAM_DISK_FULL_FRRE_MB, DEFAULT_DISK_FULL_FRRE_MB);
     minPer = config.getPercentage(PARAM_DISK_FULL_FRRE_PERCENT, DEFAULT_DISK_FULL_FRRE_PERCENT);
     paramDFFull = PlatformUtil.DF.makeThreshold(minMB, minPer);
   }
   if (changedKeys.contains(PARAM_SIZE_CALC_MAX_LOAD)) {
     sizeCalcMaxLoad = config.getPercentage(PARAM_SIZE_CALC_MAX_LOAD, DEFAULT_SIZE_CALC_MAX_LOAD);
   }
   if (changedKeys.contains(PREFIX)) {
     maxUnusedDirSearch =
         config.getInt(PARAM_MAX_UNUSED_DIR_SEARCH, DEFAULT_MAX_UNUSED_DIR_SEARCH);
     isStatefulUnusedDirSearch =
         config.getBoolean(
             PARAM_IS_STATEFUL_UNUSED_DIR_SEARCH, DEFAULT_IS_STATEFUL_UNUSED_DIR_SEARCH);
     enableLongComponents =
         config.getBoolean(PARAM_ENABLE_LONG_COMPONENTS, DEFAULT_ENABLE_LONG_COMPONENTS);
     enableLongComponentsCompatibility =
         config.getBoolean(
             PARAM_ENABLE_LONG_COMPONENTS_COMPATIBILITY,
             DEFAULT_ENABLE_LONG_COMPONENTS_COMPATIBILITY);
     maxComponentLength = config.getInt(PARAM_MAX_COMPONENT_LENGTH, DEFAULT_MAX_COMPONENT_LENGTH);
     checkUnnormalized =
         (CheckUnnormalizedMode)
             config.getEnum(
                 CheckUnnormalizedMode.class,
                 PARAM_CHECK_UNNORMALIZED,
                 DEFAULT_CHECK_UNNORMALIZED);
   }
 }
コード例 #15
0
  public void generateFileChunks(JspWriter out, HttpServletRequest req, Configuration conf)
      throws IOException, InterruptedException {
    long startOffset = 0;
    int datanodePort = 0;
    int chunkSizeToView = 0;

    String namenodeInfoPortStr = req.getParameter("namenodeInfoPort");
    int namenodeInfoPort = -1;
    if (namenodeInfoPortStr != null) namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);

    String filename = HtmlQuoting.unquoteHtmlChars(req.getParameter("filename"));
    if (filename == null) {
      out.print("Invalid input (filename absent)");
      return;
    }

    String blockIdStr = null;
    long blockId = 0;
    blockIdStr = req.getParameter("blockId");
    if (blockIdStr == null) {
      out.print("Invalid input (blockId absent)");
      return;
    }
    blockId = Long.parseLong(blockIdStr);

    String tokenString = req.getParameter(JspHelper.DELEGATION_PARAMETER_NAME);
    UserGroupInformation ugi = JspHelper.getUGI(req, conf);
    final DFSClient dfs = JspHelper.getDFSClient(ugi, jspHelper.nameNodeAddr, conf);

    Token<BlockTokenIdentifier> accessToken = BlockTokenSecretManager.DUMMY_TOKEN;
    if (conf.getBoolean(DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY, false)) {
      List<LocatedBlock> blks =
          dfs.namenode.getBlockLocations(filename, 0, Long.MAX_VALUE).getLocatedBlocks();
      if (blks == null || blks.size() == 0) {
        out.print("Can't locate file blocks");
        dfs.close();
        return;
      }
      for (int i = 0; i < blks.size(); i++) {
        if (blks.get(i).getBlock().getBlockId() == blockId) {
          accessToken = blks.get(i).getBlockToken();
          break;
        }
      }
    }

    String blockGenStamp = null;
    long genStamp = 0;
    blockGenStamp = req.getParameter("genstamp");
    if (blockGenStamp == null) {
      out.print("Invalid input (genstamp absent)");
      return;
    }
    genStamp = Long.parseLong(blockGenStamp);

    String blockSizeStr;
    long blockSize = 0;
    blockSizeStr = req.getParameter("blockSize");
    if (blockSizeStr == null) {
      out.print("Invalid input (blockSize absent)");
      return;
    }
    blockSize = Long.parseLong(blockSizeStr);

    String chunkSizeToViewStr = req.getParameter("chunkSizeToView");
    if (chunkSizeToViewStr != null && Integer.parseInt(chunkSizeToViewStr) > 0)
      chunkSizeToView = Integer.parseInt(chunkSizeToViewStr);
    else chunkSizeToView = JspHelper.getDefaultChunkSize(conf);

    String startOffsetStr = req.getParameter("startOffset");
    if (startOffsetStr == null || Long.parseLong(startOffsetStr) < 0) startOffset = 0;
    else startOffset = Long.parseLong(startOffsetStr);

    String datanodePortStr = req.getParameter("datanodePort");
    if (datanodePortStr == null) {
      out.print("Invalid input (datanodePort absent)");
      return;
    }
    datanodePort = Integer.parseInt(datanodePortStr);
    out.print("<h3>File: ");
    JspHelper.printPathWithLinks(
        HtmlQuoting.quoteHtmlChars(filename), out, namenodeInfoPort, tokenString);
    out.print("</h3><hr>");
    String parent = new File(filename).getParent();
    JspHelper.printGotoForm(out, namenodeInfoPort, tokenString, HtmlQuoting.quoteHtmlChars(parent));
    out.print("<hr>");
    out.print(
        "<a href=\"http://"
            + req.getServerName()
            + ":"
            + req.getServerPort()
            + "/browseDirectory.jsp?dir="
            + URLEncoder.encode(parent, "UTF-8")
            + "&namenodeInfoPort="
            + namenodeInfoPort
            + "\"><i>Go back to dir listing</i></a><br>");
    out.print("<a href=\"#viewOptions\">Advanced view/download options</a><br>");
    out.print("<hr>");

    // Determine the prev & next blocks
    long nextStartOffset = 0;
    long nextBlockSize = 0;
    String nextBlockIdStr = null;
    String nextGenStamp = null;
    String nextHost = req.getServerName();
    int nextPort = req.getServerPort();
    int nextDatanodePort = datanodePort;
    // determine data for the next link
    if (startOffset + chunkSizeToView >= blockSize) {
      // we have to go to the next block from this point onwards
      List<LocatedBlock> blocks =
          dfs.namenode.getBlockLocations(filename, 0, Long.MAX_VALUE).getLocatedBlocks();
      for (int i = 0; i < blocks.size(); i++) {
        if (blocks.get(i).getBlock().getBlockId() == blockId) {
          if (i != blocks.size() - 1) {
            LocatedBlock nextBlock = blocks.get(i + 1);
            nextBlockIdStr = Long.toString(nextBlock.getBlock().getBlockId());
            nextGenStamp = Long.toString(nextBlock.getBlock().getGenerationStamp());
            nextStartOffset = 0;
            nextBlockSize = nextBlock.getBlock().getNumBytes();
            DatanodeInfo d = jspHelper.bestNode(nextBlock);
            String datanodeAddr = d.getName();
            nextDatanodePort =
                Integer.parseInt(
                    datanodeAddr.substring(datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
            nextHost = InetAddress.getByName(d.getHost()).getCanonicalHostName();
            nextPort = d.getInfoPort();
          }
        }
      }
    } else {
      // we are in the same block
      nextBlockIdStr = blockIdStr;
      nextStartOffset = startOffset + chunkSizeToView;
      nextBlockSize = blockSize;
      nextGenStamp = blockGenStamp;
    }
    String nextUrl = null;
    if (nextBlockIdStr != null) {
      nextUrl =
          "http://"
              + nextHost
              + ":"
              + nextPort
              + "/browseBlock.jsp?blockId="
              + nextBlockIdStr
              + "&blockSize="
              + nextBlockSize
              + "&startOffset="
              + nextStartOffset
              + "&genstamp="
              + nextGenStamp
              + "&filename="
              + URLEncoder.encode(filename, "UTF-8")
              + "&chunkSizeToView="
              + chunkSizeToView
              + "&datanodePort="
              + nextDatanodePort
              + "&namenodeInfoPort="
              + namenodeInfoPort
              + JspHelper.getDelegationTokenUrlParam(tokenString);
      out.print("<a href=\"" + nextUrl + "\">View Next chunk</a>&nbsp;&nbsp;");
    }
    // determine data for the prev link
    String prevBlockIdStr = null;
    String prevGenStamp = null;
    long prevStartOffset = 0;
    long prevBlockSize = 0;
    String prevHost = req.getServerName();
    int prevPort = req.getServerPort();
    int prevDatanodePort = datanodePort;
    if (startOffset == 0) {
      List<LocatedBlock> blocks =
          dfs.namenode.getBlockLocations(filename, 0, Long.MAX_VALUE).getLocatedBlocks();
      for (int i = 0; i < blocks.size(); i++) {
        if (blocks.get(i).getBlock().getBlockId() == blockId) {
          if (i != 0) {
            LocatedBlock prevBlock = blocks.get(i - 1);
            prevBlockIdStr = Long.toString(prevBlock.getBlock().getBlockId());
            prevGenStamp = Long.toString(prevBlock.getBlock().getGenerationStamp());
            prevStartOffset = prevBlock.getBlock().getNumBytes() - chunkSizeToView;
            if (prevStartOffset < 0) prevStartOffset = 0;
            prevBlockSize = prevBlock.getBlock().getNumBytes();
            DatanodeInfo d = jspHelper.bestNode(prevBlock);
            String datanodeAddr = d.getName();
            prevDatanodePort =
                Integer.parseInt(
                    datanodeAddr.substring(datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
            prevHost = InetAddress.getByName(d.getHost()).getCanonicalHostName();
            prevPort = d.getInfoPort();
          }
        }
      }
    } else {
      // we are in the same block
      prevBlockIdStr = blockIdStr;
      prevStartOffset = startOffset - chunkSizeToView;
      if (prevStartOffset < 0) prevStartOffset = 0;
      prevBlockSize = blockSize;
      prevGenStamp = blockGenStamp;
    }

    String prevUrl = null;
    if (prevBlockIdStr != null) {
      prevUrl =
          "http://"
              + prevHost
              + ":"
              + prevPort
              + "/browseBlock.jsp?blockId="
              + prevBlockIdStr
              + "&blockSize="
              + prevBlockSize
              + "&startOffset="
              + prevStartOffset
              + "&filename="
              + URLEncoder.encode(filename, "UTF-8")
              + "&chunkSizeToView="
              + chunkSizeToView
              + "&genstamp="
              + prevGenStamp
              + "&datanodePort="
              + prevDatanodePort
              + "&namenodeInfoPort="
              + namenodeInfoPort
              + JspHelper.getDelegationTokenUrlParam(tokenString);
      out.print("<a href=\"" + prevUrl + "\">View Prev chunk</a>&nbsp;&nbsp;");
    }
    out.print("<hr>");
    out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" style=\"width:100%\" READONLY>");
    try {
      jspHelper.streamBlockInAscii(
          new InetSocketAddress(req.getServerName(), datanodePort),
          blockId,
          accessToken,
          genStamp,
          blockSize,
          startOffset,
          chunkSizeToView,
          out,
          conf);
    } catch (Exception e) {
      out.print(e);
    }
    out.print("</textarea>");
    dfs.close();
  }
コード例 #16
0
  @Override
  public void runPlugin(PluginRespirator myPR) {
    try {
      Logger.normal(this, "Plugin starting up...");

      mPluginRespirator = myPR;

      if (logDEBUG) Logger.debug(this, "Opening database...");
      db = openDatabase(new File(getUserDataDirectory(), DATABASE_FILENAME));
      if (logDEBUG) Logger.debug(this, "Database opened.");

      mConfig = Configuration.loadOrCreate(this, db);
      if (mConfig.getDatabaseFormatVersion() > Freetalk.DATABASE_FORMAT_VERSION)
        throw new RuntimeException(
            "The Freetalk plugin's database format is newer than the Freetalk plugin which is being used.");

      // Create & start the core classes

      if (logDEBUG) Logger.debug(this, "Creating identity manager...");
      mIdentityManager = new WoTIdentityManager(this, mPluginRespirator.getNode().executor);

      if (logDEBUG) Logger.debug(this, "Creating message manager...");
      mMessageManager = new WoTMessageManager(db, mIdentityManager, this, mPluginRespirator);

      if (logDEBUG) Logger.debug(this, "Creating task manager...");
      mTaskManager = new PersistentTaskManager(this, db);

      upgradeDatabase();

      // We only do this if debug logging is enabled since the integrity verification cannot repair
      // anything anyway,
      // if the user does not read his logs there is no need to check the integrity.
      // TODO: Do this once every few startups and notify the user in the web ui if errors are
      // found.
      if (logDEBUG)
        databaseIntegrityTest(); // Some tests need the Identity-/Message-/TaskManager so we call
      // this after creating them.

      if (logDEBUG) Logger.debug(this, "Creating message XML...");
      mMessageXML = new WoTMessageXML();

      if (logDEBUG) Logger.debug(this, "Creating message list XML...");
      mMessageListXML = new WoTMessageListXML();

      if (logDEBUG) Logger.debug(this, "Creating old-messagelist fetcher...");
      mOldMessageListFetcher =
          new WoTOldMessageListFetcher(this, "Freetalk WoTOldMessageListFetcher", mMessageListXML);

      if (logDEBUG) Logger.debug(this, "Creating new-messagelist fetcher...");
      mNewMessageListFetcher =
          new WoTNewMessageListFetcher(
              this, "Freetalk WoTNewMessageListFetcher", mMessageListXML, db);
      mNewMessageListFetcher.start();

      if (logDEBUG) Logger.debug(this, "Creating message fetcher...");
      mMessageFetcher =
          new WoTMessageFetcher(
              mPluginRespirator.getNode(),
              mPluginRespirator.getHLSimpleClient(),
              "Freetalk WoTMessageFetcher",
              this,
              mIdentityManager,
              mMessageManager,
              mMessageXML);
      mMessageFetcher.start();

      if (logDEBUG) Logger.debug(this, "Creating message inserter...");
      mMessageInserter =
          new WoTMessageInserter(
              mPluginRespirator.getNode(),
              mPluginRespirator.getHLSimpleClient(),
              "Freetalk WoTMessageInserter",
              mIdentityManager,
              mMessageManager,
              mMessageXML);
      mMessageInserter.start();

      if (logDEBUG) Logger.debug(this, "Creating message list inserter...");
      mMessageListInserter =
          new WoTMessageListInserter(
              mPluginRespirator.getNode(),
              mPluginRespirator.getHLSimpleClient(),
              "Freetalk WoTMessageListInserter",
              mIdentityManager,
              mMessageManager,
              mMessageListXML);
      mMessageListInserter.start();

      // They need each users so they must be started after they exist all three.
      // Further, we must start them after starting the message list fetches: Otherwise the message
      // manager etc. might take locks for ages, effectively
      // preventing this startup function from finishing. So we just start them after all core
      // classes are running and before starting the UI.
      mIdentityManager.start();
      mMessageManager.start();
      mTaskManager.start();

      // This must be started after the identity manager because it will need the identity manager
      // to be connected to WoT.
      mOldMessageListFetcher.start();

      // Create & start the UI

      if (logDEBUG) Logger.debug(this, "Creating Web interface...");
      mWebInterface = new WebInterface(this);

      if (logDEBUG) Logger.debug(this, "Creating FCP interface...");
      mFCPInterface = new FCPInterface(this);

      if (mConfig.getBoolean(Configuration.NNTP_SERVER_ENABLED)) {
        if (logDEBUG) Logger.debug(this, "Creating NNTP server...");
        String bindTo = mConfig.getString(Configuration.NNTP_SERVER_BINDTO);
        if (bindTo == null) {
          bindTo = "127.0.0.1";
        }
        String allowedHosts = mConfig.getString(Configuration.NNTP_SERVER_ALLOWED_HOSTS);
        if (allowedHosts == null) {
          allowedHosts = "127.0.0.1";
        }
        mNNTPServer = new FreetalkNNTPServer(this, 1199, bindTo, allowedHosts);
        mNNTPServer.start();
      } else {
        if (logDEBUG) Logger.debug(this, "NNTP server disabled by user...");
        mNNTPServer = null;
      }

      Logger.normal(this, "Freetalk starting up completed.");
    } catch (RuntimeException e) {
      Logger.error(this, "Startup failed!", e);
      terminate();
      throw e;
    }
  }