3
3
import org .wowtools .hppt .common .pojo .SendAbleSessionBytes ;
4
4
import org .wowtools .hppt .common .pojo .SessionBytes ;
5
5
import org .wowtools .hppt .common .util .AesCipherUtil ;
6
+ import org .wowtools .hppt .common .util .BufferPool ;
6
7
import org .wowtools .hppt .common .util .BytesUtil ;
7
8
8
9
import java .nio .charset .StandardCharsets ;
@@ -34,10 +35,10 @@ public static final class Client {
34
35
public final String clientId ;
35
36
public final AesCipherUtil aesCipherUtil ;
36
37
37
- private final BlockingQueue <String > commandQueue = new LinkedBlockingQueue <>();
38
+ private final BufferPool <String > commandQueue = new BufferPool <>("<LoginClientService-Client-commandQueue" );
38
39
39
- private final BlockingQueue <SendAbleSessionBytes > sessionBytesQueue = new LinkedBlockingQueue <>();
40
- public final BlockingQueue <byte []> receiveClientBytes = new LinkedBlockingQueue <>();
40
+ private final BufferPool <SendAbleSessionBytes > sessionBytesQueue = new BufferPool <>("<LoginClientService-Client-sessionBytesQueue" );
41
+ public final BufferPool <byte []> receiveClientBytes = new BufferPool <>("<LoginClientService-Client-receiveClientBytes" );
41
42
42
43
private final HashMap <Integer , ServerSession > sessions = new HashMap <>();
43
44
@@ -57,12 +58,7 @@ public void addCommand(String cmd) {
57
58
58
59
//取出所有需要向客户端发送的命令 无命令则返回null
59
60
public List <String > fetchCommands () {
60
- if (commandQueue .isEmpty ()) {
61
- return null ;
62
- }
63
- List <String > res = new LinkedList <>();
64
- commandQueue .drainTo (res );
65
- return res ;
61
+ return commandQueue .drainToList ();
66
62
}
67
63
68
64
public void addSession (ServerSession session ) {
@@ -99,7 +95,7 @@ public List<SendAbleSessionBytes> fetchBytes(long maxReturnBodySize) {
99
95
}
100
96
List <SendAbleSessionBytes > bytesList = new LinkedList <>();
101
97
if (maxReturnBodySize < 0 ) {
102
- sessionBytesQueue .drainTo (bytesList );
98
+ sessionBytesQueue .drainToList (bytesList );
103
99
} else {
104
100
//根据maxReturnBodySize的限制取出队列中的数据返回
105
101
long currentReturnBodySize = 0L ;
@@ -119,12 +115,7 @@ public List<SendAbleSessionBytes> fetchBytes(long maxReturnBodySize) {
119
115
//取出所有需要向客户端发送的bytes 取出的bytes会按相同sessionId进行整合 无bytes则阻塞3秒后返回
120
116
public List <SendAbleSessionBytes > fetchBytesBlocked (long maxReturnBodySize ) {
121
117
List <SendAbleSessionBytes > bytesList = new LinkedList <>();
122
- SendAbleSessionBytes first ;
123
- try {
124
- first = sessionBytesQueue .poll (3 , TimeUnit .SECONDS );
125
- } catch (InterruptedException e ) {
126
- return bytesList ;
127
- }
118
+ SendAbleSessionBytes first = sessionBytesQueue .poll (3 , TimeUnit .SECONDS );
128
119
if (null == first ) {
129
120
return bytesList ;
130
121
}
@@ -133,7 +124,7 @@ public List<SendAbleSessionBytes> fetchBytesBlocked(long maxReturnBodySize) {
133
124
return bytesList ;
134
125
}
135
126
if (maxReturnBodySize < 0 ) {
136
- sessionBytesQueue .drainTo (bytesList );
127
+ sessionBytesQueue .drainToList (bytesList );
137
128
return merge (bytesList );
138
129
} else {
139
130
//根据maxReturnBodySize的限制取出队列中的数据返回
0 commit comments