// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/flow/Preconditions.java
// public static void checkArgument(final boolean ok, final String message) {
//     if (!ok) throw new IllegalArgumentException(message);
// }


import com.github.bucket4j.Bandwidth;
import com.github.bucket4j.Bucket;
import com.github.bucket4j.Bucket4j;
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import static com.vecsight.dragonite.utils.flow.Preconditions.checkArgument;
/*
 * The Dragonite Project
 * -------------------------
 * See the LICENSE file in the root directory for license information.
 */


package com.vecsight.dragonite.sdk.socket;




public class BucketPacketSender implements PacketSender {

    private final PacketSender packetSender;

    private volatile Bucket bucket;

    private volatile long speed;

    private final AtomicLong sendRawLength = new AtomicLong(0);

    public BucketPacketSender(final PacketSender packetSender, final long speed) {
        this.packetSender = packetSender;
        setSpeed(speed);
    }

    public void setSpeed(final long speed) {
        checkArgument(speed > 0, "Speed must be greater than zero");
        bucket = Bucket4j.builder().addLimit(Bandwidth.simple(speed, Duration.ofSeconds(1))).build();
        this.speed = speed;
    }

// Path: dragonite-utils/src/main/java/com/vecsight/dragonite/utils/flow/Preconditions.java
// public static void checkArgument(final boolean ok, final String message) {
//     if (!ok) throw new IllegalArgumentException(message);
// }


// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/BucketPacketSender.java
import com.github.bucket4j.Bandwidth;
import com.github.bucket4j.Bucket;
import com.github.bucket4j.Bucket4j;
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import static com.vecsight.dragonite.utils.flow.Preconditions.checkArgument;

/*
 * The Dragonite Project
 * -------------------------
 * See the LICENSE file in the root directory for license information.
 */


package com.vecsight.dragonite.sdk.socket;




public class BucketPacketSender implements PacketSender {

    private final PacketSender packetSender;

    private volatile Bucket bucket;

    private volatile long speed;

    private final AtomicLong sendRawLength = new AtomicLong(0);

    public BucketPacketSender(final PacketSender packetSender, final long speed) {
        this.packetSender = packetSender;
        setSpeed(speed);
    }

    public void setSpeed(final long speed) {
        checkArgument(speed > 0, "Speed must be greater than zero");
        bucket = Bucket4j.builder().addLimit(Bandwidth.simple(speed, Duration.ofSeconds(1))).build();
        this.speed = speed;
    }

    public long getSpeed() {