示例#1
0
 private final void passivesRequest() {
   while (true) {
     if (immediateRequestsSent != 0) {
       break;
     }
     if (passiveRequestsSent >= 10) {
       break;
     }
     if (highestPriority == 0) {
       break;
     }
     OnDemandNode onDemandNode;
     synchronized (passiveRequests) {
       onDemandNode = (OnDemandNode) passiveRequests.popTail();
     }
     while (onDemandNode != null) {
       if (filePriorities[onDemandNode.type][onDemandNode.id] != 0) {
         filePriorities[onDemandNode.type][onDemandNode.id] = (byte) 0;
         sentRequests.insertBack(onDemandNode);
         sendRequest(onDemandNode);
         expectData = true;
         if (extrasLoaded < extrasTotal) {
           extrasLoaded++;
         }
         message = "Loading extra files - " + ((extrasLoaded * 100) / extrasTotal) + "%";
         passiveRequestsSent++;
         if (passiveRequestsSent == 10) {
           return;
         }
       }
       synchronized (passiveRequests) {
         onDemandNode = (OnDemandNode) passiveRequests.popTail();
       }
     }
     for (int type = 0; type < 4; type++) {
       byte[] priority = filePriorities[type];
       for (int id = 0; id < priority.length; id++) {
         if (priority[id] == highestPriority) {
           priority[id] = (byte) 0;
           onDemandNode = new OnDemandNode();
           onDemandNode.type = type;
           onDemandNode.id = id;
           onDemandNode.immediate = false;
           sentRequests.insertBack(onDemandNode);
           sendRequest(onDemandNode);
           expectData = true;
           if (extrasLoaded < extrasTotal) {
             extrasLoaded++;
           }
           message = "Loading extra files - " + ((extrasLoaded * 100) / extrasTotal) + "%";
           passiveRequestsSent++;
           if (passiveRequestsSent == 10) {
             return;
           }
         }
       }
     }
     highestPriority--;
   }
 }
示例#2
0
 private final void localComplete() {
   OnDemandNode onDemandNode;
   synchronized (wanted) {
     onDemandNode = (OnDemandNode) wanted.popTail();
   }
   while (onDemandNode != null) {
     expectData = true;
     byte[] buffer = null;
     if (client.stores[0] != null) {
       buffer = client.stores[onDemandNode.type + 1].get(onDemandNode.id);
     }
     if (!verify(
         fileVersions[onDemandNode.type][onDemandNode.id],
         fileCrc[onDemandNode.type][onDemandNode.id],
         buffer)) {
       buffer = null;
     }
     synchronized (wanted) {
       if (buffer == null) {
         toRequest.insertBack(onDemandNode);
       } else {
         onDemandNode.buffer = buffer;
         synchronized (completed) {
           completed.insertBack(onDemandNode);
         }
       }
       onDemandNode = (OnDemandNode) wanted.popTail();
     }
   }
 }
示例#3
0
 private final void remainingRequest() {
   immediateRequestsSent = 0;
   passiveRequestsSent = 0;
   for (OnDemandNode onDemandNode = (OnDemandNode) sentRequests.getBack();
       onDemandNode != null;
       onDemandNode = (OnDemandNode) sentRequests.getPrevious()) {
     if (onDemandNode.immediate) {
       immediateRequestsSent++;
     } else {
       passiveRequestsSent++;
     }
   }
   while (immediateRequestsSent < 10) {
     OnDemandNode onDemandNode = (OnDemandNode) toRequest.popTail();
     if (onDemandNode == null) {
       break;
     }
     if (filePriorities[onDemandNode.type][onDemandNode.id] != 0) {
       extrasLoaded++;
     }
     filePriorities[onDemandNode.type][onDemandNode.id] = (byte) 0;
     sentRequests.insertBack(onDemandNode);
     immediateRequestsSent++;
     sendRequest(onDemandNode);
     expectData = true;
   }
 }
示例#4
0
 public final OnDemandNode next() {
   OnDemandNode onDemandNode;
   synchronized (completed) {
     onDemandNode = (OnDemandNode) completed.popTail();
   }
   if (onDemandNode == null) {
     return null;
   }
   synchronized (immediateRequests) {
     onDemandNode.clear();
   }
   if (onDemandNode.buffer == null) {
     return onDemandNode;
   }
   int offset = 0;
   try {
     GZIPInputStream gzipinputstream =
         new GZIPInputStream(new ByteArrayInputStream(onDemandNode.buffer));
     while (true) {
       if (offset == deflateOut.length) {
         throw new RuntimeException("buffer overflow!");
       }
       int readByte = gzipinputstream.read(deflateOut, offset, deflateOut.length - offset);
       if (readByte == -1) {
         break;
       }
       offset += readByte;
     }
   } catch (IOException ioexception) {
     throw new RuntimeException("error unzipping");
   }
   onDemandNode.buffer = new byte[offset];
   for (int position = 0; position < offset; position++) {
     onDemandNode.buffer[position] = deflateOut[position];
   }
   return onDemandNode;
 }