示例#1
0
文件: TThread.java 项目: darshikm/STM
        @Override
        public void run() {
          try {
            LOGGER.info("inside run of onCommit");
            WriteSet writeSet = WriteSet.getLocal();
            ReadSet readSet = ReadSet.getLocal();
            VersionClock.setWriteStamp();
            long writeVersion = VersionClock.getWriteStamp();

            for (Map.Entry<LockObject<?>, Object> entry : writeSet.getList()) {
              LockObject<?> key = entry.getKey();
              Copyable<?> destination = null;
              try {
                destination = key.openRead();
              } catch (AbortedException | PanicException e) {
                e.printStackTrace();
              }
              Copyable<Copyable<?>> source = (Copyable<Copyable<?>>) entry.getValue();
              source.copyTo(destination);
              key.stamp = writeVersion;
            }
            writeSet.unlock();
            writeSet.clear();
            readSet.clear();
            Transaction.getLocal().clearKarma();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
示例#2
0
文件: TThread.java 项目: darshikm/STM
  public <T> T doIt(Callable<T> xaction) throws Exception {
    T result = null;
    while (retries <= 10) {
      Transaction me = new Transaction();
      Transaction.setLocal(me);
      ContentionManager.setLocal(new PublishedTimestamp());

      try {
        result = xaction.call();
      } catch (AbortedException e) {
        LOGGER.info(
            "The transaction of thread.."
                + Thread.currentThread().getName()
                + " was aborted by CM.");
        me.abort();
        onAbort.run();
        retries++;
        continue;
      } catch (Exception e) {
        throw new PanicException(e);
      }
      if (onValidate.call()) {
        retries = 0;
        LOGGER.info("Validate call is successful by thread.." + Thread.currentThread().getName());
        if (me.commit()) {
          onCommit.run();
          LOGGER.info("COMMIT successful");
          return result;
        } else {
          LOGGER.info("Transaction COMMIT failed");
        }
      }
      me.abort();
      onAbort.run();
      LOGGER.info("Transaction ABORTED by calling onAbort after onValidate unsuccessful");
    }
    return result;
  }