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
The newest version!
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.codec.doipMessage.DoipMessage;
import org.bdware.irp.irplib.core.IrpMessage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
public class AuditLogPool {
static Logger LOGGER = LogManager.getLogger(AuditLogPool.class);
public static ExecutorService executorService = Executors.newFixedThreadPool(8, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}
});
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);
}
});
}
}