I looked at Tomcat code, and it seems that it is not possible. Bootstrap has 
private static instance:

public final class Bootstrap {

    /**
     * Daemon object used by main.
     */
    private static Bootstrap daemon = null;

And it is not possible to get this.
If it was, then still it would not possible to get the Catalina instance, which 
is also private:

    private Object catalinaDaemon = null;

But if I would get the Catalina instance somehow, then I probably could get 
Server and connectors and everything.

I wonder if it would be possible to add such static method to Bootstrap:

    public static Object getCatalina() {
        if (daemon != null) {
            return daemon.catalinaDaemon;
        }
        return null;
    }

But I have a feeling that there must be some better way of doing this.

-Harri

-----Original Message-----
From: Pesonen, Harri [mailto:harri.peso...@sap.com] 
Sent: 15. toukokuuta 2017 18:10
To: Tomcat Users List <users@tomcat.apache.org>
Subject: How to monitor Tomcat connectors?

Hello, what would be the best way to find out if any of Tomcat connectors have 
failed to initialize at startup?
They could fail for many reasons, like when the port is already in use, or 
keystore is missing etc.
Now Tomcat prints the error in log, but I would like to find out 
programmatically if any of the connectors have failed.
Or alternatively, fail the Tomcat and shutdown it if any connectors fail.

I see that Connector has getState():

https://tomcat.apache.org/tomcat-8.5-doc/api/org/apache/catalina/util/LifecycleBase.html#getState()

public LifecycleState getState()
Obtain the current state of the source component.
Specified by:
getState in interface Lifecycle
Returns:
The current state of the source component.

DESTROYED
DESTROYING
FAILED
INITIALIZED
INITIALIZING
NEW
STARTED
STARTING
STARTING_PREP
STOPPED
STOPPING
STOPPING_PREP

If the state is any of (DESTROYED, DESTROYING, FAILED) then I think that it has 
failed.
Then question is, how to get the connectors? Is there some static method to get 
Tomcat server instance and then connectors?

I am starting Tomcat using static Bootstrap method main:
https://tomcat.apache.org/tomcat-8.5-doc/api/org/apache/catalina/startup/Bootstrap.html#main(java.lang.String[])

I wonder how to get the started Tomcat instance?

-Harri

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

Reply via email to