コード例 #1
0
  public AITMatrixImpl01(int width, int height) throws InvocationException {
    super(ObjectType.ANDPERSISTENT);

    _width = width;
    _height = height;

    _values = new int[_width][];
    for (int x = 0; x < _width; x++) {
      _values[x] = new int[_height];
    }

    for (int x = 0; x < _width; x++) {
      for (int y = 0; y < _height; y++) {
        if (y < (_height / 2)) {
          _values[x][y] = 0;
        } else {
          _values[x][y] = 1;
        }
      }
    }
    try {
      AtomicTransaction atomicTransaction = new AtomicTransaction();

      atomicTransaction.begin();

      if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
        atomicTransaction.commit(true);
      } else {
        System.err.println("AITMatrixImpl01.AITMatrixImpl01: failed to get lock");
        atomicTransaction.rollback();

        throw new InvocationException(Reason.ReasonConcurrencyControl);
      }
    } catch (InvocationException invocationException) {
      throw invocationException;
    } catch (Exception exception) {
      System.err.println("AITMatrixImpl01.AITMatrixImpl01: " + exception);
      throw new InvocationException(Reason.ReasonUnknown);
    }
  }
コード例 #2
0
  public void set_value(int x, int y, int value) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
      throw new InvocationException(Reason.ReasonUnknown);
    }

    try {
      AtomicTransaction atomicTransaction = new AtomicTransaction();

      try {
        atomicTransaction.begin();

        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
          _values[x][y] = value;
          atomicTransaction.commit(true);
        } else {
          atomicTransaction.rollback();

          throw new InvocationException(Reason.ReasonConcurrencyControl);
        }
      } catch (InvocationException invocationException) {
        throw invocationException;
      } catch (Exception exception) {
        System.err.println("AITMatrixImpl01.set_value: " + exception);
        if (atomicTransaction.get_status() == Status.StatusActive) {
          atomicTransaction.rollback();
        }

        throw new InvocationException(Reason.ReasonUnknown);
      }
    } catch (InvocationException invocationException) {
      throw invocationException;
    } catch (Exception exception) {
      System.err.println("AITMatrixImpl01.set_value: " + exception);
      throw new InvocationException(Reason.ReasonUnknown);
    }
  }