Skip to content

Commit

Permalink
issue35 Add CompletionStage as supported return type for participant …
Browse files Browse the repository at this point in the history
…methods

Signed-off-by: xstefank <[email protected]>
  • Loading branch information
xstefank committed May 4, 2019
1 parent 8fcca01 commit 0149782
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions spec/src/main/asciidoc/microprofile-lra-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ MUST adhere to these predefined signatures:
** <<source-ParticipantStatus,ParticipantStatus>>
** `javax.ws.rs.core.Response`: handled similarly as for
<<jaxrs-participant-methods, JAX-RS participant methods>>
** `java.util.concurrent.CompletionStage`: with the parameter of any of the previously
defined types
* *Arguments*: up to 2 arguments of types in this order:
** `java.net.URI`: representing current LRA context identification
** `java.net.URI`: representing potentional parent LRA context identification
Expand All @@ -652,10 +654,10 @@ Examples of valid signatures:
public void compensate(URI lraId, URI parentId)
@Complete
public Response complete()
public Response complete(URI lraId)
@Status
public ParticipantStatus status(URI lraId)
public CompletionStage<ParticipantStatus> status(URI lraId)
----

Examples of invalid signatures:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;

Expand Down Expand Up @@ -93,13 +95,15 @@ public void completeWithException(URI lraId, URI parentId) {
}

@Compensate
public ParticipantStatus compensate(URI lraId) {
verifyLRAId(lraId);
public CompletionStage<ParticipantStatus> compensate(URI lraId) {
return CompletableFuture.supplyAsync(() -> {
verifyLRAId(lraId);

compensatedCount.incrementAndGet();
compensatedCount.incrementAndGet();

LOGGER.info(String.format("LRA id '%s' was compensated", lraId));
return ParticipantStatus.Compensating;
LOGGER.info(String.format("LRA id '%s' was compensated", lraId));
return ParticipantStatus.Compensating;
});
}

@Status
Expand Down

0 comments on commit 0149782

Please sign in to comment.