Skip to content

Commit

Permalink
Watcher: cleanup ensureWatchExists use (#31926)
Browse files Browse the repository at this point in the history
Previously, the ensureWatchExists was overridable. This commit makes
it final so that it cannot be overridden, and cleans up some redundant
code in the process.
  • Loading branch information
hub-cap authored Jul 13, 2018
1 parent 82cdb57 commit c1a81e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Watch watch() {
return watch;
}

public void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
public final void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
if (watch == null) {
watch = supplier.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.execution;

import org.elasticsearch.common.CheckedSupplier;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.core.watcher.actions.Action;
import org.elasticsearch.xpack.core.watcher.actions.ActionWrapper;
Expand All @@ -29,18 +28,19 @@ public class ManualExecutionContext extends WatchExecutionContext {
private final Map<String, ActionExecutionMode> actionModes;
private final boolean recordExecution;
private final boolean knownWatch;
private final Watch watch;

ManualExecutionContext(Watch watch, boolean knownWatch, DateTime executionTime, ManualTriggerEvent triggerEvent,
TimeValue defaultThrottlePeriod, Input.Result inputResult, Condition.Result conditionResult,
Map<String, ActionExecutionMode> actionModes, boolean recordExecution) {
Map<String, ActionExecutionMode> actionModes, boolean recordExecution) throws Exception {

super(watch.id(), executionTime, triggerEvent, defaultThrottlePeriod);

this.actionModes = actionModes;
this.recordExecution = recordExecution;
this.knownWatch = knownWatch;
this.watch = watch;

// set the watch early to ensure calls to watch() below succeed.
super.ensureWatchExists(() -> watch);

if (inputResult != null) {
onInputResult(inputResult);
Expand All @@ -66,12 +66,6 @@ public class ManualExecutionContext extends WatchExecutionContext {
}
}

// a noop operation, as the watch is already loaded via ctor
@Override
public void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
super.ensureWatchExists(() -> watch);
}

@Override
public boolean knownWatch() {
return knownWatch;
Expand Down Expand Up @@ -107,11 +101,6 @@ public final boolean recordExecution() {
return recordExecution;
}

@Override
public Watch watch() {
return watch;
}

public static Builder builder(Watch watch, boolean knownWatch, ManualTriggerEvent event, TimeValue defaultThrottlePeriod) {
return new Builder(watch, knownWatch, event, defaultThrottlePeriod);
}
Expand Down Expand Up @@ -173,7 +162,7 @@ public Builder withCondition(Condition.Result conditionResult) {
return this;
}

public ManualExecutionContext build() {
public ManualExecutionContext build() throws Exception {
if (executionTime == null) {
executionTime = DateTime.now(DateTimeZone.UTC);
}
Expand Down

0 comments on commit c1a81e5

Please sign in to comment.