Skip to content

Commit f831b40

Browse files
authored
Merge pull request #10 from kivo2/clean-comments
Clean comments
2 parents 4a47c21 + f781f31 commit f831b40

34 files changed

Lines changed: 3 additions & 411 deletions

File tree

common/src/main/java/com/example/common/enums/SagaStatus.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
package com.example.common.enums;
22

3-
/**
4-
* Lifecycle states for a Saga workflow instance.
5-
*
6-
* <p>State transitions:
7-
*
8-
* <p>STARTED → RUNNING → COMPLETED ↘ FAILED (permanent business failure — no retry) ↘ PENDING_RETRY
9-
* (transient failure — will retry) ↘ PERMANENTLY_FAILED (max retries exhausted)
10-
*
11-
* <p>KEY DISTINCTION: FAILED = business rule prevented completion (out of stock, card declined) No
12-
* retry — retrying won't help PERMANENTLY_FAILED = transient failure exhausted all retries Needs
13-
* manual intervention or customer action PENDING_RETRY = transient failure, retry scheduled at
14-
* next_retry_at
15-
*/
163
public enum SagaStatus {
174
STARTED,
185
RUNNING,

common/src/main/java/com/example/common/enums/SagaStep.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package com.example.common.enums;
22

3-
/**
4-
* Ordered steps in the checkout workflow.
5-
*
6-
* <p>Forward steps (Phase 1-3): RESERVE_INVENTORY → AUTHORIZE_PAYMENT → CREATE_ORDER → COMPLETED
7-
*
8-
* <p>Compensating steps (Phase 4): RELEASE_INVENTORY, REFUND_PAYMENT, CANCEL_ORDER
9-
*/
103
public enum SagaStep {
114
// Forward steps
125
RESERVE_INVENTORY,
@@ -17,7 +10,7 @@ public enum SagaStep {
1710
COMPLETED,
1811
FAILED,
1912

20-
// Compensating steps (Phase 4)
13+
// Compensating steps
2114
RELEASE_INVENTORY,
2215
REFUND_PAYMENT,
2316
CANCEL_ORDER

common/src/main/java/com/example/common/exceptions/DuplicateOrderException.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
import java.util.UUID;
44

5-
/**
6-
* Thrown when an order already exists for this saga in a conflicting state.
7-
*
8-
* <p>NOTE: This is different from idempotency. Idempotency means: "I already did this work
9-
* successfully, here's the result." DuplicateOrderException means: "An order exists for this saga
10-
* but something is wrong."
11-
*
12-
* <p>FAILURE SCENARIO: "Order creation fails (duplicate order)"
13-
*/
145
public class DuplicateOrderException extends PermanentWorkerException {
156

167
public DuplicateOrderException(UUID sagaId) {

common/src/main/java/com/example/common/exceptions/InsufficientStockException.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Thrown when requested quantity exceeds available stock.
5-
*
6-
* <p>PERMANENT failure — retrying won't restock the warehouse.
7-
*
8-
* <p>FAILURE SCENARIO: "Inventory check fails (out of stock)" FAILURE SCENARIO: "Inventory
9-
* partially available (some items in stock, some not)"
10-
*
11-
* <p>The message should identify which product(s) failed and why. Example: "Insufficient stock for
12-
* prod_1: requested=5, available=2"
13-
*/
143
public class InsufficientStockException extends PermanentWorkerException {
154

165
public InsufficientStockException(String productId, int requested, int available) {

common/src/main/java/com/example/common/exceptions/PaymentDeclinedException.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Thrown when a payment is declined by the payment provider.
5-
*
6-
* <p>PERMANENT failure — retrying a declined card won't approve it. The customer needs to use a
7-
* different payment method.
8-
*
9-
* <p>FAILURE SCENARIO: "Payment declined (insufficient funds)"
10-
*
11-
* <p>Simulate by using token: "tok_declined"
12-
*/
133
public class PaymentDeclinedException extends PermanentWorkerException {
144

155
public PaymentDeclinedException(String token) {

common/src/main/java/com/example/common/exceptions/PermanentWorkerException.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Permanent failure — retrying will NOT help.
5-
*
6-
* <p>When the orchestrator catches this, it marks the saga FAILED immediately. No retry is
7-
* scheduled. The customer needs to take action.
8-
*
9-
* <p>Subclasses: InsufficientStockException, PaymentDeclinedException, DuplicateOrderException
10-
*/
113
public class PermanentWorkerException extends WorkerException {
124

135
public PermanentWorkerException(String message) {

common/src/main/java/com/example/common/exceptions/TransientWorkerException.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Transient failure — retrying MAY help.
5-
*
6-
* <p>When the orchestrator catches this, it schedules a retry with exponential backoff. If max
7-
* retries are exhausted, the saga moves to PERMANENTLY_FAILED.
8-
*
9-
* <p>Use this for: DB timeouts, network blips, service temporarily unavailable, any infrastructure
10-
* failure that is expected to resolve on its own.
11-
*/
123
public class TransientWorkerException extends WorkerException {
134

145
public TransientWorkerException(String message) {

common/src/main/java/com/example/common/exceptions/WorkerException.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Base class for all worker exceptions.
5-
*
6-
* <p>FAILURE TYPE TAXONOMY:
7-
*
8-
* <p>PermanentWorkerException (extends this) → Business rule failure. Retrying will NOT help. →
9-
* Examples: out of stock, card declined, duplicate order → Orchestrator action: mark saga FAILED
10-
* immediately
11-
*
12-
* <p>TransientWorkerException (extends this) → Temporary infrastructure failure. Retrying MAY help.
13-
* → Examples: DB connection timeout, network blip, service unavailable → Orchestrator action:
14-
* schedule retry with exponential backoff
15-
*
16-
* <p>This distinction is the core of Phase 2 retry semantics. Getting it wrong means either: -
17-
* Retrying a declined card (wastes time, confuses customer) - Not retrying a DB timeout (loses a
18-
* valid checkout)
19-
*/
203
public abstract class WorkerException extends RuntimeException {
214

225
protected WorkerException(String message) {

common/src/main/java/com/example/common/interfaces/InventoryWorker.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@
55

66
import com.example.common.dto.StartCheckoutRequest;
77

8-
/**
9-
* Contract for the Inventory Worker.
10-
*
11-
* <p>Phase 2: Implemented as a direct Spring bean call (in-process). Phase 3a: Implemented as a
12-
* Kafka command/event exchange.
13-
*
14-
* <p>The contract stays the same across phases — only the transport changes.
15-
*
16-
* <p>IDEMPOTENCY CONTRACT: If reserveInventory is called twice with the same sagaId, the second
17-
* call MUST be a no-op. It should detect the existing reservation and return without modifying
18-
* inventory quantities a second time.
19-
*
20-
* <p>ATOMICITY CONTRACT: Either ALL items are reserved or NONE are. Never partially reserve. Check
21-
* all items first, then reserve all if possible.
22-
*/
238
public interface InventoryWorker {
249

2510
/**

common/src/main/java/com/example/common/interfaces/OrderWorker.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55

66
import com.example.common.dto.StartCheckoutRequest;
77

8-
/**
9-
* Contract for the Order Worker.
10-
*
11-
* <p>Phase 2: Direct Spring bean call. Phase 3a: Kafka command/event exchange.
12-
*
13-
* <p>IDEMPOTENCY CONTRACT: If createOrder is called twice with the same sagaId, the second call
14-
* returns the existing orderId without creating a duplicate order record.
15-
*/
168
public interface OrderWorker {
179

1810
/**

0 commit comments

Comments
 (0)