Skip to content

Commit 3f1426a

Browse files
author
jython234
committed
Update to protocol 6, and change to ConcurrentLinkedDeque
1 parent d4e2713 commit 3f1426a

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

src/main/java/net/beaconpe/jraklib/JRakLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ All credit goes to the PocketMine Project (http://pocketmine.net)
2929
*/
3030
public abstract class JRakLib {
3131
public static final String VERSION = "1.0";
32-
public static final byte PROTOCOL = 5;
32+
public static final byte PROTOCOL = 6;
3333
public static final byte[] MAGIC = new byte[]{
3434
0x00, (byte) 0xff, (byte) 0xff, 0x00,
3535
(byte) 0xfe, (byte) 0xfe, (byte) 0xfe, (byte) 0xfe,

src/main/java/net/beaconpe/jraklib/server/JRakLibServer.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ All credit goes to the PocketMine Project (http://pocketmine.net)
2525

2626
import java.net.InetSocketAddress;
2727
import java.util.ArrayList;
28+
import java.util.Deque;
2829
import java.util.List;
30+
import java.util.concurrent.ConcurrentLinkedDeque;
2931

3032
/**
3133
* JRakLib server.
@@ -36,8 +38,8 @@ public class JRakLibServer extends Thread{
3638
protected Logger logger;
3739
protected boolean shutdown = false;
3840

39-
protected List<byte[]> externalQueue;
40-
protected List<byte[]> internalQueue;
41+
protected Deque<byte[]> externalQueue;
42+
protected Deque<byte[]> internalQueue;
4143

4244
public JRakLibServer(Logger logger, int port, String _interface){
4345
if(port < 1 || port > 65536){
@@ -47,8 +49,8 @@ public JRakLibServer(Logger logger, int port, String _interface){
4749
this.logger = logger;
4850
this.shutdown = false;
4951

50-
externalQueue = new ArrayList<>();
51-
internalQueue = new ArrayList<>();
52+
externalQueue = new ConcurrentLinkedDeque<>();
53+
internalQueue = new ConcurrentLinkedDeque<>();
5254

5355
start();
5456
}
@@ -73,40 +75,34 @@ public Logger getLogger(){
7375
return logger;
7476
}
7577

76-
public List<byte[]> getExternalQueue(){
78+
public Deque<byte[]> getExternalQueue(){
7779
return externalQueue;
7880
}
7981

80-
public List<byte[]> getInternalQueue(){
82+
public Deque<byte[]> getInternalQueue(){
8183
return internalQueue;
8284
}
8385

8486
public void pushMainToThreadPacket(byte[] bytes){
85-
internalQueue.add(bytes);
87+
internalQueue.addLast(bytes);
8688
}
8789

8890
public byte[] readMainToThreadPacket(){
8991
if(!internalQueue.isEmpty()) {
90-
byte[] d = internalQueue.get(0);
91-
internalQueue.remove(d);
92-
return d;
93-
} else {
94-
return null;
92+
return internalQueue.pop();
9593
}
94+
return null;
9695
}
9796

9897
public void pushThreadToMainPacket(byte[] bytes){
99-
externalQueue.add(bytes);
98+
externalQueue.addLast(bytes);
10099
}
101100

102101
public byte[] readThreadToMainPacket(){
103102
if(!externalQueue.isEmpty()) {
104-
byte[] d = externalQueue.get(0);
105-
externalQueue.remove(d);
106-
return d;
107-
} else {
108-
return null;
103+
externalQueue.pop();
109104
}
105+
return null;
110106
}
111107

112108
private class ShutdownHandler extends Thread{

0 commit comments

Comments
 (0)