Skip to content

Commit 4ef86ab

Browse files
authored
Merge pull request #9 from pop-team/tfc
Merge upstream revisions.
2 parents 87a3590 + 0a4f9c8 commit 4ef86ab

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

workspace/popjava/src/popjava/broker/Broker.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public enum State{
9191
// thread unique callers
9292
private static ThreadLocal<POPRemoteCaller> remoteCaller = new InheritableThreadLocal<>();
9393

94+
/**
95+
* Request queue shared by all comboxes of this broker
96+
*/
97+
private final RequestQueue requestQueue = new RequestQueue();
98+
9499
private State state;
95100
private ComboxServer[] comboxServers;
96101
private POPBuffer buffer;
@@ -838,15 +843,10 @@ public POPAccessPoint getAccessPoint() {
838843
public void treatRequests() throws InterruptedException {
839844
setState(State.Running);
840845
while (getState() == State.Running) {
841-
for (ComboxServer comboxServer : comboxServers) {
842-
Request request = comboxServer.getRequestQueue().peek(REQUEST_QUEUE_TIMEOUT_MS,
843-
TimeUnit.MILLISECONDS);
844-
845-
if (request != null) {
846-
serveRequest(request);
847-
}else {
848-
Thread.sleep(100);
849-
}
846+
Request request = requestQueue.peek(REQUEST_QUEUE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
847+
848+
if (request != null) {
849+
serveRequest(request);
850850
}
851851
}
852852
LogWriter.writeDebugInfo("[Broker] Close broker "+popInfo.getClassName());
@@ -1179,4 +1179,8 @@ public String getLogPrefix() {
11791179
+ popInfo.getClass().getName() + ":";
11801180
}
11811181
}
1182+
1183+
public RequestQueue getRequestQueue() {
1184+
return requestQueue;
1185+
}
11821186
}

workspace/popjava/src/popjava/combox/ComboxServer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public abstract class ComboxServer {
1313
static public final int ABORT = 2;
1414

1515
protected int status = EXIT;
16-
protected RequestQueue requestQueue = new RequestQueue();
1716
protected Broker broker;
1817
protected int timeOut = 0;
1918
protected AccessPoint accessPoint;
@@ -35,7 +34,7 @@ public ComboxServer(AccessPoint accessPoint, int timeout, Broker broker) {
3534
* @return The associated request queue
3635
*/
3736
public RequestQueue getRequestQueue() {
38-
return requestQueue;
39-
}
37+
return broker.getRequestQueue();
38+
}
4039

4140
}

workspace/popjava/src/popjava/combox/plugin/ComboxServerPlugin.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import popjava.baseobject.AccessPoint;
44
import popjava.broker.Broker;
5-
import popjava.broker.RequestQueue;
65
import popjava.combox.ComboxServer;
76

87
/**
@@ -20,13 +19,5 @@ public ComboxServerPlugin(AccessPoint accessPoint, int timeout,
2019
Broker broker) {
2120
super(accessPoint, timeout, broker);
2221
}
23-
24-
/**
25-
* Get the associated request queue
26-
* @return The associated request queue
27-
*/
28-
public RequestQueue getRequestQueue() {
29-
return requestQueue;
30-
}
3122

3223
}

workspace/popjava/src/popjava/combox/socket/ComboxServerSocket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void createServer() {
5050
serverSocket = new ServerSocket();
5151
serverSocket.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
5252
serverSocket.bind(new InetSocketAddress(accessPoint.getPort()));
53-
serverCombox = new ComboxAcceptSocket(broker, requestQueue,
53+
serverCombox = new ComboxAcceptSocket(broker, getRequestQueue(),
5454
serverSocket);
5555
serverCombox.setStatus(RUNNING);
5656
Thread thread = new Thread(serverCombox, "Server combox acception thread");

workspace/popjava/src/popjava/combox/ssl/ComboxServerSecureSocket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void createServer() {
6060

6161
serverSocket.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
6262
serverSocket.bind(new InetSocketAddress(accessPoint.getPort()));
63-
serverCombox = new ComboxAcceptSecureSocket(broker, requestQueue, serverSocket);
63+
serverCombox = new ComboxAcceptSecureSocket(broker, getRequestQueue(), serverSocket);
6464
serverCombox.setStatus(RUNNING);
6565
Thread thread = new Thread(serverCombox, "Server combox acception thread");
6666
thread.start();

0 commit comments

Comments
 (0)