diff --git a/workspace/popjava/src/popjava/broker/Broker.java b/workspace/popjava/src/popjava/broker/Broker.java index 09c7d3d0..e8308986 100644 --- a/workspace/popjava/src/popjava/broker/Broker.java +++ b/workspace/popjava/src/popjava/broker/Broker.java @@ -91,6 +91,11 @@ public enum State{ // thread unique callers private static ThreadLocal remoteCaller = new InheritableThreadLocal<>(); + /** + * Request queue shared by all comboxes of this broker + */ + private final RequestQueue requestQueue = new RequestQueue(); + private State state; private ComboxServer[] comboxServers; private POPBuffer buffer; @@ -838,15 +843,10 @@ public POPAccessPoint getAccessPoint() { public void treatRequests() throws InterruptedException { setState(State.Running); while (getState() == State.Running) { - for (ComboxServer comboxServer : comboxServers) { - Request request = comboxServer.getRequestQueue().peek(REQUEST_QUEUE_TIMEOUT_MS, - TimeUnit.MILLISECONDS); - - if (request != null) { - serveRequest(request); - }else { - Thread.sleep(100); - } + Request request = requestQueue.peek(REQUEST_QUEUE_TIMEOUT_MS, TimeUnit.MILLISECONDS); + + if (request != null) { + serveRequest(request); } } LogWriter.writeDebugInfo("[Broker] Close broker "+popInfo.getClassName()); @@ -1179,4 +1179,8 @@ public String getLogPrefix() { + popInfo.getClass().getName() + ":"; } } + + public RequestQueue getRequestQueue() { + return requestQueue; + } } diff --git a/workspace/popjava/src/popjava/combox/ComboxServer.java b/workspace/popjava/src/popjava/combox/ComboxServer.java index a485f5b6..1aa3530b 100644 --- a/workspace/popjava/src/popjava/combox/ComboxServer.java +++ b/workspace/popjava/src/popjava/combox/ComboxServer.java @@ -13,7 +13,6 @@ public abstract class ComboxServer { static public final int ABORT = 2; protected int status = EXIT; - protected RequestQueue requestQueue = new RequestQueue(); protected Broker broker; protected int timeOut = 0; protected AccessPoint accessPoint; @@ -35,7 +34,7 @@ public ComboxServer(AccessPoint accessPoint, int timeout, Broker broker) { * @return The associated request queue */ public RequestQueue getRequestQueue() { - return requestQueue; - } + return broker.getRequestQueue(); + } } diff --git a/workspace/popjava/src/popjava/combox/plugin/ComboxServerPlugin.java b/workspace/popjava/src/popjava/combox/plugin/ComboxServerPlugin.java index 6c0e919c..f839b8db 100644 --- a/workspace/popjava/src/popjava/combox/plugin/ComboxServerPlugin.java +++ b/workspace/popjava/src/popjava/combox/plugin/ComboxServerPlugin.java @@ -2,7 +2,6 @@ import popjava.baseobject.AccessPoint; import popjava.broker.Broker; -import popjava.broker.RequestQueue; import popjava.combox.ComboxServer; /** @@ -20,13 +19,5 @@ public ComboxServerPlugin(AccessPoint accessPoint, int timeout, Broker broker) { super(accessPoint, timeout, broker); } - - /** - * Get the associated request queue - * @return The associated request queue - */ - public RequestQueue getRequestQueue() { - return requestQueue; - } } diff --git a/workspace/popjava/src/popjava/combox/socket/ComboxServerSocket.java b/workspace/popjava/src/popjava/combox/socket/ComboxServerSocket.java index 815e92ba..a13cc48c 100644 --- a/workspace/popjava/src/popjava/combox/socket/ComboxServerSocket.java +++ b/workspace/popjava/src/popjava/combox/socket/ComboxServerSocket.java @@ -50,7 +50,7 @@ public void createServer() { serverSocket = new ServerSocket(); serverSocket.setReceiveBufferSize(RECEIVE_BUFFER_SIZE); serverSocket.bind(new InetSocketAddress(accessPoint.getPort())); - serverCombox = new ComboxAcceptSocket(broker, requestQueue, + serverCombox = new ComboxAcceptSocket(broker, getRequestQueue(), serverSocket); serverCombox.setStatus(RUNNING); Thread thread = new Thread(serverCombox, "Server combox acception thread"); diff --git a/workspace/popjava/src/popjava/combox/ssl/ComboxServerSecureSocket.java b/workspace/popjava/src/popjava/combox/ssl/ComboxServerSecureSocket.java index 7f5f729d..ae4d1e5c 100644 --- a/workspace/popjava/src/popjava/combox/ssl/ComboxServerSecureSocket.java +++ b/workspace/popjava/src/popjava/combox/ssl/ComboxServerSecureSocket.java @@ -60,7 +60,7 @@ public void createServer() { serverSocket.setReceiveBufferSize(RECEIVE_BUFFER_SIZE); serverSocket.bind(new InetSocketAddress(accessPoint.getPort())); - serverCombox = new ComboxAcceptSecureSocket(broker, requestQueue, serverSocket); + serverCombox = new ComboxAcceptSecureSocket(broker, getRequestQueue(), serverSocket); serverCombox.setStatus(RUNNING); Thread thread = new Thread(serverCombox, "Server combox acception thread"); thread.start();