You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Francesco <vi...@gmail.com> on 2012/06/22 10:12:02 UTC

AprLifecycleListener initialization issue

Hi , i'm new in this mailing list, i've started recently to integrate 
tomcat in some of my applications ( i found a lot easyer to manage 
tomcat inside a big servlet than viceversa), as early adopted java 
developer i hope to help a bit in tomcat development when i become a bit 
more expert, at this moment my tomcat integration it's stuck with the 
AprLifecycleListener class,
i've compiled, installed apr ,jni, ssl and so fort documentation is a 
bit tricky on that... expecially for path+external variables handlings 
and compiling configurations,
i really hope to have time to build a guidelines for everything about 
that...
...anyway i'll go to explain my issue :


public class AprLifecycleListener

it's a class which load jni component and check for apr existance and 
versionm,

at first request it call  :

   private static void init()


then set a boolean private and unaccessible variable which avoid 
successive calls

    if (aprInitialized) {
             return;
         }


my problem is that this class seems to not recognize apr in my 
computer.. i don't know exactly when this is called, anyway if i 
overload this class and force to call the init() again within my 
overloaded class it works...



i don't have a ready to test class , it will take some time to produce, 
but if really needed i'll do..



anyway this is a test case i've done..

-------- this  (with my overloaded apr-Loader class ):

     public static void main(String[] args) throws InterruptedException {
         VarsTrackingHttpServer varsTrackingHttpServer = new 
VarsTrackingHttpServer();
         //System.out.println("ORIGINAL APR AVAILABLE? " + 
AprLifecycleListener.isAprAvailable());
         System.out.println("OVERLOADED APR CLASS AVAILABLE?" + 
testAprLifecycleListener.isAprAvailable());

         varsTrackingHttpServer.start();
         Thread.sleep(1500000);
         varsTrackingHttpServer.stop();
         varsTrackingHttpServer.waitStopped(100);

     }
----------------- produce this :
init()__ STARTED
init()__ 1
---error, aprInitialized=true
Loaded APR based Apache Tomcat Native library 1.1.24.
APR capabilities: IPv6 [true], sendfile [true], accept filters [false], 
random [true].
initializeWebServer()__start
OVERLOADED APR CLASS AVAILABLE?true
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::true
FastTomcat::STARTING()::Apache Tomcat/7.0.27
Jun 22, 2012 8:11:16 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8087"]


---------- but this (without the overloaded class called)
     public static void main(String[] args) throws InterruptedException {


         VarsTrackingHttpServer varsTrackingHttpServer = new 
VarsTrackingHttpServer();
         System.out.println("ORIGINAL APR AVAILABLE? " + 
AprLifecycleListener.isAprAvailable());
         //System.out.println("OVERLOADED APR CLASS AVAILABLE?" + 
testAprLifecycleListener.isAprAvailable());

         varsTrackingHttpServer.start();
         Thread.sleep(1500000);
         varsTrackingHttpServer.stop();
         varsTrackingHttpServer.waitStopped(100);

     }

------ produce this :

initializeWebServer()__start
ORIGINAL APR AVAILABLE? false
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::false
FastTomcat::STARTING()::Apache Tomcat/7.0.27
Jun 22, 2012 8:10:32 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8087"]



--------------------- and if i call the standard class (it will fail to 
load apr even if i call twice, because the boolean "initialized" avoid 
successive calls)  than i call my overloaded class ( it will load apr 
correctly) , than also the original class recognize apr as loaded! 
(HERE DOWN THE EXAMPLE..) so what's the trick? seems that the 
AprLifecycleListener class is being called in a moment when apr is not 
available and then there is no possibility to re-call it??


---------------- finally this :
     public static void main(String[] args) throws InterruptedException {

         VarsTrackingHttpServer varsTrackingHttpServer = new 
VarsTrackingHttpServer();
         System.out.println("ORIGINAL APR AVAILABLE? " + 
AprLifecycleListener.isAprAvailable());
         System.out.println("OVERLOADED APR CLASS AVAILABLE?" + 
testAprLifecycleListener.isAprAvailable());
         System.out.println("ORIGINAL APR AVAILABLE? " + 
AprLifecycleListener.isAprAvailable());

         varsTrackingHttpServer.start();
         Thread.sleep(1500000);
         varsTrackingHttpServer.stop();
         varsTrackingHttpServer.waitStopped(100);

     }

---------------- PRODUCE :
---error, aprInitialized=true
ORIGINAL APR AVAILABLE? false
init()__ STARTED
init()__ 1
Loaded APR based Apache Tomcat Native library 1.1.24.
APR capabilities: IPv6 [true], sendfile [true], accept filters [false], 
random [true].
initializeWebServer()__start
OVERLOADED APR CLASS AVAILABLE?true
ORIGINAL APR AVAILABLE? true
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::true
FastTomcat::STARTING()::Apache Tomcat/7.0.27
Jun 22, 2012 8:08:51 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8087"]



this is my very dumb class which overload apr..



import org.apache.catalina.core.AprLifecycleListener;
import org.apache.tomcat.jni.Library;
import org.apache.tomcat.util.ExceptionUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.jni.Library;
import org.apache.tomcat.jni.SSL;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
import org.eclipse.jdt.internal.compiler.ast.SuperReference;

import java.lang.reflect.Method;
import java.util.logging.Logger;

public class testAprLifecycleListener extends AprLifecycleListener {


     private static final Logger log = Logger.getLogger("none");


     public static boolean isAprAvailable() {
//        terminateAPR();
       /*  return AprLifecycleListener.isAprAvailable();*/

         synchronized (lock) {
             init();
         }
         return aprAvailable;
     }

     private static void init()
     {
         int major = 0;
         int minor = 0;
         int patch = 0;
         int apver = 0;
         int rqver = TCN_REQUIRED_MAJOR * 1000 + TCN_REQUIRED_MINOR * 
100 + TCN_REQUIRED_PATCH;
         int rcver = TCN_REQUIRED_MAJOR * 1000 + TCN_REQUIRED_MINOR * 
100 + TCN_RECOMMENDED_PV;

         System.out.println("init()__ STARTED ");
      /*  if (aprInitialized) {
             return;
         }*/
         aprInitialized = true;
         System.err.println("---error, aprInitialized="+aprInitialized);
         System.out.println("init()__ 1 ");
         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);
             apver = major * 1000 + minor * 100 + patch;
         } catch (Throwable t) {
             t = ExceptionUtils.unwrapInvocationTargetException(t);
             ExceptionUtils.handleThrowable(t);
             System.err.println(sm.getString("aprListener.aprInit",
                     System.getProperty("java.library.path")));
             return;
         }
         if (apver < rqver) {
            System.err.println(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) {
                 t = ExceptionUtils.unwrapInvocationTargetException(t);
                 ExceptionUtils.handleThrowable(t);
                 System.err.println("---error, PROBLEM TERMINATING APR!");
             }
             return;
         }
         if (apver < rcver) {
             System.err.println(sm.getString("aprListener.tcnVersion", 
major + "."
                     + minor + "." + patch,
                     TCN_REQUIRED_MAJOR + "." +
                             TCN_RECOMMENDED_MINOR + "." +
                             TCN_RECOMMENDED_PV));
         }

         System.err.println(sm.getString("aprListener.tcnValid", major + "."
                 + minor + "." + patch));

         // Log APR flags
         System.err.println(sm.getString("aprListener.flags",
                 Boolean.valueOf(Library.APR_HAVE_IPV6),
                 Boolean.valueOf(Library.APR_HAS_SENDFILE),
                 Boolean.valueOf(Library.APR_HAS_SO_ACCEPTFILTER),
                 Boolean.valueOf(Library.APR_HAS_RANDOM)));
         aprAvailable = true;
     }


     private static void terminateAPR()
             throws ClassNotFoundException, NoSuchMethodException,
             IllegalAccessException, InvocationTargetException
     {
         String methodName = "terminate";
         Method method = Class.forName("org.apache.tomcat.jni.Library")
                 .getMethod(methodName, (Class [])null);
         method.invoke(null, (Object []) null);
         aprAvailable = false;
         aprInitialized = false;
         sslInitialized = false; // Well we cleaned the pool in terminate.
         sslAvailable = false; // Well we cleaned the pool in terminate.
         fipsModeActive = false;
     }

}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AprLifecycleListener initialization issue

Posted by Francesco <vi...@gmail.com>.
On 06/23/2012 09:05 AM, Konstantin Kolinko wrote:
> 2012/6/22 Francesco<vi...@gmail.com>:
>> Hi , i'm new in this mailing list, i've started recently to integrate tomcat
>> in some of my applications ( i found a lot easyer to manage tomcat inside a
>> big servlet than viceversa), as early adopted java developer i hope to help
>> a bit in tomcat development when i become a bit more expert, at this moment
>> my tomcat integration it's stuck with the AprLifecycleListener class,
>> i've compiled, installed apr ,jni, ssl and so fort documentation is a bit
>> tricky on that... expecially for path+external variables handlings and
>> compiling configurations,
>> i really hope to have time to build a guidelines for everything about
>> that...
>> ...anyway i'll go to explain my issue :
>>
>>
>> public class AprLifecycleListener
>>
>> it's a class which load jni component and check for apr existance and
>> versionm,
>>
>> at first request it call  :
>>
>>   private static void init()
>>
>>
>> then set a boolean private and unaccessible variable which avoid successive
>> calls
>>
>>    if (aprInitialized) {
>>             return;
>>         }
>>
>>
>> my problem is that this class seems to not recognize apr in my computer.. i
>> don't know exactly when this is called, anyway if i overload this class and
>> force to call the init() again within my overloaded class it works...
>>
>>
>>
>> i don't have a ready to test class , it will take some time to produce, but
>> if really needed i'll do..
>>
>
>
> 1. AprLifecycleListener is a LifecycleListener.
> That is, you must add it to a server and it will react on lifecycle
> events coming from it.
>
> 2. Tomcat-Native  is a native library.  There are JRE limitations
> associated with that:
>
> One of them is that such library must be loaded exactly once. You
> cannot load it twice. You cannot load it from two different class
> loaders.
>
> This issue usually comes up with JDBC drivers that have native components.
>
> In the FAQ:
> http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat
>
>
> 3. If you want to debug Tomcat, some tips are in the FAQ.
>
> http://wiki.apache.org/tomcat/FAQ/Developing#Debugging
>
> 4.
>> my problem is that this class seems to not recognize apr in my computer.
>
> The actual error messages =?
>
>
> 5. Do you need Tomcat-Native library at all? Tomcat runs fine without it.
>
>
>
> Best regards,
> Konstantin Kolinko







i understand what you mean, i'll try to explain better my concerns..
1.(reply to 1 and 2) obviously AprLifecycleListener is mean to be loaded 
once (else the boolean value to avoid to load it twice is silly..) the 
question about that is.. why if:
A) i ask to standard loaded it doesn't work
B) i load it in a overloaded class it works (even if i load once only,
C) if i load it with standard loader, doesn't work, than i load it in my 
overloading class it works, and then ovbiously works again in the 
standard AprLifecycleListener class..

so what i am missing in that? or what is missing the 
AprLifecycleListener class that my overloading class is not? (these are 
almost identical!)

2. (reply to 2 , 3 and 4 )
i've already looked at that, i'll probably should compile the tomcat 
source and try to play in it to better debug (because class of tomcat 
distributable have lot of private members that cannot be touched to 
search the exactly point of problem source, i know only that the 
overloaded class works, even if it's semi-identical to the original 
which doesn't load apr.. maybe someone who already have had to do with 
that can help me...
anyway no error appears, this is the output of my testcase (with all 
loggers writing to stderr/stdout , it only start in bio instead of apr..

ORIGINAL APR AVAILABLE? false
initializeWebServer()__start
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::false
FastTomcat::STARTING()::Apache Tomcat/7.0.28
Jun 25, 2012 7:56:36 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8087"]
Jun 25, 2012 7:56:36 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 25, 2012 7:56:36 AM 
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener createMBeans
SEVERE: No global naming context defined for server
Jun 25, 2012 7:56:36 AM org.apache.catalina.core.StandardService 
startInternal
INFO: Starting service Tomcat
Jun 25, 2012 7:56:36 AM org.apache.catalina.core.StandardEngine 
startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.28
Jun 25, 2012 7:56:37 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8087"]
Jun 25, 2012 7:56:37 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]


3. (reply to 5)
yes i have done some tests, i have very busy servers which serve A LOT 
of small static content and a good amount of dynamic which i've 
programmed now in java.. , i was using lighttpd previously but i found 
tomcat with apr very fast not as lighttpd but lighttpd created lot of 
problem in serving dynamic content


thank you for your reply :)
Francesco







---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AprLifecycleListener initialization issue

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/6/22 Francesco <vi...@gmail.com>:
> Hi , i'm new in this mailing list, i've started recently to integrate tomcat
> in some of my applications ( i found a lot easyer to manage tomcat inside a
> big servlet than viceversa), as early adopted java developer i hope to help
> a bit in tomcat development when i become a bit more expert, at this moment
> my tomcat integration it's stuck with the AprLifecycleListener class,
> i've compiled, installed apr ,jni, ssl and so fort documentation is a bit
> tricky on that... expecially for path+external variables handlings and
> compiling configurations,
> i really hope to have time to build a guidelines for everything about
> that...
> ...anyway i'll go to explain my issue :
>
>
> public class AprLifecycleListener
>
> it's a class which load jni component and check for apr existance and
> versionm,
>
> at first request it call  :
>
>  private static void init()
>
>
> then set a boolean private and unaccessible variable which avoid successive
> calls
>
>   if (aprInitialized) {
>            return;
>        }
>
>
> my problem is that this class seems to not recognize apr in my computer.. i
> don't know exactly when this is called, anyway if i overload this class and
> force to call the init() again within my overloaded class it works...
>
>
>
> i don't have a ready to test class , it will take some time to produce, but
> if really needed i'll do..
>


1. AprLifecycleListener is a LifecycleListener.
That is, you must add it to a server and it will react on lifecycle
events coming from it.

2. Tomcat-Native  is a native library.  There are JRE limitations
associated with that:

One of them is that such library must be loaded exactly once. You
cannot load it twice. You cannot load it from two different class
loaders.

This issue usually comes up with JDBC drivers that have native components.

In the FAQ:
http://wiki.apache.org/tomcat/HowTo#I.27m_encountering_classloader_problems_when_using_JNI_under_Tomcat


3. If you want to debug Tomcat, some tips are in the FAQ.

http://wiki.apache.org/tomcat/FAQ/Developing#Debugging

4.
> my problem is that this class seems to not recognize apr in my computer.

The actual error messages =?


5. Do you need Tomcat-Native library at all? Tomcat runs fine without it.



Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AprLifecycleListener initialization issue

Posted by Francesco <vi...@gmail.com>.
On 06/24/2012 06:32 PM, Pid wrote:
> On 22/06/2012 09:12, Francesco wrote:
>> ( i found a lot easyer to manage tomcat inside a big servlet than viceversa)
>
> So what's the Servlet running in?
>
>
> p
>
>

it's a servlet of my own, which also handle some separated process, that 
is rarely restarted and when it is i prefer to restart tomcat with it, 
and also i need that the servlet isn't reloaded which is 
not-so-well-tested case, but i've read somewhere that tomcat doesn't 
guaranteee that a server isn't reloaded, only way i've found is to 
detach everything from the servlet using enums class, and separated 
threads..


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: AprLifecycleListener initialization issue

Posted by Pid <pi...@pidster.com>.
On 22/06/2012 09:12, Francesco wrote:
> ( i found a lot easyer to manage tomcat inside a big servlet than viceversa)

So what's the Servlet running in?


p


-- 

[key:62590808]