use of io.narayana.lra.annotation.LRA in project narayana by jbosstm.
the class ActivityController method status.
/**
* Performing a GET on the participant URL will return the current status of the participant {@link CompensatorStatus}, or 404 if the participant is no longer present.
*/
@GET
@Path("/status")
@Produces(MediaType.APPLICATION_JSON)
@Status
@LRA(LRA.Type.NOT_SUPPORTED)
public Response status(@PathParam("LraUrl") String lraUrl, @HeaderParam(LRA_HTTP_HEADER) String lraId) throws NotFoundException {
String txId = NarayanaLRAClient.getLRAId(lraId);
Activity activity = activityService.getActivity(txId);
if (activity.status == null)
throw new IllegalLRAStateException(lraId, "LRA is not active", "getStatus");
if (activity.getAndDecrementAcceptCount() <= 0) {
if (activity.status == CompensatorStatus.Completing)
activity.status = CompensatorStatus.Completed;
else if (activity.status == CompensatorStatus.Compensating)
activity.status = CompensatorStatus.Compensated;
}
return Response.ok(activity.status.name()).build();
}
use of io.narayana.lra.annotation.LRA in project narayana by jbosstm.
the class ActivityController method extendTimeLimit.
@GET
@Path("/renewTimeLimit")
@Produces(MediaType.APPLICATION_JSON)
@TimeLimit(limit = 100, unit = TimeUnit.MILLISECONDS)
@LRA(value = LRA.Type.REQUIRED)
public Response extendTimeLimit(@HeaderParam(LRA_HTTP_HEADER) String lraId) {
activityService.add(new Activity(NarayanaLRAClient.getLRAId(lraId)));
try {
/*
* the incomming LRA was created with a timeLimit of 100 ms via the @TimeLimit annotation
* update the timeLimit to 300
* sleep for 200
* return from the method so the LRA will have been running for 200 ms so it should not be cancelled
*/
lraClient.renewTimeLimit(NarayanaLRAClient.lraToURL(lraId), 300, TimeUnit.MILLISECONDS);
// sleep for 200000 micro seconds (should be longer than specified in the @TimeLimit annotation)
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
return Response.status(Response.Status.OK).entity(Entity.text("Simulate buisiness logic timeoout")).build();
}
use of io.narayana.lra.annotation.LRA in project narayana by jbosstm.
the class ActivityController method multiLevelNestedActivity.
@PUT
@Path("/multiLevelNestedActivity")
@LRA(LRA.Type.MANDATORY)
public Response multiLevelNestedActivity(@HeaderParam(LRA_HTTP_RECOVERY_HEADER) String rcvId, @HeaderParam(LRA_HTTP_HEADER) String nestedLRAId, @QueryParam("nestedCnt") @DefaultValue("1") Integer nestedCnt) {
assert nestedLRAId != null;
Activity activity = addWork(nestedLRAId, rcvId);
if (activity == null)
return Response.status(Response.Status.EXPECTATION_FAILED).entity("Missing lra data").build();
// invoke resources that enlist nested LRAs
String[] lras = new String[nestedCnt + 1];
lras[0] = nestedLRAId;
IntStream.range(1, lras.length).forEach(i -> lras[i] = restPutInvocation("nestedActivity", ""));
return Response.ok(String.join(",", lras)).build();
}
Aggregations