Ejemplo n.º 1
0
  private void dumpLog(final Uid u) {
    EditableTransaction act =
        TransactionTypeManager.getInstance().getTransaction(_transactionType, u);

    if (act == null) System.out.println("Dump failed! Unknown type " + _transactionType);
    else System.out.println(act.toString());
  }
Ejemplo n.º 2
0
  private final void setTransactionType(String command) {
    int index = command.indexOf(SPACE);
    int end = command.indexOf(END);

    if (index != -1) _transactionType = new String(command.substring(index + 1, end).trim());
    else _transactionType = DEFAULT_TYPE;

    if (!TransactionTypeManager.getInstance().present(_transactionType)) {
      System.err.println("Transaction log type " + _transactionType + " not supported.");

      _transactionType = "";
    }
  }
Ejemplo n.º 3
0
  private final boolean supportedLog(String logID) throws ObjectStoreException, IOException {
    Uid id = new Uid(logID);

    if (id.equals(Uid.nullUid())) return false;

    ObjectStoreIterator iter =
        new ObjectStoreIterator(
            StoreManager.getRecoveryStore(),
            TransactionTypeManager.getInstance().getTransactionType(_transactionType));
    Uid u;

    do {
      u = iter.iterate();

      if (u.equals(id)) return true;
    } while (Uid.nullUid().notEquals(u));

    return false;
  }
Ejemplo n.º 4
0
  private final void listLogs(String type) throws IOException {
    InputObjectState buff = new InputObjectState();

    try {
      if (StoreManager.getRecoveryStore()
          .allObjUids(TransactionTypeManager.getInstance().getTransactionType(type), buff)) {
        Uid u = null;

        do {
          u = UidHelper.unpackFrom(buff);

          if (Uid.nullUid().notEquals(u)) {
            System.out.println("Log: " + u);
          }
        } while (Uid.nullUid().notEquals(u));
      }
    } catch (final ObjectStoreException ex) {
      throw new IOException();
    }
  }
Ejemplo n.º 5
0
  public void doWork() {
    boolean attached = false; // move these to member variables
    boolean exit = false;
    boolean selected = false;

    while (!exit) {
      byte[] command = new byte[MAX_COMMAND_LEN];

      try {
        System.out.print("\n" + _transactionType + " - " + _currentLog + " > ");

        System.in.read(command);

        String commandString = new String(command);

        Command com = validCommand(commandString);

        switch (com) {
          case quit:
            return;
          case help:
            help();
            break;
          case ls:
            if (!selected) System.err.println("No transaction type selected.");
            else {
              if (_currentLog == "") listLogs(_transactionType);
              else dumpLog(new Uid(_currentLog));
            }

            System.out.println();

            break;
          case select:
            if (attached) {
              System.out.println("Detaching from existing log.");

              attached = false;
            }

            setTransactionType(commandString);

            if ("".equals(_transactionType)) {
              System.err.println("Unsupported type.");

              selected = false;
            } else selected = true;

            break;
          case attach:
            if (attached) System.err.println("Already attached.");
            else {
              setLogId(commandString);

              if ("".equals(_currentLog)) {
                System.err.println("Invalid log id.");
              } else attached = true;
            }
            break;
          case detach:
            if (!attached) System.err.println("Not attached.");

            _currentLog = "";

            attached = false;
            break;
          case forget:
            if (!attached) System.err.println("Not attached.");

            Uid u = new Uid(_currentLog);
            EditableTransaction act =
                TransactionTypeManager.getInstance().getTransaction(_transactionType, u);

            try {
              act.moveHeuristicToPrepared(getIndex(commandString));
            } catch (final IndexOutOfBoundsException ex) {
              System.err.println("Invalid index.");
            }

            dumpLog(u);
            break;
          case delete:
            if (!attached) System.err.println("Not attached.");

            Uid uid = new Uid(_currentLog);
            EditableTransaction ract =
                TransactionTypeManager.getInstance().getTransaction(_transactionType, uid);

            try {
              ract.deleteHeuristicParticipant(getIndex(commandString));
            } catch (final IndexOutOfBoundsException ex) {
              System.err.println("Invalid index.");
            }

            dumpLog(uid);

            break;
          case types:
            printSupportedTypes();
            break;
          default:
            System.err.println("Invalid command " + new String(command));
            break;
        }
      } catch (final Exception ex) {
        ex.printStackTrace();
      }
    }
  }