This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
/
CommandJdo_replayNext.java
146 lines (113 loc) · 4.97 KB
/
CommandJdo_replayNext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package org.isisaddons.module.command.replay.impl.mixins;
import java.util.List;
import javax.inject.Inject;
import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.ActionLayout;
import org.apache.isis.applib.annotation.CommandReification;
import org.apache.isis.applib.annotation.Contributed;
import org.apache.isis.applib.annotation.MemberOrder;
import org.apache.isis.applib.annotation.Mixin;
import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.services.message.MessageService;
import org.apache.isis.core.metamodel.services.configinternal.ConfigurationServiceInternal;
import org.apache.isis.core.runtime.services.background.CommandExecutorService;
import org.apache.isis.schema.cmd.v1.CommandDto;
import org.isisaddons.module.command.CommandModule;
import org.isisaddons.module.command.dom.CommandJdo;
import org.isisaddons.module.command.dom.CommandServiceJdoRepository;
import org.isisaddons.module.command.replay.impl.CommandFetcher;
import org.isisaddons.module.command.replay.impl.CommandReplayAnalyser;
import org.isisaddons.module.command.replay.impl.SlaveConfiguration;
import org.isisaddons.module.command.replay.impl.StatusException;
@Mixin(method = "act")
public class CommandJdo_replayNext {
private final CommandJdo commandJdo;
//region > constructor
public CommandJdo_replayNext(CommandJdo commandJdo) {
this.commandJdo = commandJdo;
}
//endregion
public static class ActionDomainEvent extends CommandModule.ActionDomainEvent<CommandJdo_replayNext> { }
@Action(
semantics = SemanticsOf.NON_IDEMPOTENT,
domainEvent = ActionDomainEvent.class,
command = CommandReification.DISABLED
)
@ActionLayout(
contributed = Contributed.AS_ACTION
)
@MemberOrder(name = "executeIn", sequence = "3")
public CommandJdo act() throws StatusException {
// double check this is still the HWM
final CommandJdo replayHwm = commandServiceJdoRepository.findReplayHwm();
if(commandJdo != replayHwm) {
messageService.informUser("HWM has changed");
return replayHwm;
}
final CommandJdo nextHwm = fetchNext();
if(nextHwm == null) {
messageService.informUser("No more commands on master");
return commandJdo;
}
execute(nextHwm);
commandReplayAnalyser.analyze(nextHwm);
return nextHwm;
}
private CommandJdo fetchNext() throws StatusException {
SlaveConfiguration slaveConfig = getSlaveConfig();
final CommandDto commandDto = commandFetcher.fetchCommand(this.commandJdo, slaveConfig);
return commandDto == null
? null
: commandServiceJdoRepository.saveForReplay(commandDto);
}
private void execute(final CommandJdo hwmCommand) {
// execute the hwm command
commandExecutorService.executeCommand(CommandExecutorService.SudoPolicy.SWITCH, hwmCommand);
// find background commands, and run them
final List<CommandJdo> backgroundCommands = commandServiceJdoRepository.findBackgroundCommandsByParent(hwmCommand);
for (final CommandJdo backgroundCommand : backgroundCommands) {
commandExecutorService.executeCommand(CommandExecutorService.SudoPolicy.SWITCH, backgroundCommand);
}
}
public String disableAct() {
final CommandJdo replayHwm = commandServiceJdoRepository.findReplayHwm();
if(commandJdo != replayHwm) {
return "This action can only be performed against the 'HWM' command on the slave";
}
if(commandJdo.getExecuteIn().isReplayable() && commandJdo.getReplayState() != null && commandJdo.getReplayState().representsError()) {
return "Replayable command is in error. Exclude the command to continue.";
}
if(!commandJdo.isComplete()) {
return "Replayable command is not complete";
}
if(commandJdo.getExecuteIn().isBackground()) {
// this shouldn't happen; findReplayHwm should never return a background command
return "Background commands cannot be replayed";
}
return null;
}
// //////////////////////////////////////
/**
* lazily loaded
*/
SlaveConfiguration slaveConfig;
private SlaveConfiguration getSlaveConfig() {
if (slaveConfig == null){
slaveConfig = new SlaveConfiguration(configurationServiceInternal.asMap());
}
return slaveConfig;
}
// //////////////////////////////////////
@javax.inject.Inject
CommandServiceJdoRepository commandServiceJdoRepository;
@javax.inject.Inject
CommandFetcher commandFetcher;
@javax.inject.Inject
CommandExecutorService commandExecutorService;
@javax.inject.Inject
ConfigurationServiceInternal configurationServiceInternal;
@javax.inject.Inject
MessageService messageService;
@Inject
CommandReplayAnalyser commandReplayAnalyser;
}