Skip to content

Commit 87af122

Browse files
author
Besok
committed
add changes according to google style
1 parent de56cbb commit 87af122

20 files changed

+98
-62
lines changed

saga/src/main/java/com/iluwatar/saga/choreography/ChoreographyChapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.choreography;
2425

2526

@@ -31,14 +32,15 @@
3132
public interface ChoreographyChapter {
3233

3334
/**
34-
* In that case, every method is responsible to make a decision on what to do then
35+
* In that case, every method is responsible to make a decision on what to do then.
3536
*
3637
* @param saga incoming saga
3738
* @return saga result
3839
*/
3940
Saga execute(Saga saga);
4041

4142
/**
43+
* get name method.
4244
* @return service name.
4345
*/
4446
String getName();

saga/src/main/java/com/iluwatar/saga/choreography/FlyBookingService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.choreography;
2425

2526

2627
/**
27-
* Class representing a service to book a fly
28+
* Class representing a service to book a fly.
2829
*/
2930
public class FlyBookingService extends Service {
3031
public FlyBookingService(ServiceDiscoveryService service) {

saga/src/main/java/com/iluwatar/saga/choreography/HotelBookingService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.choreography;
2425

2526

2627
/**
27-
* Class representing a service to book a hotel
28+
* Class representing a service to book a hotel.
2829
*/
2930
public class HotelBookingService extends Service {
3031
public HotelBookingService(ServiceDiscoveryService service) {

saga/src/main/java/com/iluwatar/saga/choreography/OrderService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.choreography;
2425

2526

saga/src/main/java/com/iluwatar/saga/choreography/Saga.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.choreography;
2425

2526
import java.util.ArrayList;
@@ -44,7 +45,7 @@ public static Saga create() {
4445
}
4546

4647
/**
47-
* get resuzlt of saga
48+
* get resuzlt of saga.
4849
*
4950
* @return result of saga @see {@link SagaResult}
5051
*/
@@ -59,7 +60,7 @@ public SagaResult getResult() {
5960
}
6061

6162
/**
62-
* add chapter to saga
63+
* add chapter to saga.
6364
* @param name chapter name
6465
* @return this
6566
*/
@@ -69,7 +70,7 @@ public Saga chapter(String name) {
6970
}
7071

7172
/**
72-
* set value to last chapter
73+
* set value to last chapter.
7374
* @param value invalue
7475
* @return this
7576
*/
@@ -82,23 +83,23 @@ public Saga setInValue(Object value) {
8283
}
8384

8485
/**
85-
* get value from current chapter
86+
* get value from current chapter.
8687
* @return value
8788
*/
8889
public Object getCurrentValue() {
8990
return chapters.get(pos).getInValue();
9091
}
9192

9293
/**
93-
* set value to current chapter
94+
* set value to current chapter.
9495
* @param value to set
9596
*/
9697
public void setCurrentValue(Object value) {
9798
chapters.get(pos).setInValue(value);
9899
}
99100

100101
/**
101-
* set status for current chapter
102+
* set status for current chapter.
102103
* @param result to set
103104
*/
104105
public void setCurrentStatus(ChapterResult result) {
@@ -143,8 +144,9 @@ boolean isCurrentSuccess() {
143144
return chapters.get(pos).isSuccess();
144145
}
145146

146-
/***
147-
* Class presents a chapter status and incoming parameters(incoming parameter transforms to outcoming parameter)
147+
/**
148+
* Class presents a chapter status and incoming
149+
* parameters(incoming parameter transforms to outcoming parameter).
148150
*/
149151
public static class Chapter {
150152
private String name;
@@ -170,15 +172,15 @@ public String getName() {
170172
}
171173

172174
/**
173-
* set result
175+
* set result.
174176
* @param result {@link ChapterResult}
175177
*/
176178
public void setResult(ChapterResult result) {
177179
this.result = result;
178180
}
179181

180182
/**
181-
* the result for chapter is good
183+
* the result for chapter is good.
182184
* @return true if is good otherwise bad
183185
*/
184186
public boolean isSuccess() {
@@ -188,14 +190,14 @@ public boolean isSuccess() {
188190

189191

190192
/**
191-
* result for chapter
193+
* result for chapter.
192194
*/
193195
public enum ChapterResult {
194196
INIT, SUCCESS, ROLLBACK
195197
}
196198

197199
/**
198-
* result for saga
200+
* result for saga.
199201
*/
200202
public enum SagaResult {
201203
PROGRESS, FINISHED, ROLLBACKED

saga/src/main/java/com/iluwatar/saga/choreography/SagaApplication.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,29 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23-
package com.iluwatar.saga.choreography;
2423

24+
package com.iluwatar.saga.choreography;
2525

2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
3030
* This pattern is used in distributed services to perform a group of operations atomically.
31-
* This is an analog of transaction in a database but in terms of microservices architecture this is executed
31+
* This is an analog of transaction in a database but in terms
32+
* of microservices architecture this is executed
3233
* in a distributed environment
33-
* <p>
34-
* A saga is a sequence of local transactions in a certain context. If one transaction fails for some reason,
35-
* the saga executes compensating transactions(rollbacks) to undo the impact of the preceding transactions.
36-
* <p>
37-
* In this approach, there are no mediators or orchestrators services.
34+
*
35+
* <p>A saga is a sequence of local transactions in a certain context.
36+
* If one transaction fails for some reason,
37+
* the saga executes compensating transactions(rollbacks)
38+
* to undo the impact of the preceding transactions.
39+
*
40+
* <p>In this approach, there are no mediators or orchestrators services.
3841
* All chapters are handled and moved by services manually.
39-
* <p>
40-
* The major difference with choreography saga is an ability to handle crashed services
41-
* (otherwise in choreography services very hard to prevent a saga if one of them has been crashed)
42+
*
43+
* <p>The major difference with choreography saga is an ability to handle crashed services
44+
* (otherwise in choreography services very hard to prevent a saga
45+
* if one of them has been crashed)
4246
*
4347
* @see com.iluwatar.saga.choreography.Saga
4448
* @see Service
@@ -47,7 +51,7 @@ public class SagaApplication {
4751
private static final Logger LOGGER = LoggerFactory.getLogger(SagaApplication.class);
4852

4953
/**
50-
* main method
54+
* main method.
5155
*/
5256
public static void main(String[] args) {
5357
ServiceDiscoveryService sd = serviceDiscovery();

saga/src/main/java/com/iluwatar/saga/choreography/Service.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.choreography;
2425

26+
import java.util.function.Supplier;
2527
import org.slf4j.Logger;
2628
import org.slf4j.LoggerFactory;
2729

28-
import java.util.function.Supplier;
2930

3031
/**
31-
* Common abstraction class representing services
32+
* Common abstraction class representing services.
3233
* implementing a general contract @see {@link ChoreographyChapter}
3334
*/
3435
public abstract class Service implements ChoreographyChapter {
@@ -73,13 +74,15 @@ public Saga execute(Saga saga) {
7374
}
7475

7576
private Supplier<RuntimeException> serviceNotFoundException(String chServiceName) {
76-
return () -> new RuntimeException(String.format("the service %s has not been found", chServiceName));
77+
return () -> new RuntimeException(
78+
String.format("the service %s has not been found", chServiceName));
7779
}
7880

7981
@Override
8082
public Saga process(Saga saga) {
8183
Object inValue = saga.getCurrentValue();
82-
LOGGER.info("The chapter '{}' has been started. The data {} has been stored or calculated successfully",
84+
LOGGER.info("The chapter '{}' has been started. "
85+
+ "The data {} has been stored or calculated successfully",
8386
getName(), inValue);
8487
saga.setCurrentStatus(Saga.ChapterResult.SUCCESS);
8588
saga.setCurrentValue(inValue);
@@ -89,7 +92,8 @@ public Saga process(Saga saga) {
8992
@Override
9093
public Saga rollback(Saga saga) {
9194
Object inValue = saga.getCurrentValue();
92-
LOGGER.info("The Rollback for a chapter '{}' has been started. The data {} has been rollbacked successfully",
95+
LOGGER.info("The Rollback for a chapter '{}' has been started. "
96+
+ "The data {} has been rollbacked successfully",
9397
getName(), inValue);
9498

9599
saga.setCurrentStatus(Saga.ChapterResult.ROLLBACK);

saga/src/main/java/com/iluwatar/saga/choreography/ServiceDiscoveryService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23-
package com.iluwatar.saga.choreography;
2423

24+
package com.iluwatar.saga.choreography;
2525

2626
import java.util.HashMap;
2727
import java.util.Map;
@@ -35,7 +35,7 @@ public class ServiceDiscoveryService {
3535
private Map<String, ChoreographyChapter> services;
3636

3737
/**
38-
* find any service
38+
* find any service.
3939
*
4040
* @return any service
4141
* @throws NoSuchElementException if no elements further

saga/src/main/java/com/iluwatar/saga/choreography/WithdrawMoneyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23-
package com.iluwatar.saga.choreography;
2423

24+
package com.iluwatar.saga.choreography;
2525

2626
/**
27-
* Class representing a service to withdraw a money
27+
* Class representing a service to withdraw a money.
2828
*/
2929
public class WithdrawMoneyService extends Service {
3030

saga/src/main/java/com/iluwatar/saga/orchestration/ChapterResult.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.orchestration;
2425

2526
/**
26-
* Executing result for chapter
27+
* Executing result for chapter.
2728
*
2829
* @param <K> incoming value
2930
*/
@@ -53,7 +54,7 @@ public static <K> ChapterResult<K> failure(K val) {
5354
}
5455

5556
/**
56-
* state for chapter
57+
* state for chapter.
5758
*/
5859
public enum State {
5960
SUCCESS, FAILURE

saga/src/main/java/com/iluwatar/saga/orchestration/FlyBookingService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.orchestration;
2425

2526
/**
26-
* Class representing a service to book a fly
27+
* Class representing a service to book a fly.
2728
*/
2829
public class FlyBookingService extends Service<String> {
2930
@Override

saga/src/main/java/com/iluwatar/saga/orchestration/HotelBookingService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.orchestration;
2425

2526
/**
26-
* Class representing a service to book a hotel
27+
* Class representing a service to book a hotel.
2728
*/
2829
public class HotelBookingService extends Service<String> {
2930
@Override
@@ -42,7 +43,8 @@ public ChapterResult<String> rollback(String value) {
4243
return ChapterResult.failure(value);
4344
}
4445

45-
LOGGER.info("The Rollback for a chapter '{}' has been started. The data {} has been rollbacked successfully",
46+
LOGGER.info("The Rollback for a chapter '{}' has been started. "
47+
+ "The data {} has been rollbacked successfully",
4648
getName(), value);
4749

4850
return super.rollback(value);

saga/src/main/java/com/iluwatar/saga/orchestration/OrchestrationChapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.orchestration;
2425

2526
/**
@@ -30,6 +31,7 @@
3031
public interface OrchestrationChapter<K> {
3132

3233
/**
34+
* method get name.
3335
* @return service name.
3436
*/
3537
String getName();

saga/src/main/java/com/iluwatar/saga/orchestration/OrderService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.saga.orchestration;
2425

2526
/**

0 commit comments

Comments
 (0)