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

org.bdware.doip.audit.client.AuditDoipClientHandler Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package org.bdware.doip.audit.client;

import io.netty.channel.ChannelHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.doip.audit.writer.AuditConfig;
import org.bdware.doip.audit.writer.AuditLogPool;
import org.bdware.doip.audit.writer.ClientContext;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.endpoint.client.DoipMessageCallback;
import org.bdware.doip.endpoint.client.NettyDoipClientHandler;

@ChannelHandler.Sharable
public class AuditDoipClientHandler extends NettyDoipClientHandler {
    static Logger LOGGER = LogManager.getLogger(AuditDoipClientHandler.class);
    private final DoIdWrapper clientDoId;
    private final DoIdWrapper serverDoId;

    AuditLogPool pool;

    public AuditDoipClientHandler(DoIdWrapper clientDoIdWrapper, DoIdWrapper serverDoIdWrapper, AuditConfig config) {
        pool = new AuditLogPool(config.createLogWriterInstance());
        this.clientDoId = clientDoIdWrapper;
        this.serverDoId = serverDoIdWrapper;
    }

    @Override
    public void sendMessage(final DoipMessage request, DoipMessageCallback callback, int timeoutSeconds) {
        super.sendMessage(request, new DoipMessageCallback() {
            @Override
            public void onResult(DoipMessage msg) {
                ClientContext context = new ClientContext(clientDoId, serverDoId, channel);
                pool.extract(context, request, msg);
                callback.onResult(msg);
            }
        }, timeoutSeconds);
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy