@Override
  public void reportHeuristic(String participantId, HeuristicType heuristicType) {
    final ParticipantInformation participantInformation =
        ParticipantsContainer.getInstance().getParticipantInformation(participantId);

    switch (heuristicType) {
      case HEURISTIC_ROLLBACK:
        participantInformation.setStatus(TxStatus.TransactionHeuristicRollback.name());
        break;

      case HEURISTIC_COMMIT:
        participantInformation.setStatus(TxStatus.TransactionHeuristicCommit.name());
        break;

      case HEURISTIC_HAZARD:
        participantInformation.setStatus(TxStatus.TransactionHeuristicHazard.name());
        break;

      case HEURISTIC_MIXED:
        participantInformation.setStatus(TxStatus.TransactionHeuristicMixed.name());
        break;

      default:
        throw new IllegalArgumentException("Unknown heuristic type");
    }

    RecoveryManager.getInstance().persistParticipantInformation(participantInformation);
  }
Пример #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();
    }