Skip to content

Commit

Permalink
Adjusted variable names and added comments to make sample code easier…
Browse files Browse the repository at this point in the history
… to understand
  • Loading branch information
trimoq committed Jun 10, 2022
1 parent 2d54d51 commit c6140dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


/*
Creates an admin channel from the configuration. used to simplify testing in other components.
*/
@Component
public class ConfigBasedAdminChannel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/*
Extract the service using the specified method to reset the token.
This allows for cleaner signatures in the controllers and the services
*/
@Component
public class StringToEventProcessorServiceConverter implements Converter<String, EventProcessorService> {

final RestEventProcessorService restEventProcessorService;
final FrameworkEventProcessorService frameworkEventProcessorRestController;
final ServerConnectorEventProcessorService serverConnectorRestController;
final FrameworkEventProcessorService frameworkEventProcessorService;
final ServerConnectorEventProcessorService serverConnectorEventProcessorService;

public StringToEventProcessorServiceConverter(RestEventProcessorService restEventProcessorService, FrameworkEventProcessorService frameworkEventProcessorRestController, ServerConnectorEventProcessorService serverConnectorRestController) {
public StringToEventProcessorServiceConverter(RestEventProcessorService restEventProcessorService, FrameworkEventProcessorService frameworkEventProcessorService, ServerConnectorEventProcessorService serverConnectorEventProcessorService) {
this.restEventProcessorService = restEventProcessorService;
this.frameworkEventProcessorRestController = frameworkEventProcessorRestController;
this.serverConnectorRestController = serverConnectorRestController;
this.frameworkEventProcessorService = frameworkEventProcessorService;
this.serverConnectorEventProcessorService = serverConnectorEventProcessorService;
}

/*
Match the passed string against a set of known constants.
This is not elegant but does get its job done for the sample.
*/
@Override
public EventProcessorService convert(String from) {
switch (from){
case "server": return serverConnectorRestController;
case "server": return serverConnectorEventProcessorService;
case "rest": return restEventProcessorService;
case "grpc": throw new IllegalArgumentException();
case "framework": return frameworkEventProcessorRestController;
case "framework": return frameworkEventProcessorService;
default: throw new IllegalArgumentException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import reactor.core.publisher.Mono;

/**
* Uses the EventProcessorService provided to it based oin the supplied method
* Uses the EventProcessorService provided to it based on the supplied method
*/
@RestController
public class EventProcessorRestController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/*
Creates empty events to allow you to see the effects of a reset
*/
@RestController
public class EventRestController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,28 @@ public Mono<Void> reset(String processorName) {
.then(start(processorName, tokenStoreIdentifier));
}

/*
* Resets the token of an event processor. The event processor needs to be stopped for this to work
*/
private Mono<Void> resetTokens(StreamingEventProcessor eventProcessor) {
return Mono.fromRunnable(eventProcessor::resetTokens);
}

/*
* Starts event processors and ensures that either the axon server waits for them to have started or we wait locally
* for them to reach the desired state (pre 4.6)
*/
protected Mono<Void> start(String eventProcessorName, String tokenStoreIdentifier) {
return Mono.fromFuture(() -> adminChannel.startEventProcessor(eventProcessorName, tokenStoreIdentifier))
.filter(Result.SUCCESS::equals)
.switchIfEmpty(awaitForStatus(eventProcessorName, tokenStoreIdentifier, true))
.then();
}

/*
* Stops event processors and ensures that either the axon server waits for them to have stopped or we wait locally
* for them to reach the desired state (pre 4.6)
*/
protected Mono<Void> pause(String eventProcessorName, String tokenStoreIdentifier) {
return Mono.fromFuture(() -> adminChannel.pauseEventProcessor(eventProcessorName, tokenStoreIdentifier))
.filter(Result.SUCCESS::equals)
Expand Down Expand Up @@ -87,7 +98,6 @@ protected Mono<Result> awaitForStatus(String eventProcessorName, String tokenSto
}



private String tokenStoreId(String processorName) {
StreamingEventProcessor eventProcessor = eventProcessor(processorName);
return eventProcessor.getTokenStoreIdentifier();
Expand Down

0 comments on commit c6140dd

Please sign in to comment.