Skip to content

Commit c6140dd

Browse files
committed
Adjusted variable names and added comments to make sample code easier to understand
1 parent 2d54d51 commit c6140dd

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

reset-handler/src/main/java/io/axoniq/config/ConfigBasedAdminChannel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import org.springframework.context.annotation.Bean;
77
import org.springframework.stereotype.Component;
88

9+
10+
/*
11+
Creates an admin channel from the configuration. used to simplify testing in other components.
12+
*/
913
@Component
1014
public class ConfigBasedAdminChannel {
1115

reset-handler/src/main/java/io/axoniq/config/StringToEventProcessorServiceConverter.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@
77
import org.springframework.core.convert.converter.Converter;
88
import org.springframework.stereotype.Component;
99

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

1317
final RestEventProcessorService restEventProcessorService;
14-
final FrameworkEventProcessorService frameworkEventProcessorRestController;
15-
final ServerConnectorEventProcessorService serverConnectorRestController;
18+
final FrameworkEventProcessorService frameworkEventProcessorService;
19+
final ServerConnectorEventProcessorService serverConnectorEventProcessorService;
1620

17-
public StringToEventProcessorServiceConverter(RestEventProcessorService restEventProcessorService, FrameworkEventProcessorService frameworkEventProcessorRestController, ServerConnectorEventProcessorService serverConnectorRestController) {
21+
public StringToEventProcessorServiceConverter(RestEventProcessorService restEventProcessorService, FrameworkEventProcessorService frameworkEventProcessorService, ServerConnectorEventProcessorService serverConnectorEventProcessorService) {
1822
this.restEventProcessorService = restEventProcessorService;
19-
this.frameworkEventProcessorRestController = frameworkEventProcessorRestController;
20-
this.serverConnectorRestController = serverConnectorRestController;
23+
this.frameworkEventProcessorService = frameworkEventProcessorService;
24+
this.serverConnectorEventProcessorService = serverConnectorEventProcessorService;
2125
}
2226

27+
/*
28+
Match the passed string against a set of known constants.
29+
This is not elegant but does get its job done for the sample.
30+
*/
2331
@Override
2432
public EventProcessorService convert(String from) {
2533
switch (from){
26-
case "server": return serverConnectorRestController;
34+
case "server": return serverConnectorEventProcessorService;
2735
case "rest": return restEventProcessorService;
2836
case "grpc": throw new IllegalArgumentException();
29-
case "framework": return frameworkEventProcessorRestController;
37+
case "framework": return frameworkEventProcessorService;
3038
default: throw new IllegalArgumentException();
3139
}
3240
}

reset-handler/src/main/java/io/axoniq/controller/EventProcessorRestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import reactor.core.publisher.Mono;
1010

1111
/**
12-
* Uses the EventProcessorService provided to it based oin the supplied method
12+
* Uses the EventProcessorService provided to it based on the supplied method
1313
*/
1414
@RestController
1515
public class EventProcessorRestController {

reset-handler/src/main/java/io/axoniq/controller/EventRestController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.springframework.web.bind.annotation.GetMapping;
55
import org.springframework.web.bind.annotation.RestController;
66

7+
/*
8+
Creates empty events to allow you to see the effects of a reset
9+
*/
710
@RestController
811
public class EventRestController {
912

reset-handler/src/main/java/io/axoniq/service/ServerConnectorEventProcessorService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,28 @@ public Mono<Void> reset(String processorName) {
4747
.then(start(processorName, tokenStoreIdentifier));
4848
}
4949

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

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

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

89100

90-
91101
private String tokenStoreId(String processorName) {
92102
StreamingEventProcessor eventProcessor = eventProcessor(processorName);
93103
return eventProcessor.getTokenStoreIdentifier();

0 commit comments

Comments
 (0)