Esempio n. 1
0
 /**
  * インスタンスを生成する。
  *
  * @param configuration 設定情報
  * @throws IOException ファイルシステムの利用に失敗した場合
  * @throws IllegalArgumentException 引数に{@code null}が含まれる場合
  */
 public StageResourceDriver(Configuration configuration) throws IOException {
   if (configuration == null) {
     throw new IllegalArgumentException("configuration must not be null"); // $NON-NLS-1$
   }
   this.configuration = configuration;
   this.localFileSystem = FileSystem.getLocal(configuration);
   this.accessMode = AccessMode.decode(configuration.get(KEY_ACCESS_MODE));
 }
Esempio n. 2
0
 /**
  * Sets the access mode for stage resources in the job.
  *
  * @param context the current job context
  * @param mode the access mode
  * @since 0.7.1
  */
 public static void setAccessMode(JobContext context, AccessMode mode) {
   if (context == null) {
     throw new IllegalArgumentException("context must not be null"); // $NON-NLS-1$
   }
   if (mode == null) {
     throw new IllegalArgumentException("mode must not be null"); // $NON-NLS-1$
   }
   context.getConfiguration().set(KEY_ACCESS_MODE, mode.encode());
 }
Esempio n. 3
0
 static AccessMode decode(String value) {
   if (value != null) {
     try {
       return AccessMode.valueOf(value);
     } catch (IllegalArgumentException e) {
       LOG.warn(MessageFormat.format("invalid access mode for stage resources: {0}", value), e);
     }
   }
   return DEFAULT;
 }
Esempio n. 4
0
  @Override
  protected void readCustomNBT(NBTTagCompound root) {
    if (root.hasKey("accessMode")) {
      accessMode = AccessMode.values()[root.getShort("accessMode")];
    } else {
      // keep behavior the same for blocks placed prior to this update
      accessMode = AccessMode.PUBLIC;
    }
    placedBy = PlayerUtil.getPlayerUIDUnstable(root.getString("placedBy"));
    for (int i = 0; i < password.length; i++) {
      if (root.hasKey("password" + i)) {
        NBTTagCompound stackRoot = (NBTTagCompound) root.getTag("password" + i);
        password[i] = ItemStack.loadItemStackFromNBT(stackRoot);
      } else {
        password[i] = null;
      }
    }
    authorisedUsers.clear();
    String userStr = root.getString("authorisedUsers");
    if (userStr != null && userStr.length() > 0) {
      String[] users = userStr.split(",");
      for (String user : users) {
        if (user != null) {
          user = user.trim();
          if (user.length() > 0) {
            authorisedUsers.add(PlayerUtil.getPlayerUIDUnstable(user));
          }
        }
      }
    }
    if (root.hasKey("itemLabel")) {
      NBTTagCompound stackRoot = (NBTTagCompound) root.getTag("itemLabel");
      itemLabel = ItemStack.loadItemStackFromNBT(stackRoot);
    } else {
      itemLabel = null;
    }

    String sourceBlockStr = root.getString(KEY_SOURCE_BLOCK_ID);
    sourceBlock = Block.getBlockFromName(sourceBlockStr);
    sourceBlockMetadata = root.getInteger(KEY_SOURCE_BLOCK_META);

    label = root.getString("label");
    if (label == null || label.trim().length() == 0) {
      label = null;
    }
  }
Esempio n. 5
0
  @Override
  protected void writeCustomNBT(NBTTagCompound root) {
    root.setShort("accessMode", (short) accessMode.ordinal());
    if (placedBy != null) {
      root.setString("placedBy", placedBy.toString());
    }
    for (int i = 0; i < password.length; i++) {
      ItemStack stack = password[i];
      if (stack != null) {
        NBTTagCompound stackRoot = new NBTTagCompound();
        stack.writeToNBT(stackRoot);
        root.setTag("password" + i, stackRoot);
      }
    }
    StringBuffer userStr = new StringBuffer();
    for (UUID user : authorisedUsers) {
      if (user != null) {
        userStr.append(user.toString());
        userStr.append(",");
      }
    }
    if (authorisedUsers.size() > 0) {
      root.setString("authorisedUsers", userStr.toString());
    }
    if (itemLabel != null) {
      NBTTagCompound labelRoot = new NBTTagCompound();
      itemLabel.writeToNBT(labelRoot);
      root.setTag("itemLabel", labelRoot);
    }

    if (sourceBlock != null) {
      root.setString(KEY_SOURCE_BLOCK_ID, Block.blockRegistry.getNameForObject(sourceBlock));
    }
    root.setInteger(KEY_SOURCE_BLOCK_META, sourceBlockMetadata);

    if (label != null && label.trim().length() > 0) {
      root.setString("label", label);
    }
  }
Esempio n. 6
0
 /**
  * Returns the access mode for stage resources in the job.
  *
  * @param context the current job context
  * @return the access mode
  * @since 0.7.1
  */
 public static AccessMode getAccessMode(JobContext context) {
   if (context == null) {
     throw new IllegalArgumentException("context must not be null"); // $NON-NLS-1$
   }
   return AccessMode.decode(context.getConfiguration().get(KEY_ACCESS_MODE));
 }