Java Code Examples for org.apache.tomcat.jni.Pool#destroy()

The following examples show how to use org.apache.tomcat.jni.Pool#destroy() . 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: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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 2
Source File: AprSocketWrapperImpl.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
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 3
Source File: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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 4
Source File: OpenSSLContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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 5
Source File: TestXxxEndpoint.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
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 6
Source File: AprEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: AprEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 8
Source File: TestXxxEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
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 9
Source File: AprEndpoint.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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: AprEndpoint.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: TestXxxEndpoint.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
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 12
Source File: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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 13
Source File: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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 14
Source File: AprEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * 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 15
Source File: AprEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: OpenSslContext.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
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);
    }
}