Package fr.dyade.aaa.util

Examples of fr.dyade.aaa.util.Operation


    if (logmon.isLoggable(BasicLevel.DEBUG))
      logmon.log(BasicLevel.DEBUG,
                 "NGTransaction, saveInLog(" + dirName + '/' + name + ", " + copy + ", " + first + ")");

    Object key = OperationKey.newKey(dirName, name);
    Operation op = null;
    if (first)
      op = Operation.alloc(Operation.CREATE, dirName, name, buf);
    else
      op = Operation.alloc(Operation.SAVE, dirName, name, buf);
    Operation old = (Operation) log.put(key, op);
    if (copy) {
      if ((old != null) &&
          (old.type == Operation.SAVE) &&
          (old.value.length == buf.length)) {
        // reuse old buffer
        op.value = old.value;
      } else {
        // alloc a new one
        op.value = new byte[buf.length];
      }
      System.arraycopy(buf, 0, op.value, 0, buf.length);
    }
    if (old != null) old.free();

  }
View Full Code Here


  }

  private final byte[] getFromLog(Hashtable log, Object key) throws IOException {
    // Searches in the log a new value for the object.
    Operation op = (Operation) log.get(key);
    if (op != null) {
      if ((op.type == Operation.SAVE) || (op.type == Operation.CREATE)) {
        return op.value;
      } else if (op.type == Operation.DELETE) {
        // The object was deleted.
View Full Code Here

                 "NTransaction, delete(" + dirName + ", " + name + ")");

    Object key = OperationKey.newKey(dirName, name);

    Hashtable log = ((Context) perThreadContext.get()).getLog();
    Operation op = Operation.alloc(Operation.DELETE, dirName, name);
    Operation old = (Operation) log.put(key, op);
    if (old != null) {
      if (old.type == Operation.CREATE) op.type = Operation.NOOP;
      old.free();
    }
  }
View Full Code Here

                if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
                  logmon.log(BasicLevel.DEBUG,
                             "NGTransaction.LogManager, OPERATION=" + optype + ", " + name + " buf=" + Arrays.toString(buf));
               
                Operation old = log.get(key);
                if (old != null) {
                  logFile[old.logidx%nbLogFile].logCounter -= 1;

                  // There is 6 different cases:
                  //
                  //   new |
                  // old   |  C  |  S  |  D
                  // ------+-----+-----+-----+
                  //   C   |  C  |  C  | NOP
                  // ------+-----+-----+-----+
                  //   S   |  S  |  S  |  D
                  // ------+-----+-----+-----+
                  //   D   |  S  |  S  |  D
                  //

                  if ((old.type == Operation.CREATE) || (old.type == Operation.SAVE)) {
                    if ((optype == Operation.CREATE) || (optype == Operation.SAVE)) {
                      // The resulting operation is still the same, just change the logidx
                      // and logptr informations.
                      old.logidx = logidx;
                      old.logptr = ptr;
                    } else {
                      // The operation is a delete
                      if (old.type == Operation.CREATE) {
                        // There is no need to memorize the deletion, the object will be never
                        // created on disk.
                        old.type = Operation.NOOP;
                        log.remove(key);
                        old.free();
                        logFile[logidx%nbLogFile].logCounter -= 1;
                      } else {
                        // The operation is a save, overload it.
                        old.type = Operation.DELETE;
                        old.logidx = logidx;
                        old.logptr = ptr;
                      }
                    }
                  } else if (old.type == Operation.DELETE) {
                    if ((optype == Operation.CREATE) || (optype == Operation.SAVE)) {
                      // The resulting operation is a save
                      old.type = Operation.SAVE;
                    }
                    old.logidx = logidx;
                    old.logptr = ptr;
                  }
                } else {
                  Operation op = Operation.alloc(optype, dirName, name);
                  op.logidx = logidx;
                  op.logptr = ptr;
                  log.put(key, op);
                }
               
View Full Code Here

      Iterator<Entry<Object, Operation>> iterator = entries.iterator();
      try {
        while (true) {
          Entry<Object, Operation> entry = iterator.next();
          Object key = entry.getKey();
          Operation op = entry.getValue();

          if (op.type == Operation.NOOP) continue;

//        if (logmon.isLoggable(BasicLevel.DEBUG)) {
//           if (op.type == Operation.SAVE) {
//             logmon.log(BasicLevel.DEBUG, "NTransaction save " + op.name);
//           } else if (op.type == Operation.CREATE) {
//             logmon.log(BasicLevel.DEBUG, "NTransaction create " + op.name);
//           } else if (op.type == Operation.DELETE) {
//             logmon.log(BasicLevel.DEBUG, "NTransaction delete " + op.name);
//           } else {
//             logmon.log(BasicLevel.DEBUG, "NTransaction unknown(" + op.type + ") " + op.name);
//           }
//        }

          op.logidx = logidx;
          op.logptr = current + count;

          // Save the operation to the log on disk
          write(op.type);
          if (op.dirName != null) {
            writeUTF(op.dirName);
          } else {
            write(emptyUTFString);
          }
          writeUTF(op.name);
          if ((op.type == Operation.SAVE) || (op.type == Operation.CREATE)) {
            writeInt(op.value.length);
            write(op.value);
          }
          // TODO: Use SoftReference ?
          op.value = null;

          // Reports all committed operation in current log
          Operation old = log.put(key, op);
          logFile[logidx%nbLogFile].logCounter += 1;

          if (old != null) {
            logFile[old.logidx%nbLogFile].logCounter -= 1;

            // There is 6 different cases:
            //
            //   new |
            // old   |  C  |  S  |  D
            // ------+-----+-----+-----+
            //   C   |  C  |  C  | NOP
            // ------+-----+-----+-----+
            //   S   |  S  |  S  |  D
            // ------+-----+-----+-----+
            //   D   |  S  |  S  |  D
            //

            if (old.type == Operation.CREATE) {
              if (op.type == Operation.SAVE) {
                // The object has never been created on disk, the resulting operation
                // is still a creation.
                op.type = Operation.CREATE;
              } else if (op.type == Operation.DELETE) {
                // There is no more need to memorize the deletion the object will be
                // never created on disk.
                op.type = Operation.NOOP;
                log.remove(key);
                op.free();
                logFile[logidx%nbLogFile].logCounter -= 1;
              }
            }
            old.free();
          }
        }
      } catch (NoSuchElementException exc) {}
      write(Operation.END);
View Full Code Here

      }
    }

    public byte[] getFromLog(String dirName, String name) throws IOException {
      // First searches in the logs a new value for the object.
      Operation op = log.get(OperationKey.newKey(dirName, name));
      if (op != null) {
        if ((op.type == Operation.SAVE) || (op.type == Operation.CREATE)) {
          // reads the value from the log file
          return getFromLog(op);
        } else if (op.type == Operation.DELETE) {
View Full Code Here

          if (logFile[i] != null)
            logmon.log(BasicLevel.FATAL, "logCounter[" + logFile[i].logidx + "]=" + logFile[i].logCounter);
        }

        for (Enumeration<Operation> e = log.elements(); e.hasMoreElements();) {
          Operation op = e.nextElement();
          logmon.log(BasicLevel.DEBUG, op);
        }
      }

      for (int i=0; i<nbLogFile; i++)
View Full Code Here

     
      if (logf.logCounter > 0) {
        Iterator<Operation> iterator = log.values().iterator();
        try {
          while (true) {
            Operation op = iterator.next();

            if (op.logidx != logf.logidx) continue;

            if ((op.type == Operation.SAVE) || (op.type == Operation.CREATE)) {
              if (logmon.isLoggable(BasicLevel.DEBUG))
                logmon.log(BasicLevel.DEBUG,
                           "NTransaction, LogFile.Save (" + op.dirName + '/' + op.name + ')');

              byte buf[] = getFromLog(op);

              repository.save(op.dirName, op.name, buf);
            } else if (op.type == Operation.DELETE) {
              if (logmon.isLoggable(BasicLevel.DEBUG))
                logmon.log(BasicLevel.DEBUG,
                           "NTransaction, LogFile.Delete (" + op.dirName + '/' + op.name + ')');

              repository.delete(op.dirName, op.name);
            }

            iterator.remove();
            op.free();
          }
        } catch (NoSuchElementException exc) {}

        repository.commit();
      }
View Full Code Here

TOP

Related Classes of fr.dyade.aaa.util.Operation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.