separate pkgs
This commit is contained in:
parent
1b32e23493
commit
ffeee2f1a4
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
* Copyright © 2014-2019 Ilkka Seppälä
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.iluwatar.saga.choreography;
|
|
||||||
|
|
||||||
import com.iluwatar.saga.orchestration.ChapterResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chapter is an interface representing a contract for an external service.
|
|
||||||
* @param <K> is type for passing params
|
|
||||||
*/
|
|
||||||
public interface Chapter<K> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return service name.
|
|
||||||
*/
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* every chapter is responsible for a part of saga.
|
|
||||||
* @param value incoming value
|
|
||||||
* @return saga result @see {@link RichSaga}
|
|
||||||
*/
|
|
||||||
RichSaga<K> execute(K value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The operation executed in general case.
|
|
||||||
* @param value incoming value
|
|
||||||
* @return result {@link ChapterResult}
|
|
||||||
*/
|
|
||||||
ChapterResult<K> process(K value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The operation executed in rollback case.
|
|
||||||
* @param value incoming value
|
|
||||||
* @return result {@link ChapterResult}
|
|
||||||
*/
|
|
||||||
ChapterResult<K> rollback(K value);
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package com.iluwatar.saga.choreography;
|
|
||||||
|
|
||||||
import com.iluwatar.saga.ServiceDiscoveryService;
|
|
||||||
import com.iluwatar.saga.orchestration.Chapter;
|
|
||||||
import com.iluwatar.saga.orchestration.ChapterResult;
|
|
||||||
import com.iluwatar.saga.orchestration.OrchestrationService;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public abstract class ChoreographyService<K> implements Chapter<K> {
|
|
||||||
|
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(OrchestrationService.class);
|
|
||||||
|
|
||||||
private final ServiceDiscoveryService service;
|
|
||||||
protected ChoreographyService(ServiceDiscoveryService service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChapterResult<K> process(K value) {
|
|
||||||
logger.info("The chapter '{}' has been started. The data {} has been stored or calculated successfully",
|
|
||||||
getName(),value);
|
|
||||||
return ChapterResult.success(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChapterResult<K> rollback(K value) {
|
|
||||||
logger.info("The Rollback for a chapter '{}' has been started. The data {} has been rollbacked successfully",
|
|
||||||
getName(),value);
|
|
||||||
return ChapterResult.success(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package com.iluwatar.saga.choreography;
|
|
||||||
|
|
||||||
public class RichSaga<K> {
|
|
||||||
}
|
|
@ -25,7 +25,7 @@ package com.iluwatar.saga.orchestration;
|
|||||||
/**
|
/**
|
||||||
* Class representing a service to book a fly
|
* Class representing a service to book a fly
|
||||||
*/
|
*/
|
||||||
public class FlyBookingService extends OrchestrationService<String> {
|
public class FlyBookingService extends Service<String> {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "booking a Fly";
|
return "booking a Fly";
|
||||||
|
@ -25,7 +25,7 @@ package com.iluwatar.saga.orchestration;
|
|||||||
/**
|
/**
|
||||||
* Class representing a service to book a hotel
|
* Class representing a service to book a hotel
|
||||||
*/
|
*/
|
||||||
public class HotelBookingService extends OrchestrationService<String> {
|
public class HotelBookingService extends Service<String> {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "booking a Hotel";
|
return "booking a Hotel";
|
||||||
|
@ -25,7 +25,7 @@ package com.iluwatar.saga.orchestration;
|
|||||||
/**
|
/**
|
||||||
* Class representing a service to init a new order.
|
* Class representing a service to init a new order.
|
||||||
*/
|
*/
|
||||||
public class OrderService extends OrchestrationService<String> {
|
public class OrderService extends Service<String> {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "init an order";
|
return "init an order";
|
||||||
|
@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @see Saga
|
* @see Saga
|
||||||
* @see SagaOrchestrator
|
* @see SagaOrchestrator
|
||||||
* @see OrchestrationService
|
* @see Service
|
||||||
*/
|
*/
|
||||||
public class SagaApplication {
|
public class SagaApplication {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SagaApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(SagaApplication.class);
|
||||||
|
@ -30,8 +30,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
* implementing a general contract @see {@link Chapter}
|
* implementing a general contract @see {@link Chapter}
|
||||||
* @param <K> type of incoming param
|
* @param <K> type of incoming param
|
||||||
*/
|
*/
|
||||||
public abstract class OrchestrationService<K> implements Chapter<K> {
|
public abstract class Service<K> implements Chapter<K> {
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(OrchestrationService.class);
|
protected static final Logger logger = LoggerFactory.getLogger(Service.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract String getName();
|
public abstract String getName();
|
@ -25,7 +25,7 @@ package com.iluwatar.saga.orchestration;
|
|||||||
/**
|
/**
|
||||||
* Class representing a service to withdraw a money
|
* Class representing a service to withdraw a money
|
||||||
*/
|
*/
|
||||||
public class WithdrawMoneyService extends OrchestrationService<String> {
|
public class WithdrawMoneyService extends Service<String> {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "withdrawing Money";
|
return "withdrawing Money";
|
||||||
|
@ -39,7 +39,7 @@ public class SagaOrchestratorInternallyTest {
|
|||||||
.discover(new Service4());
|
.discover(new Service4());
|
||||||
}
|
}
|
||||||
|
|
||||||
class Service1 extends OrchestrationService<Integer> {
|
class Service1 extends Service<Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -59,7 +59,7 @@ public class SagaOrchestratorInternallyTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Service2 extends OrchestrationService<Integer> {
|
class Service2 extends Service<Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -78,7 +78,7 @@ public class SagaOrchestratorInternallyTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Service3 extends OrchestrationService<Integer> {
|
class Service3 extends Service<Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -97,7 +97,7 @@ public class SagaOrchestratorInternallyTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Service4 extends OrchestrationService<Integer> {
|
class Service4 extends Service<Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user