Skip to content

Instantly share code, notes, and snippets.

@xstefank
Created May 13, 2019 05:52
Show Gist options
  • Save xstefank/ae9b80a8d60486d342acb63c57874f82 to your computer and use it in GitHub Desktop.
Save xstefank/ae9b80a8d60486d342acb63c57874f82 to your computer and use it in GitHub Desktop.
package org.eclipse.microprofile.lra.tck.participant.nonjaxrs.valid;
import org.eclipse.microprofile.lra.annotation.Compensate;
import org.eclipse.microprofile.lra.annotation.ParticipantStatus;
import org.eclipse.microprofile.lra.annotation.Status;
import org.eclipse.microprofile.lra.annotation.ws.rs.LRA;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
@Path("non-jax-rs-participant")
public class NonJaxRsCompletionStage {
@GET
@Path("enlist")
@LRA(LRA.Type.REQUIRES_NEW)
public Response enlist(@HeaderParam(LRA.LRA_HTTP_CONTEXT_HEADER) String lraId) {
return Response.ok().build();
}
@Compensate
public CompletionStage<Optional<ParticipantStatus>> complete(URI lraId) {
return CompletableFuture.supplyAsync(() -> {
startDoingSomeBusinessWork(lraId);
return Optional.of(ParticipantStatus.Compensating);
});
}
@Status
public Optional<ParticipantStatus> status(URI lraId) {
if (checkBusinessWorkIsDone(lraId)) {
return Optional.of(ParticipantStatus.Compensated);
} else {
return Optional.of(ParticipantStatus.Compensating);
}
}
private void startDoingSomeBusinessWork(URI lraId) {
// intentionally empty
}
private boolean checkBusinessWorkIsDone(URI lraId) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment