예제 #1
0
  /**
   * This constructor is meant for pessimistic transactions.
   *
   * @param nodeId Node ID.
   * @param nearNodeId Near node ID.
   * @param nearXidVer Near transaction ID.
   * @param xidVer XID version.
   * @param commitVer Commit version.
   * @param sys System flag.
   * @param concurrency Concurrency level (should be pessimistic).
   * @param isolation Transaction isolation.
   * @param invalidate Invalidate flag.
   * @param timeout Timeout.
   * @param ctx Cache registry.
   * @param txSize Expected transaction size.
   */
  public GridNearTxRemote(
      GridCacheSharedContext ctx,
      UUID nodeId,
      UUID nearNodeId,
      GridCacheVersion nearXidVer,
      GridCacheVersion xidVer,
      GridCacheVersion commitVer,
      boolean sys,
      byte plc,
      TransactionConcurrency concurrency,
      TransactionIsolation isolation,
      boolean invalidate,
      long timeout,
      int txSize,
      @Nullable UUID subjId,
      int taskNameHash) {
    super(
        ctx,
        nodeId,
        xidVer,
        commitVer,
        sys,
        plc,
        concurrency,
        isolation,
        invalidate,
        timeout,
        txSize,
        subjId,
        taskNameHash);

    assert nearNodeId != null;

    this.nearXidVer = nearXidVer;
    this.nearNodeId = nearNodeId;

    txState =
        new IgniteTxRemoteStateImpl(
            U.<IgniteTxKey, IgniteTxEntry>newLinkedHashMap(1),
            U.<IgniteTxKey, IgniteTxEntry>newLinkedHashMap(txSize));
  }
예제 #2
0
  /**
   * This constructor is meant for optimistic transactions.
   *
   * @param ldr Class loader.
   * @param nodeId Node ID.
   * @param nearNodeId Near node ID.
   * @param xidVer XID version.
   * @param commitVer Commit version.
   * @param sys System flag.
   * @param concurrency Concurrency level (should be pessimistic).
   * @param isolation Transaction isolation.
   * @param invalidate Invalidate flag.
   * @param timeout Timeout.
   * @param writeEntries Write entries.
   * @param ctx Cache registry.
   * @param txSize Expected transaction size.
   * @throws IgniteCheckedException If unmarshalling failed.
   */
  public GridNearTxRemote(
      GridCacheSharedContext ctx,
      ClassLoader ldr,
      UUID nodeId,
      UUID nearNodeId,
      GridCacheVersion xidVer,
      GridCacheVersion commitVer,
      boolean sys,
      byte plc,
      TransactionConcurrency concurrency,
      TransactionIsolation isolation,
      boolean invalidate,
      long timeout,
      Collection<IgniteTxEntry> writeEntries,
      int txSize,
      @Nullable UUID subjId,
      int taskNameHash)
      throws IgniteCheckedException {
    super(
        ctx,
        nodeId,
        xidVer,
        commitVer,
        sys,
        plc,
        concurrency,
        isolation,
        invalidate,
        timeout,
        txSize,
        subjId,
        taskNameHash);

    assert nearNodeId != null;

    this.nearNodeId = nearNodeId;

    int writeSize = writeEntries != null ? Math.max(txSize, writeEntries.size()) : txSize;

    txState =
        new IgniteTxRemoteStateImpl(
            Collections.<IgniteTxKey, IgniteTxEntry>emptyMap(),
            U.<IgniteTxKey, IgniteTxEntry>newLinkedHashMap(writeSize));

    if (writeEntries != null) {
      for (IgniteTxEntry entry : writeEntries) {
        entry.unmarshal(ctx, true, ldr);

        addEntry(entry);
      }
    }
  }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  public <M extends Map<?, ?>> M readMap(
      MessageCollectionItemType keyType,
      MessageCollectionItemType valType,
      boolean linked,
      MessageReader reader) {
    if (readSize == -1) {
      int size = readInt();

      if (!lastFinished) return null;

      readSize = size;
    }

    if (readSize >= 0) {
      if (map == null) map = linked ? U.newLinkedHashMap(readSize) : U.newHashMap(readSize);

      for (int i = readItems; i < readSize; i++) {
        if (!keyDone) {
          Object key = read(keyType, reader);

          if (!lastFinished) return null;

          mapCur = key;
          keyDone = true;
        }

        Object val = read(valType, reader);

        if (!lastFinished) return null;

        map.put(mapCur, val);

        keyDone = false;

        readItems++;
      }
    }

    readSize = -1;
    readItems = 0;
    mapCur = null;

    M map0 = (M) map;

    map = null;

    return map0;
  }