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

com.iteaj.iot.client.component.LengthFieldBasedFrameClientComponent Maven / Gradle / Ivy

The newest version!
package com.iteaj.iot.client.component;

import com.iteaj.iot.client.ClientConnectProperties;
import com.iteaj.iot.client.ClientMessage;
import com.iteaj.iot.client.MultiClientManager;
import com.iteaj.iot.client.TcpSocketClient;
import com.iteaj.iot.client.codec.LengthFieldBasedFrameClient;

import java.nio.ByteOrder;

public abstract class LengthFieldBasedFrameClientComponent extends TcpClientComponent {

    private ByteOrder byteOrder;
    private int maxFrameLength;
    private int lengthFieldOffset;
    private int lengthFieldLength;
    private int lengthAdjustment;
    private int initialBytesToStrip;
    private boolean failFast;

    public LengthFieldBasedFrameClientComponent(ClientConnectProperties config, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength) {
        this(config, maxFrameLength, lengthFieldOffset, lengthFieldLength, 0, 0);
    }

    public LengthFieldBasedFrameClientComponent(ClientConnectProperties config, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip) {
        this(config, maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, true);
    }

    public LengthFieldBasedFrameClientComponent(ClientConnectProperties config, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
        this(config, ByteOrder.BIG_ENDIAN, maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, failFast);
    }

    public LengthFieldBasedFrameClientComponent(ClientConnectProperties config, ByteOrder byteOrder, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
        super(config);
        this.failFast = failFast;
        this.byteOrder = byteOrder;

        this.maxFrameLength = maxFrameLength;
        this.lengthAdjustment = lengthAdjustment;
        this.lengthFieldOffset = lengthFieldOffset;
        this.lengthFieldLength = lengthFieldLength;

        this.initialBytesToStrip = initialBytesToStrip;
    }

    public LengthFieldBasedFrameClientComponent(ClientConnectProperties config, MultiClientManager clientManager, ByteOrder byteOrder, int maxFrameLength
            , int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
        super(config, clientManager);
        this.failFast = failFast;
        this.byteOrder = byteOrder;

        this.maxFrameLength = maxFrameLength;
        this.lengthAdjustment = lengthAdjustment;
        this.lengthFieldOffset = lengthFieldOffset;
        this.lengthFieldLength = lengthFieldLength;

        this.initialBytesToStrip = initialBytesToStrip;
    }

    @Override
    public TcpSocketClient createNewClient(ClientConnectProperties config) {
        return new LengthFieldBasedFrameClient(this, config, byteOrder, maxFrameLength
                , lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, failFast);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy