Beispiel #1
0
    @SuppressWarnings({"UnusedDeclaration"})
    @PUT
    @Path("{pId}/{tId}/volatile-participant")
    public Response synchronizations(
        @PathParam("pId") @DefaultValue("") String pId,
        @PathParam("tId") @DefaultValue("") String tId,
        String content) {
      Work work = faults.get(pId);
      TxStatus txStatus;
      int vStatus;

      if (work == null) return Response.ok().build();

      txStatus = content != null ? TxStatus.fromStatus(content) : TxStatus.TransactionStatusUnknown;

      vStatus = txStatus.equals(TxStatus.TransactionStatusUnknown) ? 1 : 2;

      if (vStatus == 2 && work.vStatus == 0) {
        // afterCompletion but coordinator never called beforeCompletion
        return Response.status(HttpURLConnection.HTTP_BAD_REQUEST).build();
      }

      work.vStatus = vStatus;
      work.syncCount += 1;

      if (vStatus == 1 && "V_PREPARE".equals(work.fault))
        return Response.status(HttpURLConnection.HTTP_CONFLICT).build();
      else if (vStatus == 2 && "V_COMMIT".equals(work.fault))
        return Response.status(HttpURLConnection.HTTP_CONFLICT).build();

      return Response.ok().build();
    }
Beispiel #2
0
    @SuppressWarnings({"UnusedDeclaration"})
    @PUT
    @Path("{pId}/{tId}/terminator")
    public Response terminate(
        @PathParam("pId") @DefaultValue("") String pId,
        @PathParam("tId") @DefaultValue("") String tId,
        String content) {
      TxStatus status = TxSupport.toTxStatus(content);

      // String status = TxSupport.getStatus(content);
      Work work = faults.get(pId);

      if (work == null) return Response.status(HttpURLConnection.HTTP_NOT_FOUND).build();

      String fault = work.fault;

      if (status.isPrepare()) {
        if ("READONLY".equals(fault)) {
          //                    faults.remove(pId);
          work.status = TxStatus.TransactionReadOnly.name();
        } else if ("PREPARE_FAIL".equals(fault)) {
          //                    faults.remove(pId);
          return Response.status(HttpURLConnection.HTTP_CONFLICT).build();
          // throw new WebApplicationException(HttpURLConnection.HTTP_CONFLICT);
        } else {
          if ("PDELAY".equals(fault)) {
            try {
              Thread.sleep(2000);
            } catch (InterruptedException e) {
            }
          }
          work.status = TxStatus.TransactionPrepared.name();
        }
      } else if (status.isCommit() || status.isCommitOnePhase()) {
        if ("H_HAZARD".equals(fault)) work.status = TxStatus.TransactionHeuristicHazard.name();
        else if ("H_ROLLBACK".equals(fault))
          work.status = TxStatus.TransactionHeuristicRollback.name();
        else if ("H_MIXED".equals(fault)) work.status = TxStatus.TransactionHeuristicMixed.name();
        else {
          if ("CDELAY".equals(fault)) {
            try {
              Thread.sleep(3000);
            } catch (InterruptedException e) {
              // ok
            }
          }
          work.status =
              status.isCommitOnePhase()
                  ? TxStatus.TransactionCommittedOnePhase.name()
                  : TxStatus.TransactionCommitted.name();

          work.end(true);
        }
      } else if (status.isAbort()) {
        if ("H_HAZARD".equals(fault)) work.status = TxStatus.TransactionHeuristicHazard.name();
        else if ("H_COMMIT".equals(fault)) work.status = TxStatus.TransactionHeuristicCommit.name();
        else if ("H_MIXED".equals(fault)) work.status = TxStatus.TransactionHeuristicMixed.name();
        else {
          if ("ADELAY".equals(fault)) {
            try {
              Thread.sleep(2000);
            } catch (InterruptedException e) {
              // ok
            }
          }
          work.status = TxStatus.TransactionRolledBack.name();
          work.end(false);
          //                    faults.remove(pId);
        }
      } else {
        return Response.status(HttpURLConnection.HTTP_BAD_REQUEST).build();
        // throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST);
      }

      // return TxSupport.toStatusContent(work.status);
      return Response.ok(TxSupport.toStatusContent(work.status)).build();
    }
Beispiel #3
0
 public boolean inTxn() {
   return status != null && TxStatus.fromStatus(status).isActive();
   // return TxSupport.isActive(status);
 }