// path functions...
 public boolean childOf(Command c1, Command c2) {
   if (c1.getPath().startsWith(c2.getPath())) {
     return true;
   } else {
     return false;
   }
 }
    public TranspResult(Command cmd1, Command cmd2, boolean keepGoing) {
      this.cmd1 = cmd1;
      this.cmd2 = cmd2;
      this.keepGoing = keepGoing;

      // Set the right ticket to the command
      long ticket1 = cmd1.getTicket();
      long ticket2 = cmd2.getTicket();

      if (ticket1 < ticket2) {
        // order ok
      } else {
        // change ticket
        cmd1.setTicket(ticket2);
        cmd2.setTicket(ticket1);
      }
    }
  /*
   * c1 is the oldest Op c2 is the newest Op
   */
  public TranspResult transp(Command c1, Command c2) throws Exception {
    Command res = null;
    Method m = null;

    try {
      try {
        m = this.getClass().getMethod("transp", new Class[] {c1.getClass(), c2.getClass()});
      } catch (NoSuchMethodException e1) {
        // System.out.println("catch 1");
        try {
          m =
              this.getClass()
                  .getMethod("transp", new Class[] {c1.getClass().getSuperclass(), c2.getClass()});
        } catch (NoSuchMethodException e2) {
          // System.out.println("catch 2");
          try {
            m =
                this.getClass()
                    .getMethod(
                        "transp", new Class[] {c1.getClass(), c2.getClass().getSuperclass()});
          } catch (NoSuchMethodException e3) {
            // System.out.println("catch 3");
            try {
              m =
                  this.getClass()
                      .getMethod(
                          "transp",
                          new Class[] {
                            c1.getClass().getSuperclass(), c2.getClass().getSuperclass()
                          });
            } catch (NoSuchMethodException e4) {
              // System.out.println("catch 4");
              try {
                m =
                    this.getClass()
                        .getMethod(
                            "transp",
                            new Class[] {
                              c1.getClass().getSuperclass().getSuperclass(),
                              c2.getClass().getSuperclass()
                            });
              } catch (NoSuchMethodException e5) {
                // System.out.println("catch 5");
                try {
                  m =
                      this.getClass()
                          .getMethod(
                              "transp",
                              new Class[] {
                                c1.getClass().getSuperclass(),
                                c2.getClass().getSuperclass().getSuperclass()
                              });
                } catch (NoSuchMethodException e6) {
                  // System.out.println("catch 6");
                  try {
                    m =
                        this.getClass()
                            .getMethod(
                                "transp",
                                new Class[] {
                                  c1.getClass().getSuperclass().getSuperclass(), c2.getClass()
                                });
                  } catch (NoSuchMethodException e7) {
                    // System.out.println("catch 7");
                    try {
                      m =
                          this.getClass()
                              .getMethod(
                                  "transp",
                                  new Class[] {
                                    c1.getClass().getSuperclass().getSuperclass(), c2.getClass()
                                  });
                    } catch (NoSuchMethodException e8) {
                      // System.out.println("catch 8");
                      m =
                          this.getClass()
                              .getMethod(
                                  "transp",
                                  new Class[] {
                                    c1.getClass().getSuperclass().getSuperclass(),
                                    c2.getClass().getSuperclass().getSuperclass()
                                  });
                    }
                  }
                }
              }
            }
          }
        }
      }
    } catch (NoSuchMethodException e) {
      throw new Exception("No such methode : " + c1 + " / " + c2);
    }

    return (TranspResult) m.invoke(this, new Object[] {c1, c2});
  }
  // and uniquePath(c2,c1)
  public String uniquePath(Command c1, Command c2) {
    long maxTicket = java.lang.Math.max(c1.getTicket(), c2.getTicket());

    return new String(c1.getPath() + "#" + maxTicket);
  }
Beispiel #5
0
  public static void main(String[] args) throws Exception {
    File dir = FileUtils.createTmpDir();
    File opVectorDir = FileUtils.createTmpDir();
    File attachDir = FileUtils.createTmpDir();
    OpVectorFsImpl opVector = new OpVectorFsImpl(opVectorDir.getAbsolutePath());
    File execDir = FileUtils.createTmpDir();
    File execCompDir = FileUtils.createTmpDir();
    DBType dbType = new DBType(dir.getAbsolutePath() + "/dbType.txt", "");
    WsConnection wsc = new WsConnection("c:/replicaTest/original/.so6/1/so6.properties");
    File[] patchList = wsc.getAppliedPatch().list();
    int index = 1;

    for (int i = 0; i < patchList.length; i++) {
      PatchFile pf = new PatchFile(patchList[i].getAbsolutePath());
      pf.buildOpVector(opVector, attachDir.getAbsolutePath(), null);
    }

    // print history
    Command cmd = null;
    FileWriter fw1 = new FileWriter("c:/originalHist.txt");

    for (ListIterator i = opVector.getCommands(); i.hasNext(); ) {
      cmd = (Command) i.next();
      System.out.println(index);

      if (!(cmd instanceof NeutralCommand)) {
        cmd.execute(execDir.getAbsolutePath(), dbType);
        fw1.write(
            index++
                + "\t"
                + cmd.getClass().getName().substring(cmd.getClass().getName().lastIndexOf(".") + 1)
                + "\t"
                + cmd.getPath()
                + "\t"
                + cmd.getAttachement()
                + "\n");
      }
    }

    fw1.close();

    // compression
    CompressUtil.compressLog(opVector);

    // print new history
    FileWriter fw2 = new FileWriter("c:/compressedHist.txt");
    index = 1;

    for (ListIterator i = opVector.getCommands(); i.hasNext(); ) {
      cmd = (Command) i.next();

      if (!(cmd instanceof NeutralCommand)) {
        System.out.println(index);
        cmd.execute(execCompDir.getAbsolutePath(), dbType);
        fw2.write(
            index++
                + "\t"
                + cmd.getClass().getName().substring(cmd.getClass().getName().lastIndexOf(".") + 1)
                + "\t"
                + cmd.getPath()
                + "\t"
                + cmd.getAttachement()
                + "\n");
      }
    }

    fw2.close();
    System.out.println("Exec dir: " + execDir);
    System.out.println("Exec compression dir: " + execCompDir);
    System.out.println(
        "Compare: "
            + FileUtils.compareDir(execDir.getAbsolutePath(), execCompDir.getAbsolutePath()));
  }