workers = new WorkerStack(maxThreads);\r
}\r
\r
- // Start acceptor thread\r
+ // Start acceptor threads\r
for (int i = 0; i < acceptorThreadCount; i++) {\r
Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);\r
acceptorThread.setPriority(threadPriority);\r
acceptorThread.start();\r
}\r
\r
- // Start poller thread\r
+ // Start poller threads\r
pollers = new Poller[pollerThreadCount];\r
for (int i = 0; i < pollerThreadCount; i++) {\r
pollers[i] = new Poller();\r
pollerThread.start();\r
}\r
\r
- // Start sendfile thread\r
+ // Start sendfile threads\r
if (useSendfile) {\r
sendfiles = new Sendfile[sendfileThreadCount];\r
for (int i = 0; i < sendfileThreadCount; i++) {\r
protected long sendfilePollset = 0;\r
protected long pool = 0;\r
protected long[] desc;\r
- protected HashMap sendfileData;\r
+ protected HashMap<Long, SendfileData> sendfileData;\r
\r
protected int sendfileCount;\r
public int getSendfileCount() { return sendfileCount; }\r
\r
- protected ArrayList addS;\r
+ protected ArrayList<SendfileData> addS;\r
\r
/**\r
* Create the sendfile poller. With some versions of APR, the maximum poller size will\r
sendfilePollset = allocatePoller(size, pool, soTimeout);\r
}\r
desc = new long[size * 2];\r
- sendfileData = new HashMap(size);\r
- addS = new ArrayList();\r
+ sendfileData = new HashMap<Long, SendfileData>(size);\r
+ addS = new ArrayList<SendfileData>();\r
}\r
\r
/**\r
protected void destroy() {\r
// Close any socket remaining in the add queue\r
for (int i = (addS.size() - 1); i >= 0; i--) {\r
- SendfileData data = (SendfileData) addS.get(i);\r
+ SendfileData data = addS.get(i);\r
Socket.destroy(data.socket);\r
}\r
// Close all sockets still in the poller\r
if (addS.size() > 0) {\r
synchronized (this) {\r
for (int i = (addS.size() - 1); i >= 0; i--) {\r
- SendfileData data = (SendfileData) addS.get(i);\r
+ SendfileData data = addS.get(i);\r
int rv = Poll.add(sendfilePollset, data.socket, Poll.APR_POLLOUT);\r
if (rv == Status.APR_SUCCESS) {\r
sendfileData.put(new Long(data.socket), data);\r
for (int n = 0; n < rv; n++) {\r
// Get the sendfile state\r
SendfileData state =\r
- (SendfileData) sendfileData.get(new Long(desc[n*2+1]));\r
+ sendfileData.get(new Long(desc[n*2+1]));\r
// Problem events\r
if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP)\r
|| ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)) {\r
/**
- * The acceptor thread.
- */
- protected Thread acceptorThread = null;
-
-
- /**
* Available workers.
*/
protected WorkerStack workers = null;
/**
+ * Acceptor thread count.
+ */
+ protected int acceptorThreadCount = 0;
+ public void setAcceptorThreadCount(int acceptorThreadCount) { this.acceptorThreadCount = acceptorThreadCount; }
+ public int getAcceptorThreadCount() { return acceptorThreadCount; }
+
+
+ /**
* External Executor based thread pool.
*/
protected Executor executor = null;
try {
socket.close();
} catch (IOException e) {
+ // Ignore
}
}
} catch (Throwable t) {
// -------------------- Public methods --------------------
- public void init() throws IOException, InstantiationException {
+ public void init()
+ throws Exception {
+
+ if (initialized)
+ return;
+
+ // Initialize thread count defaults for acceptor
+ if (acceptorThreadCount == 0) {
+ acceptorThreadCount = 1;
+ }
if (serverSocketFactory == null) {
serverSocketFactory = ServerSocketFactory.getDefault();
}
}
//if( serverTimeout >= 0 )
// serverSocket.setSoTimeout( serverTimeout );
+
initialized = true;
+
}
public void start()
workers = new WorkerStack(maxThreads);
}
- // Start acceptor thread
- acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor");
- acceptorThread.setPriority(threadPriority);
- acceptorThread.setDaemon(daemon);
- acceptorThread.start();
+ // Start acceptor threads
+ for (int i = 0; i < acceptorThreadCount; i++) {
+ Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);
+ acceptorThread.setPriority(threadPriority);
+ acceptorThread.setDaemon(daemon);
+ acceptorThread.start();
+ }
}
}
if (running) {
running = false;
unlockAccept();
- acceptorThread = null;
}
}