All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.doip.audit.writer.AuditLogPool Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show 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.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);
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy