diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/ChoreographyChapter.java b/saga/src/main/java/com/iluwatar/saga/choreography/ChoreographyChapter.java index caa377a1e..c79a77a9a 100644 --- a/saga/src/main/java/com/iluwatar/saga/choreography/ChoreographyChapter.java +++ b/saga/src/main/java/com/iluwatar/saga/choreography/ChoreographyChapter.java @@ -20,6 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.saga.choreography; @@ -31,7 +32,7 @@ package com.iluwatar.saga.choreography; public interface ChoreographyChapter { /** - * In that case, every method is responsible to make a decision on what to do then + * In that case, every method is responsible to make a decision on what to do then. * * @param saga incoming saga * @return saga result @@ -39,6 +40,7 @@ public interface ChoreographyChapter { Saga execute(Saga saga); /** + * get name method. * @return service name. */ String getName(); diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/FlyBookingService.java b/saga/src/main/java/com/iluwatar/saga/choreography/FlyBookingService.java index 60b183be3..4a9b1e804 100644 --- a/saga/src/main/java/com/iluwatar/saga/choreography/FlyBookingService.java +++ b/saga/src/main/java/com/iluwatar/saga/choreography/FlyBookingService.java @@ -20,11 +20,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.saga.choreography; /** - * Class representing a service to book a fly + * Class representing a service to book a fly. */ public class FlyBookingService extends Service { public FlyBookingService(ServiceDiscoveryService service) { diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/HotelBookingService.java b/saga/src/main/java/com/iluwatar/saga/choreography/HotelBookingService.java index 0bbf1d3e3..ee623482e 100644 --- a/saga/src/main/java/com/iluwatar/saga/choreography/HotelBookingService.java +++ b/saga/src/main/java/com/iluwatar/saga/choreography/HotelBookingService.java @@ -20,11 +20,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.saga.choreography; /** - * Class representing a service to book a hotel + * Class representing a service to book a hotel. */ public class HotelBookingService extends Service { public HotelBookingService(ServiceDiscoveryService service) { diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/OrderService.java b/saga/src/main/java/com/iluwatar/saga/choreography/OrderService.java index 3a2c002b1..19586a5a3 100644 --- a/saga/src/main/java/com/iluwatar/saga/choreography/OrderService.java +++ b/saga/src/main/java/com/iluwatar/saga/choreography/OrderService.java @@ -20,6 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.saga.choreography; diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/Saga.java b/saga/src/main/java/com/iluwatar/saga/choreography/Saga.java index 35069b80f..b591adaf2 100644 --- a/saga/src/main/java/com/iluwatar/saga/choreography/Saga.java +++ b/saga/src/main/java/com/iluwatar/saga/choreography/Saga.java @@ -20,6 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.saga.choreography; import java.util.ArrayList; @@ -44,7 +45,7 @@ public class Saga { } /** - * get resuzlt of saga + * get resuzlt of saga. * * @return result of saga @see {@link SagaResult} */ @@ -59,7 +60,7 @@ public class Saga { } /** - * add chapter to saga + * add chapter to saga. * @param name chapter name * @return this */ @@ -69,7 +70,7 @@ public class Saga { } /** - * set value to last chapter + * set value to last chapter. * @param value invalue * @return this */ @@ -82,7 +83,7 @@ public class Saga { } /** - * get value from current chapter + * get value from current chapter. * @return value */ public Object getCurrentValue() { @@ -90,7 +91,7 @@ public class Saga { } /** - * set value to current chapter + * set value to current chapter. * @param value to set */ public void setCurrentValue(Object value) { @@ -98,7 +99,7 @@ public class Saga { } /** - * set status for current chapter + * set status for current chapter. * @param result to set */ public void setCurrentStatus(ChapterResult result) { @@ -143,8 +144,9 @@ public class Saga { return chapters.get(pos).isSuccess(); } - /*** - * Class presents a chapter status and incoming parameters(incoming parameter transforms to outcoming parameter) + /** + * Class presents a chapter status and incoming + * parameters(incoming parameter transforms to outcoming parameter). */ public static class Chapter { private String name; @@ -170,7 +172,7 @@ public class Saga { } /** - * set result + * set result. * @param result {@link ChapterResult} */ public void setResult(ChapterResult result) { @@ -178,7 +180,7 @@ public class Saga { } /** - * the result for chapter is good + * the result for chapter is good. * @return true if is good otherwise bad */ public boolean isSuccess() { @@ -188,14 +190,14 @@ public class Saga { /** - * result for chapter + * result for chapter. */ public enum ChapterResult { INIT, SUCCESS, ROLLBACK } /** - * result for saga + * result for saga. */ public enum SagaResult { PROGRESS, FINISHED, ROLLBACKED diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/SagaApplication.java b/saga/src/main/java/com/iluwatar/saga/choreography/SagaApplication.java index 3aeb8672c..d8844c864 100644 --- a/saga/src/main/java/com/iluwatar/saga/choreography/SagaApplication.java +++ b/saga/src/main/java/com/iluwatar/saga/choreography/SagaApplication.java @@ -20,25 +20,29 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package com.iluwatar.saga.choreography; +package com.iluwatar.saga.choreography; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This pattern is used in distributed services to perform a group of operations atomically. - * This is an analog of transaction in a database but in terms of microservices architecture this is executed + * This is an analog of transaction in a database but in terms + * of microservices architecture this is executed * in a distributed environment - *
- * A saga is a sequence of local transactions in a certain context. If one transaction fails for some reason, - * the saga executes compensating transactions(rollbacks) to undo the impact of the preceding transactions. - *
- * In this approach, there are no mediators or orchestrators services. + * + *
A saga is a sequence of local transactions in a certain context. + * If one transaction fails for some reason, + * the saga executes compensating transactions(rollbacks) + * to undo the impact of the preceding transactions. + * + *
In this approach, there are no mediators or orchestrators services. * All chapters are handled and moved by services manually. - *
- * The major difference with choreography saga is an ability to handle crashed services - * (otherwise in choreography services very hard to prevent a saga if one of them has been crashed) + * + *
The major difference with choreography saga is an ability to handle crashed services
+ * (otherwise in choreography services very hard to prevent a saga
+ * if one of them has been crashed)
*
* @see com.iluwatar.saga.choreography.Saga
* @see Service
@@ -47,7 +51,7 @@ public class SagaApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(SagaApplication.class);
/**
- * main method
+ * main method.
*/
public static void main(String[] args) {
ServiceDiscoveryService sd = serviceDiscovery();
diff --git a/saga/src/main/java/com/iluwatar/saga/choreography/Service.java b/saga/src/main/java/com/iluwatar/saga/choreography/Service.java
index a602b1147..2e932b528 100644
--- a/saga/src/main/java/com/iluwatar/saga/choreography/Service.java
+++ b/saga/src/main/java/com/iluwatar/saga/choreography/Service.java
@@ -20,15 +20,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+
package com.iluwatar.saga.choreography;
+import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.function.Supplier;
/**
- * Common abstraction class representing services
+ * Common abstraction class representing services.
* implementing a general contract @see {@link ChoreographyChapter}
*/
public abstract class Service implements ChoreographyChapter {
@@ -73,13 +74,15 @@ public abstract class Service implements ChoreographyChapter {
}
private Supplier
- * A saga is a sequence of local transactions in a certain context. If one transaction fails for some reason,
- * the saga executes compensating transactions(rollbacks) to undo the impact of the preceding transactions.
- *
- * In this approach, there is an orchestrator @see {@link SagaOrchestrator}
+ *
+ * A saga is a sequence of local transactions in a certain context.
+ * If one transaction fails for some reason,
+ * the saga executes compensating transactions(rollbacks)
+ * to undo the impact of the preceding transactions.
+ *
+ * In this approach, there is an orchestrator @see {@link SagaOrchestrator}
* that manages all the transactions and directs
* the participant services to execute local transactions based on events.
* The major difference with choreography saga is an ability to handle crashed services
- * (otherwise in choreography services very hard to prevent a saga if one of them has been crashed)
+ * (otherwise in choreography services very hard to prevent a saga
+ * if one of them has been crashed)
*
* @see Saga
* @see SagaOrchestrator
@@ -49,7 +53,7 @@ public class SagaApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(SagaApplication.class);
/**
- * method to show common saga logic
+ * method to show common saga logic.
*/
public static void main(String[] args) {
SagaOrchestrator sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
@@ -58,7 +62,8 @@ public class SagaApplication {
Saga.Result badOrder = sagaOrchestrator.execute("bad_order");
Saga.Result crashedOrder = sagaOrchestrator.execute("crashed_order");
- LOGGER.info("orders: goodOrder is {}, badOrder is {},crashedOrder is {}", goodOrder, badOrder, crashedOrder);
+ LOGGER.info("orders: goodOrder is {}, badOrder is {},crashedOrder is {}",
+ goodOrder, badOrder, crashedOrder);
}
diff --git a/saga/src/main/java/com/iluwatar/saga/orchestration/SagaOrchestrator.java b/saga/src/main/java/com/iluwatar/saga/orchestration/SagaOrchestrator.java
index 2f25ebd46..beec37655 100644
--- a/saga/src/main/java/com/iluwatar/saga/orchestration/SagaOrchestrator.java
+++ b/saga/src/main/java/com/iluwatar/saga/orchestration/SagaOrchestrator.java
@@ -20,14 +20,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+
package com.iluwatar.saga.orchestration;
+import static com.iluwatar.saga.orchestration.Saga.Result.CRASHED;
+import static com.iluwatar.saga.orchestration.Saga.Result.FINISHED;
+import static com.iluwatar.saga.orchestration.Saga.Result.ROLLBACK;
+
+import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Optional;
-
-import static com.iluwatar.saga.orchestration.Saga.Result.*;
/**
* The orchestrator that manages all the transactions and directs
@@ -41,7 +44,7 @@ public class SagaOrchestrator {
/**
- * Create a new service to orchetrate sagas
+ * Create a new service to orchetrate sagas.
* @param saga saga to process
* @param sd service discovery @see {@link ServiceDiscoveryService}
*/
@@ -52,7 +55,7 @@ public class SagaOrchestrator {
}
/**
- * pipeline to execute saga process/story
+ * pipeline to execute saga process/story.
*
* @param value incoming value
* @param