FileDocCategorySizeDatePackage
AprLifecycleListener.javaAPI DocApache Tomcat 6.0.148232Fri Jul 20 04:20:30 BST 2007org.apache.catalina.core

AprLifecycleListener

public class AprLifecycleListener extends Object implements org.apache.catalina.LifecycleListener
Implementation of LifecycleListener that will init and and destroy APR.
author
Remy Maucherat
author
Filip Hanik
version
$Revision: 534930 $ $Date: 2007-05-03 18:43:35 +0200 (jeu., 03 mai 2007) $
since
4.1

Fields Summary
private static org.apache.juli.logging.Log
log
protected org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected static final int
TCN_REQUIRED_MAJOR
protected static final int
TCN_REQUIRED_MINOR
protected static final int
TCN_REQUIRED_PATCH
protected static final int
TCN_RECOMMENDED_PV
protected static String
SSLEngine
protected static boolean
sslInitialized
protected static boolean
aprInitialized
Constructors Summary
Methods Summary
public java.lang.StringgetSSLEngine()

        return SSLEngine;
    
private booleaninit()

        int major = 0;
        int minor = 0;
        int patch = 0;
        if (aprInitialized) {
            return true;    
        }
        try {
            String methodName = "initialize";
            Class paramTypes[] = new Class[1];
            paramTypes[0] = String.class;
            Object paramValues[] = new Object[1];
            paramValues[0] = null;
            Class clazz = Class.forName("org.apache.tomcat.jni.Library");
            Method method = clazz.getMethod(methodName, paramTypes);
            method.invoke(null, paramValues);
            major = clazz.getField("TCN_MAJOR_VERSION").getInt(null);
            minor = clazz.getField("TCN_MINOR_VERSION").getInt(null);
            patch = clazz.getField("TCN_PATCH_VERSION").getInt(null);
        } catch (Throwable t) {
            if (!log.isDebugEnabled()) {
                log.info(sm.getString("aprListener.aprInit",
                        System.getProperty("java.library.path")));
            } else {
                log.debug(sm.getString("aprListener.aprInit",
                        System.getProperty("java.library.path")), t);
            }
            return false;
        }
        if ((major != TCN_REQUIRED_MAJOR)  ||
            (minor != TCN_REQUIRED_MINOR) ||
            (patch <  TCN_REQUIRED_PATCH)) {
            log.error(sm.getString("aprListener.tcnInvalid", major + "."
                    + minor + "." + patch,
                    TCN_REQUIRED_MAJOR + "." +
                    TCN_REQUIRED_MINOR + "." +
                    TCN_REQUIRED_PATCH));
            try {
                // Terminate the APR in case the version
                // is below required.                
                terminateAPR();
            } catch (Throwable t) {
                // Ignore
            }
            return false;
        }
        if (patch <  TCN_RECOMMENDED_PV) {
            if (!log.isDebugEnabled()) {
                log.info(sm.getString("aprListener.tcnVersion", major + "."
                        + minor + "." + patch,
                        TCN_REQUIRED_MAJOR + "." +
                        TCN_REQUIRED_MINOR + "." +
                        TCN_RECOMMENDED_PV));
            } else {
                log.debug(sm.getString("aprListener.tcnVersion", major + "."
                        + minor + "." + patch,
                        TCN_REQUIRED_MAJOR + "." +
                        TCN_REQUIRED_MINOR + "." +
                        TCN_RECOMMENDED_PV));
            }
        }
        if (!log.isDebugEnabled()) {
           log.info(sm.getString("aprListener.tcnValid", major + "."
                    + minor + "." + patch));
        }
        else {
           log.debug(sm.getString("aprListener.tcnValid", major + "."
                     + minor + "." + patch));
        }
        // Log APR flags
        log.info(sm.getString("aprListener.flags", Library.APR_HAVE_IPV6, Library.APR_HAS_SENDFILE, 
                Library.APR_HAS_SO_ACCEPTFILTER, Library.APR_HAS_RANDOM));
        return true;
    
private static synchronized voidinitializeSSL()


        if ("off".equalsIgnoreCase(SSLEngine)) {
            return;
        }
        if (sslInitialized) {
             //only once per VM
            return;
        }
        String methodName = "initialize";
        Class paramTypes[] = new Class[1];
        paramTypes[0] = String.class;
        Object paramValues[] = new Object[1];
        paramValues[0] = "on".equalsIgnoreCase(SSLEngine)?null:SSLEngine;
        Class clazz = Class.forName("org.apache.tomcat.jni.SSL");
        Method method = clazz.getMethod(methodName, paramTypes);
        method.invoke(null, paramValues);
        sslInitialized = true;
    
public voidlifecycleEvent(org.apache.catalina.LifecycleEvent event)
Primary entry point for startup and shutdown events.

param
event The event that has occurred


    // ---------------------------------------------- LifecycleListener Methods

                        
        

        if (Lifecycle.INIT_EVENT.equals(event.getType())) {
            aprInitialized = init();
            if (aprInitialized) {
                try {
                    initializeSSL();
                } catch (Throwable t) {
                    if (!log.isDebugEnabled()) {
                        log.info(sm.getString("aprListener.sslInit"));
                    } else {
                        log.debug(sm.getString("aprListener.sslInit"));
                    }
                }
            }
        } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
            if (!aprInitialized) {
                return;
            }
            try {
                terminateAPR();
            } catch (Throwable t) {
                if (!log.isDebugEnabled()) {
                    log.info(sm.getString("aprListener.aprDestroy"));
                } else {
                    log.debug(sm.getString("aprListener.aprDestroy"), t);
                }
            }
        }

    
public voidsetSSLEngine(java.lang.String SSLEngine)

        this.SSLEngine = SSLEngine;
    
private static synchronized voidterminateAPR()

        String methodName = "terminate";
        Method method = Class.forName("org.apache.tomcat.jni.Library")
            .getMethod(methodName, (Class [])null);
        method.invoke(null, (Object []) null);