if (!validateSettings()) {
return;
}
stopIfRunning();
final Stats stats = new Stats();
final StatsPanel statsPanel = new StatsPanel();
resultsPanel.insert(statsPanel, 0);
// create the message payload
Integer messageSizeInt = messageSize.getValue();
StringBuilder sb = new StringBuilder(messageSizeInt);
for (int i = 0; i < messageSizeInt; i++) {
sb.append("!");
}
messageValue = sb.toString();
if (messageMultiplier.getValue() == null || messageMultiplier.getValue() < 1) {
messageMultiplier.setValue(1);
}
final int multipler = messageMultiplier.getValue();
sendTimer = new Timer() {
private boolean hasStarted;
@Override
public void run() {
hasStarted = true;
for (int i = 0; i < multipler; i++) {
MessageBuildSendable sendable = MessageBuilder.createMessage()
.toSubject("StressTestService")
.withValue(messageValue)
.done()
.repliesTo(new MessageCallback() {
@Override
public void callback(Message message) {
stats.registerReceivedMessage(message);
statsPanel.updateStatsLabels(stats);
}
});
sendable.sendNowWith(bus);
stats.registerSentMessage(sendable.getMessage());
}
statsPanel.updateStatsLabels(stats);
}
@Override
public void cancel() {
super.cancel();
if (hasStarted) {
stats.registerTestFinishing();
statsPanel.onRunFinished(stats);
}
}
};
sendTimer.scheduleRepeating(messageInterval.getValue());
stats.registerTestStarting();
statsPanel.onRunStarted(stats);
}