コード例 #1
0
ファイル: SlaveManagement.java プロジェクト: dr3plus/dr3
  public CommandResponse doSITE_SLAVESELECT(CommandRequest request) throws ImproperUsageException {

    if (!request.hasArgument()) {
      throw new ImproperUsageException();
    }
    String argument = request.getArgument();
    StringTokenizer arguments = new StringTokenizer(argument);
    if (arguments.hasMoreTokens() == false) {
      throw new ImproperUsageException();
    }
    String type = arguments.nextToken();
    if (arguments.hasMoreTokens() == false) {
      throw new ImproperUsageException();
    }
    String path = arguments.nextToken();
    if (!path.startsWith(VirtualFileSystem.separator)) {
      throw new ImproperUsageException();
    }
    char direction = Transfer.TRANSFER_UNKNOWN;
    if (type.equalsIgnoreCase("up")) {
      direction = Transfer.TRANSFER_RECEIVING_UPLOAD;
    } else if (type.equalsIgnoreCase("down")) {
      direction = Transfer.TRANSFER_SENDING_DOWNLOAD;
    } else {
      throw new ImproperUsageException();
    }
    Collection<RemoteSlave> slaves;
    try {
      slaves = GlobalContext.getGlobalContext().getSlaveManager().getAvailableSlaves();
    } catch (NoAvailableSlaveException e1) {
      return StandardCommandManager.genericResponse("RESPONSE_530_SLAVE_UNAVAILABLE");
    }
    SlaveSelectionManager ssm = null;
    try {
      ssm = (SlaveSelectionManager) GlobalContext.getGlobalContext().getSlaveSelectionManager();
    } catch (ClassCastException e) {
      return new CommandResponse(
          500,
          "You are attempting to test filter.SlaveSelectionManager yet you're using def.SlaveSelectionManager");
    }
    CommandResponse response = new CommandResponse(500, "***End of SlaveSelection output***");
    Collection<Filter> filters = ssm.getFilterChain(type).getFilters();
    ScoreChart sc = new ScoreChart(slaves);
    for (Filter filter : filters) {
      try {
        filter.process(sc, null, null, direction, new FileHandle(path), null);
      } catch (NoAvailableSlaveException e) {
      }
    }
    for (SlaveScore ss : sc.getSlaveScores()) {
      response.addComment(ss.getRSlave().getName() + "=" + ss.getScore());
    }
    return response;
  }