package mapped;

import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSArchiveDiskActionHandler;

@ObfuscatedName("ox")
public class ArchiveDiskActionHandler implements Runnable, RSArchiveDiskActionHandler {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lon;"
   )
   public static final NodeDeque ArchiveDiskActionHandler_requestQueue;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lon;"
   )
   public static NodeDeque ArchiveDiskActionHandler_responseQueue;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = -632476027
   )
   static int field4271;
   @ObfuscatedName("ao")
   static boolean field4274;
   @ObfuscatedName("ab")
   static Object field4272;
   @ObfuscatedName("au")
   static Thread ArchiveDiskActionHandler_thread;

   static {
      ArchiveDiskActionHandler_requestQueue = new NodeDeque();
      ArchiveDiskActionHandler_responseQueue = new NodeDeque();
      field4271 = 0;
      field4274 = false;
      field4272 = new Object();
   }

   public void run() {
      try {
         while(true) {
            Object var14;
            while(true) {
               NodeDeque var2 = ArchiveDiskActionHandler_requestQueue;
               ArchiveDiskAction var1;
               synchronized(ArchiveDiskActionHandler_requestQueue) {
                  var1 = (ArchiveDiskAction)ArchiveDiskActionHandler_requestQueue.method7265();
               }

               if(var1 != null) {
                  if(var1.type == 0) {
                     var1.archiveDisk.write_base((int)var1.key, var1.data, var1.data.length);
                     var2 = ArchiveDiskActionHandler_requestQueue;
                     synchronized(ArchiveDiskActionHandler_requestQueue) {
                        var1.remove_base();
                     }
                  } else if(var1.type == 1) {
                     var1.data = var1.archiveDisk.read_base((int)var1.key);
                     var2 = ArchiveDiskActionHandler_requestQueue;
                     synchronized(ArchiveDiskActionHandler_requestQueue) {
                        ArchiveDiskActionHandler_responseQueue.method7233(var1);
                     }
                  }
                  break;
               }

               class219.method4260_base(100L);
               var14 = field4272;
               synchronized(field4272) {
                  if((field4274 || field4271 <= 1) && ArchiveDiskActionHandler_requestQueue.method7235_base()) {
                     field4271 = 0;
                     field4272.notifyAll();
                     return;
                  }

                  --field4271;
               }
            }

            var14 = field4272;
            synchronized(field4272) {
               if((field4274 || field4271 <= 1) && ArchiveDiskActionHandler_requestQueue.method7235_base()) {
                  field4271 = 0;
                  field4272.notifyAll();
                  return;
               }

               field4271 = 600;
            }
         }
      } catch (Exception var13) {
         GrandExchangeOfferWorldComparator.RunException_sendStackTrace_base((String)null, var13);
      }
   }
}
