use of io.narayana.lra.participant.model.Activity 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.participant.model.Activity 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();
}
use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method compensateWork.
@PUT
@Path("/compensate")
@Produces(MediaType.APPLICATION_JSON)
@Compensate
public Response compensateWork(@HeaderParam(LRA_HTTP_HEADER) String lraId, String userData) throws NotFoundException {
compensatedCount.incrementAndGet();
assert lraId != null;
String txId = NarayanaLRAClient.getLRAId(lraId);
Activity activity = activityService.getActivity(txId);
activity.setEndData(userData);
if (activity.getAndDecrementAcceptCount() > 0) {
activity.status = CompensatorStatus.Compensating;
activity.statusUrl = String.format("%s/%s/%s/status", context.getBaseUri(), ACTIVITIES_PATH, txId);
return Response.accepted().location(URI.create(activity.statusUrl)).build();
}
activity.status = CompensatorStatus.Compensated;
activity.statusUrl = String.format("%s/%s/activity/compensated", context.getBaseUri(), txId);
System.out.printf("ActivityController compensating %s%n", txId);
return Response.ok(activity.statusUrl).build();
}
use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method forget.
@PUT
@Path("/{TxId}/forget")
public void forget(@PathParam("TxId") String txId) throws NotFoundException {
Activity activity = activityService.getActivity(txId);
activityService.remove(activity.id);
}
use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method compensate.
/**
* Performing a PUT on <participant URL>/compensate will cause the participant to compensate
* the work that was done within the scope of the transaction.
*
* The participant will either return a 200 OK code and a <status URL> which indicates the outcome and which can be probed (via GET)
* and will simply return the same (implicit) information:
*
* <URL>/cannot-compensate
* <URL>/cannot-complete
*/
@PUT
@Path("/{TxId}/compensate")
@Produces(MediaType.APPLICATION_JSON)
public Response compensate(@PathParam("TxId") String txId) throws NotFoundException {
Activity activity = activityService.getActivity(txId);
activity.status = CompensatorStatus.Compensated;
activity.statusUrl = String.format("%s/%s/activity/compensated", context.getBaseUri(), txId);
return Response.ok(activity.statusUrl).build();
}
Aggregations