Skip to content

Commit

Permalink
shutdown hook plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkWolters committed Oct 5, 2023
1 parent 10451e9 commit 29ea236
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 51 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,24 +12,23 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.nosqlbench.engine.shutdown;
package io.nosqlbench.api.shutdown;

import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.script.ScriptContext;
import java.util.function.Function;

public class ShutdownHookPlugin {
private final Logger logger;
private final NBComponent baseComponent;

public ShutdownHookPlugin(Logger logger, NBComponent baseComponent) {
public class NBShutdownHook extends NBBaseComponent {
private final Logger logger = LogManager.getLogger(NBShutdownHook.class);

this.logger = logger;
this.baseComponent = baseComponent;
public NBShutdownHook(NBComponent baseComponent) {
super(baseComponent);
}

public void addShutdownHook(String name, Object f) {
Expand All @@ -41,6 +40,5 @@ public void addShutdownHook(String name, Object f) {
runnable.setName(shutdownName);
Runtime.getRuntime().addShutdownHook(runnable);
logger.info(() -> "Registered shutdown hook to run under name '" + shutdownName + "'");

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.nosqlbench.engine.shutdown;
package io.nosqlbench.api.shutdown;

import org.apache.logging.log4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.nosqlbench.api.optimizers.BobyqaOptimizerInstance;
import io.nosqlbench.api.files.FileAccess;
import io.nosqlbench.api.labels.NBLabels;
import io.nosqlbench.api.shutdown.NBShutdownHook;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -131,8 +132,12 @@ public HttpPlugin httpPlugin(NBComponent component) {
return new HttpPlugin(component);
}

public NBShutdownHook shutdownHook(NBComponent component) {
return new NBShutdownHook(component);
}

public static class CsvOutputWriterBuilder {
//CsvOutputPluginWriter(NBComponent component, String filename, String... headers) {

private final NBComponent component;
private final String filename;
private String[] headers;
Expand Down

0 comments on commit 29ea236

Please sign in to comment.