Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  protected void processInStreamOutStream(
      int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer) throws IgniteCheckedException {
    switch (type) {
      case OP_START:
        {
          TransactionConcurrency txConcurrency =
              TransactionConcurrency.fromOrdinal(reader.readInt());

          assert txConcurrency != null;

          TransactionIsolation txIsolation = TransactionIsolation.fromOrdinal(reader.readInt());

          assert txIsolation != null;

          Transaction tx =
              txs.txStart(txConcurrency, txIsolation, reader.readLong(), reader.readInt());

          long id = registerTx(tx);

          writer.writeLong(id);

          return;
        }
    }

    super.processInStreamOutStream(type, reader, writer);
  }
  /**
   * Tests preset eviction policy.
   *
   * @throws Exception If failed.
   */
  private void checkPolicy0() throws Exception {
    for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
      txConcurrency = concurrency;

      for (TransactionIsolation isolation : TransactionIsolation.values()) {
        txIsolation = isolation;

        Ignite g = startGrids();

        IgniteCache<String, String> cache = g.cache(null);

        try {
          info(
              ">>> Checking policy [txConcurrency="
                  + txConcurrency
                  + ", txIsolation="
                  + txIsolation
                  + ", plc="
                  + plc
                  + ", nearPlc="
                  + nearPlc
                  + ']');

          checkExplicitTx(g, cache);

          checkImplicitTx(cache);
        } finally {
          stopAllGrids();
        }
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean readFrom(ByteBuffer buf, MessageReader reader) {
    reader.setBuffer(buf);

    if (!reader.beforeMessageRead()) return false;

    if (!super.readFrom(buf, reader)) return false;

    switch (reader.state()) {
      case 8:
        byte concurrencyOrd;

        concurrencyOrd = reader.readByte("concurrency");

        if (!reader.isLastRead()) return false;

        concurrency = TransactionConcurrency.fromOrdinal(concurrencyOrd);

        reader.incrementState();

      case 9:
        dhtVerKeys = reader.readCollection("dhtVerKeys", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 10:
        dhtVerVals = reader.readCollection("dhtVerVals", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 11:
        grpLockKeyBytes = reader.readByteArray("grpLockKeyBytes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 12:
        invalidate = reader.readBoolean("invalidate");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 13:
        byte isolationOrd;

        isolationOrd = reader.readByte("isolation");

        if (!reader.isLastRead()) return false;

        isolation = TransactionIsolation.fromOrdinal(isolationOrd);

        reader.incrementState();

      case 14:
        onePhaseCommit = reader.readBoolean("onePhaseCommit");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 15:
        partLock = reader.readBoolean("partLock");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 16:
        byte plcOrd;

        plcOrd = reader.readByte("plc");

        if (!reader.isLastRead()) return false;

        plc = GridIoPolicy.fromOrdinal(plcOrd);

        reader.incrementState();

      case 17:
        reads = reader.readCollection("reads", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 18:
        sys = reader.readBoolean("sys");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 19:
        threadId = reader.readLong("threadId");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 20:
        timeout = reader.readLong("timeout");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 21:
        txNodesBytes = reader.readByteArray("txNodesBytes");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 22:
        txSize = reader.readInt("txSize");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 23:
        writeVer = reader.readMessage("writeVer");

        if (!reader.isLastRead()) return false;

        reader.incrementState();

      case 24:
        writes = reader.readCollection("writes", MessageCollectionItemType.MSG);

        if (!reader.isLastRead()) return false;

        reader.incrementState();
    }

    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
    writer.setBuffer(buf);

    if (!super.writeTo(buf, writer)) return false;

    if (!writer.isHeaderWritten()) {
      if (!writer.writeHeader(directType(), fieldsCount())) return false;

      writer.onHeaderWritten();
    }

    switch (writer.state()) {
      case 8:
        if (!writer.writeByte(
            "concurrency", concurrency != null ? (byte) concurrency.ordinal() : -1)) return false;

        writer.incrementState();

      case 9:
        if (!writer.writeCollection("dhtVerKeys", dhtVerKeys, MessageCollectionItemType.MSG))
          return false;

        writer.incrementState();

      case 10:
        if (!writer.writeCollection("dhtVerVals", dhtVerVals, MessageCollectionItemType.MSG))
          return false;

        writer.incrementState();

      case 11:
        if (!writer.writeByteArray("grpLockKeyBytes", grpLockKeyBytes)) return false;

        writer.incrementState();

      case 12:
        if (!writer.writeBoolean("invalidate", invalidate)) return false;

        writer.incrementState();

      case 13:
        if (!writer.writeByte("isolation", isolation != null ? (byte) isolation.ordinal() : -1))
          return false;

        writer.incrementState();

      case 14:
        if (!writer.writeBoolean("onePhaseCommit", onePhaseCommit)) return false;

        writer.incrementState();

      case 15:
        if (!writer.writeBoolean("partLock", partLock)) return false;

        writer.incrementState();

      case 16:
        if (!writer.writeByte("plc", plc != null ? (byte) plc.ordinal() : -1)) return false;

        writer.incrementState();

      case 17:
        if (!writer.writeCollection("reads", reads, MessageCollectionItemType.MSG)) return false;

        writer.incrementState();

      case 18:
        if (!writer.writeBoolean("sys", sys)) return false;

        writer.incrementState();

      case 19:
        if (!writer.writeLong("threadId", threadId)) return false;

        writer.incrementState();

      case 20:
        if (!writer.writeLong("timeout", timeout)) return false;

        writer.incrementState();

      case 21:
        if (!writer.writeByteArray("txNodesBytes", txNodesBytes)) return false;

        writer.incrementState();

      case 22:
        if (!writer.writeInt("txSize", txSize)) return false;

        writer.incrementState();

      case 23:
        if (!writer.writeMessage("writeVer", writeVer)) return false;

        writer.incrementState();

      case 24:
        if (!writer.writeCollection("writes", writes, MessageCollectionItemType.MSG)) return false;

        writer.incrementState();
    }

    return true;
  }