@SuppressWarnings("unchecked")
  @Override
  public void map(LongWritable positionToMap, LongWritable record, Context context) {
    try {
      S pos = game.hashToState(positionToMap.get());
      game.longToRecord(pos, record.get(), rec);
      rec.previousPosition();

      int numParents = 0;
      numParents = ((Undoable<S>) game).possibleParents(pos, parentStates);

      for (int i = 0; i < numParents; i++) {
        long parentHash = game.stateToHash(parentStates[i]);
        RangeFile parentFile = rangeFiles.getFile(parentHash);

        srp.state = parentHash;
        srp.record = game.recordToLong(parentStates[i], rec);

        context.write(parentFile, new StateRecordPair(srp.state, srp.record));
      }
    } catch (IOException e) {
      throw new Error(e);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void setup(Context context) {
    try {
      org.apache.hadoop.conf.Configuration hadoopConf = context.getConfiguration();
      conf = Configuration.deserialize(hadoopConf.get("gamesman.configuration"));
      game = conf.getCheckedGame();
      if (game instanceof Undoable<?>) {
        parentStates = game.newStateArray(((Undoable<?>) game).maxParents());
      }
      fs = FileSystem.get(hadoopConf);
      rec = new Record(conf);
      srp = new StateRecordPair();

      rangeFiles = new RangeFileManager<S>(fs, hadoopConf, game);
    } catch (IOException e) {
      throw new Error(e);
    } catch (ClassNotFoundException e) {
      throw new Error(e);
    } catch (ClassCastException e) {
      throw new Error("Game is not Undoable");
    }
  }
Exemplo n.º 3
0
 public static DatabaseArgs getArgs(
     String uri, Configuration conf, boolean reading, boolean writing) {
   Game<?> g = conf.getGame();
   return getArgs(uri, conf, 0, g.numHashes(), reading, writing);
 }