Add flag to disable post-processors
This commit is contained in:
parent
9e82b61df7
commit
519e6a49f3
|
@ -1,16 +1,15 @@
|
|||
package ctbrec.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
import com.squareup.moshi.JsonReader;
|
||||
import com.squareup.moshi.JsonReader.Token;
|
||||
import com.squareup.moshi.JsonWriter;
|
||||
|
||||
import ctbrec.recorder.postprocessing.PostProcessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class PostProcessorJsonAdapter extends JsonAdapter<PostProcessor> {
|
||||
|
||||
@Override
|
||||
|
@ -18,16 +17,18 @@ public class PostProcessorJsonAdapter extends JsonAdapter<PostProcessor> {
|
|||
reader.beginObject();
|
||||
Object type = null;
|
||||
PostProcessor postProcessor = null;
|
||||
while(reader.hasNext()) {
|
||||
while (reader.hasNext()) {
|
||||
try {
|
||||
Token token = reader.peek();
|
||||
if(token == Token.NAME) {
|
||||
if (token == Token.NAME) {
|
||||
String key = reader.nextName();
|
||||
if(key.equals("type")) {
|
||||
if (key.equals("type")) {
|
||||
type = reader.readJsonValue();
|
||||
Class<?> modelClass = Class.forName(type.toString());
|
||||
postProcessor = (PostProcessor) modelClass.getDeclaredConstructor().newInstance();
|
||||
} else if(key.equals("config")) {
|
||||
} else if (key.equals("enabled")) {
|
||||
postProcessor.setEnabled(reader.nextBoolean());
|
||||
} else if (key.equals("config")) {
|
||||
reader.beginObject();
|
||||
} else {
|
||||
String value = reader.nextString();
|
||||
|
@ -36,7 +37,8 @@ public class PostProcessorJsonAdapter extends JsonAdapter<PostProcessor> {
|
|||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException |
|
||||
NoSuchMethodException | SecurityException e) {
|
||||
throw new IOException("Couldn't instantiate post-processor class [" + type + "]", e);
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +52,7 @@ public class PostProcessorJsonAdapter extends JsonAdapter<PostProcessor> {
|
|||
public void toJson(JsonWriter writer, PostProcessor pp) throws IOException {
|
||||
writer.beginObject();
|
||||
writer.name("type").value(pp.getClass().getName());
|
||||
writer.name("enabled").value(pp.isEnabled());
|
||||
writer.name("config");
|
||||
writer.beginObject();
|
||||
for (Entry<String, String> entry : pp.getConfig().entrySet()) {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class NextGenLocalRecorder implements Recorder {
|
|||
public static final boolean IGNORE_CACHE = true;
|
||||
private final List<Model> models = Collections.synchronizedList(new ArrayList<>());
|
||||
private final Config config;
|
||||
private volatile boolean recording = true;
|
||||
private volatile boolean recording;
|
||||
private final ReentrantLock recorderLock = new ReentrantLock();
|
||||
private final ReentrantLock modelGroupLock = new ReentrantLock();
|
||||
private final RecorderHttpClient client;
|
||||
|
@ -190,10 +190,14 @@ public class NextGenLocalRecorder implements Recorder {
|
|||
List<PostProcessor> postProcessors = config.getSettings().postProcessors;
|
||||
PostProcessingContext ctx = createPostProcessingContext(recording);
|
||||
for (PostProcessor postProcessor : postProcessors) {
|
||||
LOG.debug("Running post-processor: {}", postProcessor.getName());
|
||||
boolean continuePP = postProcessor.postprocess(ctx);
|
||||
if (!continuePP) {
|
||||
break;
|
||||
if (postProcessor.isEnabled()) {
|
||||
LOG.debug("Running post-processor: {}", postProcessor.getName());
|
||||
boolean continuePP = postProcessor.postprocess(ctx);
|
||||
if (!continuePP) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG.debug("Skipping post-processor {} because it is disabled", postProcessor.getName());
|
||||
}
|
||||
}
|
||||
recording.refresh();
|
||||
|
@ -445,7 +449,7 @@ public class NextGenLocalRecorder implements Recorder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Recording> getRecordings() throws IOException {
|
||||
public List<Recording> getRecordings() {
|
||||
return recordingManager.getAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
package ctbrec.recorder.postprocessing;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class AbstractPostProcessor implements PostProcessor {
|
||||
|
||||
private Map<String, String> config = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<String, String> getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfig(Map<String, String> conf) {
|
||||
this.config = conf;
|
||||
}
|
||||
private boolean enabled = true;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -9,6 +9,7 @@ public interface PostProcessor extends Serializable {
|
|||
|
||||
/**
|
||||
* Runs the post-processing code on the given recording
|
||||
*
|
||||
* @param ctx {@link PostProcessingContext}, which allows access to post-processing related objects
|
||||
* @return false to stop futher post-processing, true to continue
|
||||
* @throws IOException
|
||||
|
@ -16,6 +17,11 @@ public interface PostProcessor extends Serializable {
|
|||
*/
|
||||
boolean postprocess(PostProcessingContext ctx) throws IOException, InterruptedException;
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
void setEnabled(boolean enabled);
|
||||
|
||||
Map<String, String> getConfig();
|
||||
|
||||
void setConfig(Map<String, String> conf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue