org.apache.tomcat.jni.Pool Java Examples
The following examples show how to use
org.apache.tomcat.jni.Pool.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AprSocketWrapperImpl.java From cloudstack with Apache License 2.0 | 6 votes |
void destroyPull() { if (shutdowned) return; // Causes segfault in AprSocketSource.poll() method, so this function must be called from it try { Socket.close(socket); // or // Socket.shutdown(socket, Socket.APR_SHUTDOWN_READWRITE); Pool.destroy(pool); } catch (Exception e) { s_logger.info("[ignored]" + "failure during network cleanup: " + e.getLocalizedMessage()); } }
Example #2
Source File: AprEndpoint.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create the sendfile poller. With some versions of APR, the maximum * poller size will be 62 (recompiling APR is necessary to remove this * limitation). */ protected void init() { pool = Pool.create(serverSockPool); int size = sendfileSize; if (size <= 0) { size = (OS.IS_WIN32 || OS.IS_WIN64) ? (1 * 1024) : (16 * 1024); } sendfilePollset = allocatePoller(size, pool, getSoTimeout()); if (sendfilePollset == 0 && size > 1024) { size = 1024; sendfilePollset = allocatePoller(size, pool, getSoTimeout()); } if (sendfilePollset == 0) { size = 62; sendfilePollset = allocatePoller(size, pool, getSoTimeout()); } desc = new long[size * 2]; sendfileData = new HashMap<Long, SendfileData>(size); addS = new ArrayList<SendfileData>(); }
Example #3
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Deallocate APR memory pools, and close server socket. */ @Override public void unbind() throws Exception { if (running) { stop(); } // Destroy pool if it was initialised if (serverSockPool != 0) { Pool.destroy(serverSockPool); serverSockPool = 0; } doCloseServerSocket(); destroySsl(); // Close all APR memory pools and resources if initialised if (rootPool != 0) { Pool.destroy(rootPool); rootPool = 0; } getHandler().recycle(); }
Example #4
Source File: AprEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create the sendfile poller. With some versions of APR, the maximum * poller size will be 62 (recompiling APR is necessary to remove this * limitation). */ protected void init() { pool = Pool.create(serverSockPool); int size = sendfileSize; if (size <= 0) { size = (OS.IS_WIN32 || OS.IS_WIN64) ? (1 * 1024) : (16 * 1024); } sendfilePollset = allocatePoller(size, pool, getSoTimeout()); if (sendfilePollset == 0 && size > 1024) { size = 1024; sendfilePollset = allocatePoller(size, pool, getSoTimeout()); } if (sendfilePollset == 0) { size = 62; sendfilePollset = allocatePoller(size, pool, getSoTimeout()); } desc = new long[size * 2]; sendfileData = new HashMap<Long, SendfileData>(size); addS = new ArrayList<SendfileData>(); }
Example #5
Source File: AprEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Destroy the poller. */ protected void destroy() { sendfileRunning = false; // Wait for polltime before doing anything, so that the poller threads // exit, otherwise parallel destruction of sockets which are still // in the poller can cause problems try { synchronized (this) { this.notify(); this.wait(pollTime / 1000); } } catch (InterruptedException e) { // Ignore } // Close any socket remaining in the add queue for (int i = (addS.size() - 1); i >= 0; i--) { SendfileData data = addS.get(i); closeSocket(data.socket); } // Close all sockets still in the poller int rv = Poll.pollset(sendfilePollset, desc); if (rv > 0) { for (int n = 0; n < rv; n++) { closeSocket(desc[n*2+1]); } } Pool.destroy(pool); sendfileData.clear(); }
Example #6
Source File: TestXxxEndpoint.java From tomcatsrc with Apache License 2.0 | 5 votes |
private void destroyAprSocket(long serverSock, long pool) { if (serverSock != 0) { Socket.shutdown(serverSock, Socket.APR_SHUTDOWN_READWRITE); Socket.close(serverSock); Socket.destroy(serverSock); } if (pool != 0) { Pool.destroy(pool); pool = 0; } }
Example #7
Source File: TestXxxEndpoint.java From tomcatsrc with Apache License 2.0 | 5 votes |
private long createAprPool() { // Create the pool for the server socket try { return Pool.create(0); } catch (UnsatisfiedLinkError e) { log.error("Could not create socket pool", e); return 0; } }
Example #8
Source File: AprEndpoint.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Destroy the poller. */ protected void destroy() { sendfileRunning = false; // Wait for polltime before doing anything, so that the poller threads // exit, otherwise parallel destruction of sockets which are still // in the poller can cause problems try { synchronized (this) { this.notify(); this.wait(pollTime / 1000); } } catch (InterruptedException e) { // Ignore } // Close any socket remaining in the add queue for (int i = (addS.size() - 1); i >= 0; i--) { SendfileData data = addS.get(i); closeSocket(data.socket); } // Close all sockets still in the poller int rv = Poll.pollset(sendfilePollset, desc); if (rv > 0) { for (int n = 0; n < rv; n++) { closeSocket(desc[n*2+1]); } } Pool.destroy(pool); sendfileData.clear(); }
Example #9
Source File: AprEndpoint.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Deallocate APR memory pools, and close server socket. */ @Override public void unbind() throws Exception { if (running) { stop(); } // Destroy pool if it was initialised if (serverSockPool != 0) { Pool.destroy(serverSockPool); serverSockPool = 0; } // Close server socket if it was initialised if (serverSock != 0) { Socket.close(serverSock); serverSock = 0; } sslContext = 0; // Close all APR memory pools and resources if initialised if (rootPool != 0) { Pool.destroy(rootPool); rootPool = 0; } handler.recycle(); }
Example #10
Source File: TestXxxEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private void destroyAprSocket(long serverSock, long pool) { if (serverSock != 0) { Socket.shutdown(serverSock, Socket.APR_SHUTDOWN_READWRITE); Socket.close(serverSock); Socket.destroy(serverSock); } if (pool != 0) { Pool.destroy(pool); pool = 0; } }
Example #11
Source File: TestXxxEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private long createAprPool() { // Create the pool for the server socket try { return Pool.create(0); } catch (UnsatisfiedLinkError e) { log.error("Could not create socket pool", e); return 0; } }
Example #12
Source File: AprEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Deallocate APR memory pools, and close server socket. */ @Override public void unbind() throws Exception { if (running) { stop(); } // Destroy pool if it was initialised if (serverSockPool != 0) { Pool.destroy(serverSockPool); serverSockPool = 0; } // Close server socket if it was initialised if (serverSock != 0) { Socket.close(serverSock); serverSock = 0; } sslContext = 0; // Close all APR memory pools and resources if initialised if (rootPool != 0) { Pool.destroy(rootPool); rootPool = 0; } handler.recycle(); }
Example #13
Source File: TestXxxEndpoint.java From Tomcat8-Source-Read with MIT License | 5 votes |
private void destroyAprSocket(long serverSock, long pool) { if (serverSock != 0) { Socket.shutdown(serverSock, Socket.APR_SHUTDOWN_READWRITE); Socket.close(serverSock); Socket.destroy(serverSock); } if (pool != 0) { Pool.destroy(pool); pool = 0; } }
Example #14
Source File: TestXxxEndpoint.java From Tomcat8-Source-Read with MIT License | 5 votes |
private long createAprPool() { // Create the pool for the server socket try { return Pool.create(0); } catch (UnsatisfiedLinkError e) { log.error("Could not create socket pool", e); return 0; } }
Example #15
Source File: OpenSSLContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public synchronized void destroy() { // Guard against multiple destroyPools() calls triggered by construction exception and finalize() later if (aprPoolDestroyed.compareAndSet(0, 1)) { if (ctx != 0) { SSLContext.free(ctx); } if (cctx != 0) { SSLConf.free(cctx); } if (aprPool != 0) { Pool.destroy(aprPool); } } }
Example #16
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Destroy the poller. */ protected void destroy() { sendfileRunning = false; // Wait for polltime before doing anything, so that the poller threads // exit, otherwise parallel destruction of sockets which are still // in the poller can cause problems try { synchronized (this) { this.notify(); this.wait(pollTime / 1000); } } catch (InterruptedException e) { // Ignore } // Close any socket remaining in the add queue for (int i = (addS.size() - 1); i >= 0; i--) { SendfileData data = addS.get(i); closeSocket(data.socket); } // Close all sockets still in the poller int rv = Poll.pollset(sendfilePollset, desc); if (rv > 0) { for (int n = 0; n < rv; n++) { closeSocket(desc[n*2+1]); } } Pool.destroy(pool); sendfileData.clear(); }
Example #17
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Create the sendfile poller. */ protected void init() { pool = Pool.create(serverSockPool); int size = sendfileSize; if (size <= 0) { size = 16 * 1024; } sendfilePollset = allocatePoller(size, pool, getConnectionTimeout()); desc = new long[size * 2]; sendfileData = new HashMap<>(size); addS = new ArrayList<>(); }
Example #18
Source File: AprEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Create the poller. With some versions of APR, the maximum poller size * will be 62 (recompiling APR is necessary to remove this limitation). */ protected void init() { pool = Pool.create(serverSockPool); // Single poller by default int defaultPollerSize = getMaxConnections(); if ((OS.IS_WIN32 || OS.IS_WIN64) && (defaultPollerSize > 1024)) { // The maximum per poller to get reasonable performance is 1024 // Adjust poller size so that it won't reach the limit. This is // a limitation of XP / Server 2003 that has been fixed in // Vista / Server 2008 onwards. actualPollerSize = 1024; } else { actualPollerSize = defaultPollerSize; } timeouts = new SocketTimeouts(defaultPollerSize); // At the moment, setting the timeout is useless, but it could get // used again as the normal poller could be faster using maintain. // It might not be worth bothering though. long pollset = allocatePoller(actualPollerSize, pool, -1); if (pollset == 0 && actualPollerSize > 1024) { actualPollerSize = 1024; pollset = allocatePoller(actualPollerSize, pool, -1); } if (pollset == 0) { actualPollerSize = 62; pollset = allocatePoller(actualPollerSize, pool, -1); } pollerCount = defaultPollerSize / actualPollerSize; pollerTime = pollTime / pollerCount; nextPollerTime = pollerTime; pollers = new long[pollerCount]; pollers[0] = pollset; for (int i = 1; i < pollerCount; i++) { pollers[i] = allocatePoller(actualPollerSize, pool, -1); } pollerSpace = new int[pollerCount]; for (int i = 0; i < pollerCount; i++) { pollerSpace[i] = actualPollerSize; } desc = new long[actualPollerSize * 2]; connectionCount.set(0); addList = new SocketList(defaultPollerSize); closeList = new SocketList(defaultPollerSize); }
Example #19
Source File: AprEndpoint.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Add the sendfile data to the sendfile poller. Note that in most cases, * the initial non blocking calls to sendfile will return right away, and * will be handled asynchronously inside the kernel. As a result, * the poller will never be used. * * @param data containing the reference to the data which should be snet * @return true if all the data has been sent right away, and false * otherwise */ public boolean add(SendfileData data) { // Initialize fd from data given try { data.fdpool = Socket.pool(data.socket); data.fd = File.open (data.fileName, File.APR_FOPEN_READ | File.APR_FOPEN_SENDFILE_ENABLED | File.APR_FOPEN_BINARY, 0, data.fdpool); data.pos = data.start; // Set the socket to nonblocking mode Socket.timeoutSet(data.socket, 0); while (true) { long nw = Socket.sendfilen(data.socket, data.fd, data.pos, data.end - data.pos, 0); if (nw < 0) { if (!(-nw == Status.EAGAIN)) { Pool.destroy(data.fdpool); data.socket = 0; return false; } else { // Break the loop and add the socket to poller. break; } } else { data.pos = data.pos + nw; if (data.pos >= data.end) { // Entire file has been sent Pool.destroy(data.fdpool); // Set back socket to blocking mode Socket.timeoutSet( data.socket, getSoTimeout() * 1000); return true; } } } } catch (Exception e) { log.warn(sm.getString("endpoint.sendfile.error"), e); return false; } // Add socket to the list. Newly added sockets will wait // at most for pollTime before being polled synchronized (this) { addS.add(data); this.notify(); } return false; }
Example #20
Source File: AprEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Create the poller. With some versions of APR, the maximum poller size * will be 62 (recompiling APR is necessary to remove this limitation). */ protected void init() { pool = Pool.create(serverSockPool); // Single poller by default int defaultPollerSize = getMaxConnections(); if ((OS.IS_WIN32 || OS.IS_WIN64) && (defaultPollerSize > 1024)) { // The maximum per poller to get reasonable performance is 1024 // Adjust poller size so that it won't reach the limit. This is // a limitation of XP / Server 2003 that has been fixed in // Vista / Server 2008 onwards. actualPollerSize = 1024; } else { actualPollerSize = defaultPollerSize; } timeouts = new SocketTimeouts(defaultPollerSize); // At the moment, setting the timeout is useless, but it could get // used again as the normal poller could be faster using maintain. // It might not be worth bothering though. long pollset = allocatePoller(actualPollerSize, pool, -1); if (pollset == 0 && actualPollerSize > 1024) { actualPollerSize = 1024; pollset = allocatePoller(actualPollerSize, pool, -1); } if (pollset == 0) { actualPollerSize = 62; pollset = allocatePoller(actualPollerSize, pool, -1); } pollerCount = defaultPollerSize / actualPollerSize; pollerTime = pollTime / pollerCount; nextPollerTime = pollerTime; pollers = new long[pollerCount]; pollers[0] = pollset; for (int i = 1; i < pollerCount; i++) { pollers[i] = allocatePoller(actualPollerSize, pool, -1); } pollerSpace = new int[pollerCount]; for (int i = 0; i < pollerCount; i++) { pollerSpace[i] = actualPollerSize; } desc = new long[actualPollerSize * 2]; connectionCount.set(0); addList = new SocketList(defaultPollerSize); closeList = new SocketList(defaultPollerSize); }
Example #21
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Add the sendfile data to the sendfile poller. Note that in most cases, * the initial non blocking calls to sendfile will return right away, and * will be handled asynchronously inside the kernel. As a result, * the poller will never be used. * * @param data containing the reference to the data which should be snet * @return true if all the data has been sent right away, and false * otherwise */ public SendfileState add(SendfileData data) { // Initialize fd from data given try { data.fdpool = Socket.pool(data.socket); data.fd = File.open (data.fileName, File.APR_FOPEN_READ | File.APR_FOPEN_SENDFILE_ENABLED | File.APR_FOPEN_BINARY, 0, data.fdpool); // Set the socket to nonblocking mode Socket.timeoutSet(data.socket, 0); while (sendfileRunning) { long nw = Socket.sendfilen(data.socket, data.fd, data.pos, data.length, 0); if (nw < 0) { if (!(-nw == Status.EAGAIN)) { Pool.destroy(data.fdpool); data.socket = 0; return SendfileState.ERROR; } else { // Break the loop and add the socket to poller. break; } } else { data.pos += nw; data.length -= nw; if (data.length == 0) { // Entire file has been sent Pool.destroy(data.fdpool); // Set back socket to blocking mode Socket.timeoutSet(data.socket, getConnectionTimeout() * 1000); return SendfileState.DONE; } } } } catch (Exception e) { log.warn(sm.getString("endpoint.sendfile.error"), e); return SendfileState.ERROR; } // Add socket to the list. Newly added sockets will wait // at most for pollTime before being polled synchronized (this) { addS.add(data); this.notify(); } return SendfileState.PENDING; }
Example #22
Source File: AprEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Add the sendfile data to the sendfile poller. Note that in most cases, * the initial non blocking calls to sendfile will return right away, and * will be handled asynchronously inside the kernel. As a result, * the poller will never be used. * * @param data containing the reference to the data which should be snet * @return true if all the data has been sent right away, and false * otherwise */ public boolean add(SendfileData data) { // Initialize fd from data given try { data.fdpool = Socket.pool(data.socket); data.fd = File.open (data.fileName, File.APR_FOPEN_READ | File.APR_FOPEN_SENDFILE_ENABLED | File.APR_FOPEN_BINARY, 0, data.fdpool); data.pos = data.start; // Set the socket to nonblocking mode Socket.timeoutSet(data.socket, 0); while (true) { long nw = Socket.sendfilen(data.socket, data.fd, data.pos, data.end - data.pos, 0); if (nw < 0) { if (!(-nw == Status.EAGAIN)) { Pool.destroy(data.fdpool); data.socket = 0; return false; } else { // Break the loop and add the socket to poller. break; } } else { data.pos = data.pos + nw; if (data.pos >= data.end) { // Entire file has been sent Pool.destroy(data.fdpool); // Set back socket to blocking mode Socket.timeoutSet( data.socket, getSoTimeout() * 1000); return true; } } } } catch (Exception e) { log.warn(sm.getString("endpoint.sendfile.error"), e); return false; } // Add socket to the list. Newly added sockets will wait // at most for pollTime before being polled synchronized (this) { addS.add(data); this.notify(); } return false; }
Example #23
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Destroy the poller. */ protected synchronized void destroy() { // Wait for pollerTime before doing anything, so that the poller // threads exit, otherwise parallel destruction of sockets which are // still in the poller can cause problems try { this.notify(); this.wait(pollerCount * pollTime / 1000); } catch (InterruptedException e) { // Ignore } // Close all sockets in the close queue SocketInfo info = closeList.get(); while (info != null) { // Make sure we aren't trying add the socket as well as close it addList.remove(info.socket); // Make sure the socket isn't in the poller before we close it removeFromPoller(info.socket); // Poller isn't running at this point so use destroySocket() // directly destroySocket(info.socket); info = closeList.get(); } closeList.clear(); // Close all sockets in the add queue info = addList.get(); while (info != null) { // Make sure the socket isn't in the poller before we close it removeFromPoller(info.socket); // Poller isn't running at this point so use destroySocket() // directly destroySocket(info.socket); info = addList.get(); } addList.clear(); // Close all sockets still in the poller for (int i = 0; i < pollerCount; i++) { int rv = Poll.pollset(pollers[i], desc); if (rv > 0) { for (int n = 0; n < rv; n++) { destroySocket(desc[n*2+1]); } } } Pool.destroy(pool); connectionCount.set(0); }
Example #24
Source File: OpenSslContext.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
protected final void destroyPools() { // Guard against multiple destroyPools() calls triggered by construction exception and finalize() later if (aprPool != 0 && DESTROY_UPDATER.compareAndSet(this, 0, 1)) { Pool.destroy(aprPool); } }
Example #25
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Create the poller. With some versions of APR, the maximum poller size * will be 62 (recompiling APR is necessary to remove this limitation). */ protected synchronized void init() { pool = Pool.create(serverSockPool); // Single poller by default int defaultPollerSize = getMaxConnections(); if ((OS.IS_WIN32 || OS.IS_WIN64) && (defaultPollerSize > 1024)) { // The maximum per poller to get reasonable performance is 1024 // Adjust poller size so that it won't reach the limit. This is // a limitation of XP / Server 2003 that has been fixed in // Vista / Server 2008 onwards. actualPollerSize = 1024; } else { actualPollerSize = defaultPollerSize; } timeouts = new SocketTimeouts(defaultPollerSize); // At the moment, setting the timeout is useless, but it could get // used again as the normal poller could be faster using maintain. // It might not be worth bothering though. long pollset = allocatePoller(actualPollerSize, pool, -1); if (pollset == 0 && actualPollerSize > 1024) { actualPollerSize = 1024; pollset = allocatePoller(actualPollerSize, pool, -1); } if (pollset == 0) { actualPollerSize = 62; pollset = allocatePoller(actualPollerSize, pool, -1); } pollerCount = defaultPollerSize / actualPollerSize; pollerTime = pollTime / pollerCount; nextPollerTime = pollerTime; pollers = new long[pollerCount]; pollers[0] = pollset; for (int i = 1; i < pollerCount; i++) { pollers[i] = allocatePoller(actualPollerSize, pool, -1); } pollerSpace = new int[pollerCount]; for (int i = 0; i < pollerCount; i++) { pollerSpace[i] = actualPollerSize; } /* * x2 - One descriptor for the socket, one for the event(s). * x2 - Some APR implementations return multiple events for the * same socket as different entries. Each socket is registered * for a maximum of two events (read and write) at any one * time. * * Therefore size is actual poller size *4. */ desc = new long[actualPollerSize * 4]; connectionCount.set(0); addList = new SocketList(defaultPollerSize); closeList = new SocketList(defaultPollerSize); }