Search in sources :

Example 6 with LRA

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();
}
Also used : Activity(io.narayana.lra.participant.model.Activity) IllegalLRAStateException(io.narayana.lra.client.IllegalLRAStateException) Path(javax.ws.rs.Path) Status(io.narayana.lra.annotation.Status) CompensatorStatus(io.narayana.lra.annotation.CompensatorStatus) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LRA(io.narayana.lra.annotation.LRA) NestedLRA(io.narayana.lra.annotation.NestedLRA)

Example 7 with LRA

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();
}
Also used : Activity(io.narayana.lra.participant.model.Activity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LRA(io.narayana.lra.annotation.LRA) NestedLRA(io.narayana.lra.annotation.NestedLRA) TimeLimit(io.narayana.lra.annotation.TimeLimit)

Example 8 with LRA

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();
}
Also used : Activity(io.narayana.lra.participant.model.Activity) Path(javax.ws.rs.Path) LRA(io.narayana.lra.annotation.LRA) NestedLRA(io.narayana.lra.annotation.NestedLRA) PUT(javax.ws.rs.PUT)

Aggregations

LRA (io.narayana.lra.annotation.LRA)8 NestedLRA (io.narayana.lra.annotation.NestedLRA)7 Path (javax.ws.rs.Path)6 Status (io.narayana.lra.annotation.Status)4 Activity (io.narayana.lra.participant.model.Activity)4 PUT (javax.ws.rs.PUT)4 Forget (io.narayana.lra.annotation.Forget)3 Leave (io.narayana.lra.annotation.Leave)3 IllegalLRAStateException (io.narayana.lra.client.IllegalLRAStateException)3 Annotation (java.lang.annotation.Annotation)3 URL (java.net.URL)3 GET (javax.ws.rs.GET)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Compensate (io.narayana.lra.annotation.Compensate)2 Complete (io.narayana.lra.annotation.Complete)2 TimeLimit (io.narayana.lra.annotation.TimeLimit)2 GenericLRAException (io.narayana.lra.client.GenericLRAException)2 Method (java.lang.reflect.Method)2 URI (java.net.URI)2 Produces (javax.ws.rs.Produces)2