// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
// 
//     public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
// 
//     public static final byte PROTOCOL_VERSION = 2;
// 
//     public static final int MIN_SEND_WINDOW_SIZE = 20;
// 
//     public static final int ACK_INTERVAL_MS = 10;
// 
//     public static final int MAX_FAST_RESEND_COUNT = 3;
// 
//     public static final int MAX_SLOW_RESEND_MULT = 4;
// 
//     public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
// 
//     public static final int DEV_RTT_MULT = 4;
// 
//     public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
// 
//     public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
// 
//     public static final int WEB_PANEL_PORT = 8000;
// 
// }
// 
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
// 
//     public static long min(final long l1, final long l2) {
//         return l1 < l2 ? l1 : l2;
//     }
// 
//     public static long max(final long l1, final long l2) {
//         return l1 > l2 ? l1 : l2;
//     }
// 
//     public static int min(final int i1, final int i2) {
//         return i1 < i2 ? i1 : i2;
//     }
// 
//     public static int max(final int i1, final int i2) {
//         return i1 > i2 ? i1 : i2;
//     }
// 
// }
// 
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
// 
//     int getSequence();
// 
//     void setSequence(int sequence);
// 
// }


import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
        resendThread = new Thread(() -> {
            try {
                while (canRun()) {

                    final long sleepTime;
                    final int sequence;

                    ResendItem resendItem;

                    /*synchronized (queueLock) {
                        resendItem = resendQueue.take();
                        sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
                        sequence = resendItem.getSequence();

                        resendItem.addSendCount();
                        resendItem.setNextSendTime(getNextSendTime(resendItem.getSendCount(), NumUtils.max(sleepTime, 0)));
                        resendQueue.put(resendItem);
                    }*/

                    synchronized (queueLock) {
                        while ((resendItem = riQueue.poll()) == null && canRun()) {
                            queueLock.wait();
                        }
                        if (resendItem == null) {
                            break;
                        }
                        sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
                        sequence = resendItem.getSequence();

                        resendItem.addSendCount();
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/DragoniteGlobalConstants.java
// public final class DragoniteGlobalConstants {
// 
//     public static final String LIBRARY_VERSION = DragoniteBuildConfig.VERSION;
// 
//     public static final byte PROTOCOL_VERSION = 2;
// 
//     public static final int MIN_SEND_WINDOW_SIZE = 20;
// 
//     public static final int ACK_INTERVAL_MS = 10;
// 
//     public static final int MAX_FAST_RESEND_COUNT = 3;
// 
//     public static final int MAX_SLOW_RESEND_MULT = 4;
// 
//     public static final int INIT_RTT_MS = 200, RTT_MAX_VARIATION_MS = 200, RTT_UPDATE_INTERVAL_MS = 100, RTT_RESEND_CORRECTION_INTERVAL_MS = 2000;
// 
//     public static final int DEV_RTT_MULT = 4;
// 
//     public static final float RTT_RESENDED_REFRESH_MAX_MULT = 1.5f;
// 
//     public static final int MIN_CLOSE_WAIT_MS = 100, CLOSE_WAIT_RTT_MULT = 4;
// 
//     public static final int WEB_PANEL_PORT = 8000;
// 
// }
// 
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/misc/NumUtils.java
// public final class NumUtils {
// 
//     public static long min(final long l1, final long l2) {
//         return l1 < l2 ? l1 : l2;
//     }
// 
//     public static long max(final long l1, final long l2) {
//         return l1 > l2 ? l1 : l2;
//     }
// 
//     public static int min(final int i1, final int i2) {
//         return i1 < i2 ? i1 : i2;
//     }
// 
//     public static int max(final int i1, final int i2) {
//         return i1 > i2 ? i1 : i2;
//     }
// 
// }
// 
// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/msg/ReliableMessage.java
// public interface ReliableMessage extends Message {
// 
//     int getSequence();
// 
//     void setSequence(int sequence);
// 
// }


// Path: dragonite-sdk/src/main/java/com/vecsight/dragonite/sdk/socket/ResendHandler.java
import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants;
import com.vecsight.dragonite.sdk.misc.NumUtils;
import com.vecsight.dragonite.sdk.msg.ReliableMessage;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

        resendThread = new Thread(() -> {
            try {
                while (canRun()) {

                    final long sleepTime;
                    final int sequence;

                    ResendItem resendItem;

                    /*synchronized (queueLock) {
                        resendItem = resendQueue.take();
                        sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
                        sequence = resendItem.getSequence();

                        resendItem.addSendCount();
                        resendItem.setNextSendTime(getNextSendTime(resendItem.getSendCount(), NumUtils.max(sleepTime, 0)));
                        resendQueue.put(resendItem);
                    }*/

                    synchronized (queueLock) {
                        while ((resendItem = riQueue.poll()) == null && canRun()) {
                            queueLock.wait();
                        }
                        if (resendItem == null) {
                            break;
                        }
                        sleepTime = resendItem.getNextSendTime() - System.currentTimeMillis();
                        sequence = resendItem.getSequence();

                        resendItem.addSendCount();
                        resendItem.setNextSendTime(getNextSendTime(resendItem.getSendCount(), NumUtils.max(sleepTime, 0)));