|
32 | 32 | import jakarta.ws.rs.core.Response; |
33 | 33 | import jakarta.ws.rs.core.UriBuilder; |
34 | 34 |
|
| 35 | +import org.eclipse.microprofile.config.Config; |
| 36 | +import org.eclipse.microprofile.config.ConfigProvider; |
35 | 37 | import org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService; |
36 | 38 | import org.jboss.logging.Logger; |
37 | 39 |
|
38 | 40 | import io.narayana.lra.LRAConstants; |
39 | 41 |
|
40 | 42 | public class NarayanaLRARecovery implements LRARecoveryService { |
41 | 43 | private static final Logger log = Logger.getLogger(NarayanaLRARecovery.class); |
| 44 | + private static final long WAIT_CALLBACK_TIMEOUT = initWaitForCallbackTimeout(); |
| 45 | + private static final String WAIT_CALLBACK_TIMEOUT_PROPERTY = "lra.tck.callback.timeout"; |
| 46 | + private static final int DEFAULT_CALLBACK_TIMEOUT = 1000; |
42 | 47 |
|
| 48 | + /* |
| 49 | + * Wait for the participant to return the callback. This method does not |
| 50 | + * guarantee callbacks to finish. The Participant status is not immediately |
| 51 | + * reflected to the LRA status, but only after a recovery scan which executes an |
| 52 | + * enlistment. The waiting time can be configurable by |
| 53 | + * lra.tck.callback.timeout property. |
| 54 | + */ |
43 | 55 | @Override |
44 | 56 | public void waitForCallbacks(URI lraId) { |
45 | | - // no action needed |
| 57 | + log.trace("waitForCallbacks for: " + lraId.toASCIIString()); |
| 58 | + try { |
| 59 | + Thread.sleep(WAIT_CALLBACK_TIMEOUT); |
| 60 | + } catch (InterruptedException e) { |
| 61 | + log.error("waitForCallbacks interrupted by " + e.getMessage()); |
| 62 | + } |
46 | 63 | } |
47 | 64 |
|
48 | 65 | @Override |
@@ -83,4 +100,17 @@ private boolean recoverLRAs(URI lraId) { |
83 | 100 | recoveryCoordinatorClient.close(); |
84 | 101 | } |
85 | 102 | } |
| 103 | + |
| 104 | + private static Integer initWaitForCallbackTimeout() { |
| 105 | + Config config = ConfigProvider.getConfig(); |
| 106 | + if (config != null) { |
| 107 | + try { |
| 108 | + return config.getOptionalValue(WAIT_CALLBACK_TIMEOUT_PROPERTY, Integer.class).orElse(DEFAULT_CALLBACK_TIMEOUT); |
| 109 | + } catch (IllegalArgumentException e) { |
| 110 | + log.error("property " + WAIT_CALLBACK_TIMEOUT_PROPERTY + " not set correctly, using the default value: " |
| 111 | + + DEFAULT_CALLBACK_TIMEOUT); |
| 112 | + } |
| 113 | + } |
| 114 | + return DEFAULT_CALLBACK_TIMEOUT; |
| 115 | + } |
86 | 116 | } |
0 commit comments