Skip to content

Commit 1e008a4

Browse files
committed
refactor: rename high/standard priority
1 parent d0efc57 commit 1e008a4

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

src/main/java/org/runejs/client/net/UpdateServer.java

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ public class UpdateServer implements IUpdateServer {
1717
private Buffer fileDataBuffer = new Buffer(8);
1818
private Buffer inboundFile;
1919
private Buffer crcTableBuffer;
20-
private HashTable immediateWriteQueue = new HashTable(4096);
21-
private HashTable activeRequests = new HashTable(32);
22-
private HashTable queuedRequests = new HashTable(4096);
23-
private HashTable writeQueue = new HashTable(4096);
20+
private HashTable highPriorityWriteQueue = new HashTable(4096);
21+
private HashTable highPriorityOutgoingRequests = new HashTable(32);
22+
private HashTable standardPriorityOutgoingRequests = new HashTable(4096);
23+
private HashTable standardPriorityWriteQueue = new HashTable(4096);
2424
private UpdateServerNode currentResponse;
2525
private CRC32 crc32 = new CRC32();
2626
private byte encryption = (byte) 0;
27-
private int immediateResponses = 0;
28-
private int pendingWrites = 0;
29-
private int immediateWrites = 0;
30-
private int pendingResponses = 0;
31-
private boolean priorityRequest;
27+
private int highPriorityResponseCount = 0;
28+
private int standardPriorityWriteCount = 0;
29+
private int highPriorityWriteCount = 0;
30+
private int standardPriorityResponseCount = 0;
31+
private boolean highPriorityRequest;
3232
private NodeQueue pendingWriteQueue = new NodeQueue();
3333
private int blockOffset = 0;
3434
private int msSinceLastUpdate = 0;
@@ -74,26 +74,26 @@ public void receiveConnection(GameSocket socket, boolean isLoggedIn) {
7474
currentResponse = null;
7575

7676
for(; ; ) {
77-
UpdateServerNode updateServerNode = (UpdateServerNode) activeRequests.getNextNode();
77+
UpdateServerNode updateServerNode = (UpdateServerNode) highPriorityOutgoingRequests.getNextNode();
7878
if(updateServerNode == null) {
7979
break;
8080
}
8181

82-
immediateWriteQueue.put(updateServerNode.key, updateServerNode);
83-
immediateResponses--;
84-
immediateWrites++;
82+
highPriorityWriteQueue.put(updateServerNode.key, updateServerNode);
83+
highPriorityResponseCount--;
84+
highPriorityWriteCount++;
8585
}
8686

8787
for(; ; ) {
88-
UpdateServerNode updateServerNode = (UpdateServerNode) queuedRequests.getNextNode();
88+
UpdateServerNode updateServerNode = (UpdateServerNode) standardPriorityOutgoingRequests.getNextNode();
8989
if(updateServerNode == null) {
9090
break;
9191
}
9292

9393
pendingWriteQueue.unshift(updateServerNode);
94-
writeQueue.put(updateServerNode.key, updateServerNode);
95-
pendingResponses--;
96-
pendingWrites++;
94+
standardPriorityWriteQueue.put(updateServerNode.key, updateServerNode);
95+
standardPriorityResponseCount--;
96+
standardPriorityWriteCount++;
9797
}
9898

9999
if(encryption != 0) {
@@ -129,7 +129,7 @@ public boolean poll() {
129129
currentMsSinceLastUpdate = 200;
130130
}
131131
msSinceLastUpdate += currentMsSinceLastUpdate;
132-
if(pendingResponses == 0 && immediateResponses == 0 && pendingWrites == 0 && immediateWrites == 0) {
132+
if(standardPriorityResponseCount == 0 && highPriorityResponseCount == 0 && standardPriorityWriteCount == 0 && highPriorityWriteCount == 0) {
133133
return true;
134134
}
135135
if(updateServerSocket == null) {
@@ -142,29 +142,29 @@ public boolean poll() {
142142
}
143143

144144
// Immediate file requests
145-
for(/**/; immediateResponses < 20; immediateResponses++) {
146-
if(immediateWrites <= 0) {
145+
for(/**/; highPriorityResponseCount < 20; highPriorityResponseCount++) {
146+
if(highPriorityWriteCount <= 0) {
147147
break;
148148
}
149-
UpdateServerNode updateServerNode = (UpdateServerNode) immediateWriteQueue.getNextNode();
149+
UpdateServerNode updateServerNode = (UpdateServerNode) highPriorityWriteQueue.getNextNode();
150150
Buffer buffer = new Buffer(4);
151151
buffer.putByte(Opcode.PRIORITY_REQUEST.getValue()); // immediate file request
152152
buffer.putMediumBE((int) updateServerNode.key); // file index + file id
153153
updateServerSocket.sendDataFromBuffer(4, 0, buffer.buffer);
154-
activeRequests.put(updateServerNode.key, updateServerNode);
155-
immediateWrites--;
154+
highPriorityOutgoingRequests.put(updateServerNode.key, updateServerNode);
155+
highPriorityWriteCount--;
156156
}
157157

158158
// Queuable file requests
159-
for(/**/; pendingResponses < 20 && pendingWrites > 0; pendingWrites--) {
159+
for(/**/; standardPriorityResponseCount < 20 && standardPriorityWriteCount > 0; standardPriorityWriteCount--) {
160160
UpdateServerNode updateServerNode = (UpdateServerNode) pendingWriteQueue.next();
161161
Buffer buffer = new Buffer(4);
162162
buffer.putByte(Opcode.REQUEST.getValue()); // queued file request
163163
buffer.putMediumBE((int) updateServerNode.key); // file index + file id
164164
updateServerSocket.sendDataFromBuffer(4, 0, buffer.buffer);
165165
updateServerNode.clear();
166-
queuedRequests.put(updateServerNode.key, updateServerNode);
167-
pendingResponses++;
166+
standardPriorityOutgoingRequests.put(updateServerNode.key, updateServerNode);
167+
standardPriorityResponseCount++;
168168
}
169169

170170
for(int i1 = 0; i1 < 100; i1++) {
@@ -232,18 +232,18 @@ public boolean poll() {
232232

233233
ioExceptions = 0;
234234
crcMismatches = 0;
235-
currentResponse.cacheArchive.method196((currentResponse.key & 0xff0000L) == 16711680L, (int) (currentResponse.key & 0xffffL), priorityRequest, inboundFile.buffer);
235+
currentResponse.cacheArchive.method196((currentResponse.key & 0xff0000L) == 16711680L, (int) (currentResponse.key & 0xffffL), highPriorityRequest, inboundFile.buffer);
236236
}
237237

238238
currentResponse.unlink();
239239
currentResponse = null;
240240
inboundFile = null;
241241
blockOffset = 0;
242242

243-
if(!priorityRequest) {
244-
pendingResponses--;
243+
if(!highPriorityRequest) {
244+
standardPriorityResponseCount--;
245245
} else {
246-
immediateResponses--;
246+
highPriorityResponseCount--;
247247
}
248248
} else {
249249
if(blockOffset != 512) {
@@ -278,12 +278,12 @@ public boolean poll() {
278278
int fileCompression = fileDataBuffer.getUnsignedByte();
279279
int fileSize = fileDataBuffer.getIntBE();
280280
long fileKey = ((long) fileIndexId << 16) + fileId;
281-
UpdateServerNode updateServerNode = (UpdateServerNode) activeRequests.getNode(fileKey);
282-
priorityRequest = true;
281+
UpdateServerNode updateServerNode = (UpdateServerNode) highPriorityOutgoingRequests.getNode(fileKey);
282+
highPriorityRequest = true;
283283

284284
if(updateServerNode == null) {
285-
updateServerNode = (UpdateServerNode) queuedRequests.getNode(fileKey);
286-
priorityRequest = false;
285+
updateServerNode = (UpdateServerNode) standardPriorityOutgoingRequests.getNode(fileKey);
286+
highPriorityRequest = false;
287287
}
288288

289289
if(updateServerNode == null) {
@@ -325,45 +325,45 @@ public boolean poll() {
325325
}
326326
}
327327

328-
public void method327(boolean unknownBool, CacheArchive archive, int archiveIndexId, int fileId, byte arg4, int expectedCrc) {
328+
public void method327(boolean isPriority, CacheArchive archive, int archiveIndexId, int fileId, byte arg4, int expectedCrc) {
329329
long fileKey = fileId + ((long) archiveIndexId << 16);
330-
UpdateServerNode updateServerNode = (UpdateServerNode) immediateWriteQueue.getNode(fileKey);
330+
UpdateServerNode updateServerNode = (UpdateServerNode) highPriorityWriteQueue.getNode(fileKey);
331331

332332
if (updateServerNode == null) {
333-
updateServerNode = (UpdateServerNode) activeRequests.getNode(fileKey);
333+
updateServerNode = (UpdateServerNode) highPriorityOutgoingRequests.getNode(fileKey);
334334
if (updateServerNode == null) {
335-
updateServerNode = (UpdateServerNode) writeQueue.getNode(fileKey);
335+
updateServerNode = (UpdateServerNode) standardPriorityWriteQueue.getNode(fileKey);
336336
if (updateServerNode == null) {
337-
if (!unknownBool) {
338-
updateServerNode = (UpdateServerNode) queuedRequests.getNode(fileKey);
337+
if (!isPriority) {
338+
updateServerNode = (UpdateServerNode) standardPriorityOutgoingRequests.getNode(fileKey);
339339
if (updateServerNode != null)
340340
return;
341341
}
342342
updateServerNode = new UpdateServerNode();
343343
updateServerNode.crc = expectedCrc;
344344
updateServerNode.padding = arg4;
345345
updateServerNode.cacheArchive = archive;
346-
if (unknownBool) {
347-
immediateWriteQueue.put(fileKey, updateServerNode);
348-
immediateWrites++;
346+
if (isPriority) {
347+
highPriorityWriteQueue.put(fileKey, updateServerNode);
348+
highPriorityWriteCount++;
349349
} else {
350350
pendingWriteQueue.push(updateServerNode);
351-
writeQueue.put(fileKey, updateServerNode);
352-
pendingWrites++;
351+
standardPriorityWriteQueue.put(fileKey, updateServerNode);
352+
standardPriorityWriteCount++;
353353
}
354-
} else if (unknownBool) {
354+
} else if (isPriority) {
355355
updateServerNode.clear();
356-
immediateWriteQueue.put(fileKey, updateServerNode);
357-
pendingWrites--;
358-
immediateWrites++;
356+
highPriorityWriteQueue.put(fileKey, updateServerNode);
357+
standardPriorityWriteCount--;
358+
highPriorityWriteCount++;
359359
}
360360
}
361361
}
362362
}
363363

364364
public void method399(int arg0, int arg2) {
365365
long l = (arg0 << 16) + arg2;
366-
UpdateServerNode updateServerNode = (UpdateServerNode) writeQueue.getNode(l);
366+
UpdateServerNode updateServerNode = (UpdateServerNode) standardPriorityWriteQueue.getNode(l);
367367
if (updateServerNode != null) {
368368
pendingWriteQueue.unshift(updateServerNode);
369369
}
@@ -424,13 +424,13 @@ public int calculateDataLoaded(int volume, int file) {
424424
}
425425

426426
@Override
427-
public int getActiveCount(boolean pending, boolean immediate) {
427+
public int getActiveCount(boolean includeStandardPriority, boolean includeHighPriority) {
428428
int total = 0;
429-
if (immediate) {
430-
total += immediateResponses + immediateWrites;
429+
if (includeHighPriority) {
430+
total += highPriorityResponseCount + highPriorityWriteCount;
431431
}
432-
if (pending) {
433-
total += pendingResponses + pendingWrites;
432+
if (includeStandardPriority) {
433+
total += standardPriorityResponseCount + standardPriorityWriteCount;
434434
}
435435
return total;
436436
}

0 commit comments

Comments
 (0)