org.bdware.doip.audit.writer.AuditLogPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip.audit.writer;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.doip.audit.config.ConfigStorage;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.irp.irplib.core.IrpMessage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class AuditLogPool {
static Logger LOGGER = LogManager.getLogger(AuditLogPool.class);
public static ExecutorService executorService = Executors.newFixedThreadPool(8);
private LogWriter logWriter = new NoneWriter();
private static String getProp(JsonObject jo, String field, String defaultValue) {
if (jo == null || field == null || !jo.has(field))
return defaultValue;
return jo.get(field).getAsString();
}
public AuditLogPool(LogWriter writer) {
if (writer!=null)
logWriter = writer;
}
public void extract(EndpointContext ctx, IrpMessage request, IrpMessage response) {
executorService.execute(new Runnable() {
@Override
public void run() {
AuditLog log = logWriter.extract(ctx, request, response);
logWriter.write(log);
}
});
}
public void extract(EndpointContext ctx, DoipMessage request, DoipMessage response) {
executorService.execute(new Runnable() {
@Override
public void run() {
AuditLog log = logWriter.extract(ctx, request, response);
logWriter.write(log);
}
});
}
}