shutdown hook plugin

This commit is contained in:
Mark Wolters 2023-10-05 14:47:57 -04:00 committed by Jonathan Shook
parent 6e496f8e7b
commit 28c4446a13
4 changed files with 18 additions and 51 deletions

View File

@ -1,37 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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;
import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
import org.apache.logging.log4j.Logger;
@Service(value= ScriptingExtensionPluginInfo.class,selector = "shutdown")
public class ShutdownHookPluginMetadata implements ScriptingExtensionPluginInfo<ShutdownHookPlugin> {
@Override
public String getDescription() {
return "Register shutdown hooks in the form of javascript functions.";
}
@Override
public ShutdownHookPlugin getExtensionObject(final Logger logger, final NBComponent baseComponent) {
return new ShutdownHookPlugin(logger,baseComponent);
}
}

View File

@ -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.
@ -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 class NBShutdownHook extends NBBaseComponent {
private final Logger logger = LogManager.getLogger(NBShutdownHook.class);
public ShutdownHookPlugin(Logger logger, NBComponent baseComponent) {
this.logger = logger;
this.baseComponent = baseComponent;
public NBShutdownHook(NBComponent baseComponent) {
super(baseComponent);
}
public void addShutdownHook(String name, Object f) {
@ -41,6 +40,5 @@ public class ShutdownHookPlugin {
runnable.setName(shutdownName);
Runtime.getRuntime().addShutdownHook(runnable);
logger.info(() -> "Registered shutdown hook to run under name '" + shutdownName + "'");
}
}

View File

@ -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.
@ -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;

View File

@ -34,6 +34,7 @@ import io.nosqlbench.api.http.HttpPlugin;
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;
@ -149,8 +150,12 @@ public class NBBuilders {
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;