1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.catalina.startup;
20
21
22 import org.apache.catalina.Engine;
23 import org.apache.catalina.Lifecycle;
24 import org.apache.catalina.LifecycleEvent;
25 import org.apache.catalina.LifecycleListener;
26 import org.apache.juli.logging.Log;
27 import org.apache.juli.logging.LogFactory;
28 import org.apache.tomcat.util.res.StringManager;
29
30
31 /**
32  * Startup event listener for a <b>Engine</b> that configures the properties
33  * of that Engine, and the associated defined contexts.
34  *
35  * @author Craig R. McClanahan
36  */

37 public class EngineConfig
38     implements LifecycleListener {
39
40
41     private static final Log log = LogFactory.getLog(EngineConfig.class);
42
43     // ----------------------------------------------------- Instance Variables
44
45
46     /**
47      * The Engine we are associated with.
48      */

49     protected Engine engine = null;
50
51
52     /**
53      * The string resources for this package.
54      */

55     protected static final StringManager sm =
56         StringManager.getManager(Constants.Package);
57
58
59     // --------------------------------------------------------- Public Methods
60
61
62     /**
63      * Process the START event for an associated Engine.
64      *
65      * @param event The lifecycle event that has occurred
66      */

67     @Override
68     public void lifecycleEvent(LifecycleEvent event) {
69
70         // Identify the engine we are associated with
71         try {
72             engine = (Engine) event.getLifecycle();
73         } catch (ClassCastException e) {
74             log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
75             return;
76         }
77
78         // Process the event that has occurred
79         if (event.getType().equals(Lifecycle.START_EVENT))
80             start();
81         else if (event.getType().equals(Lifecycle.STOP_EVENT))
82             stop();
83
84     }
85
86
87     // -------------------------------------------------------- Protected Methods
88
89
90     /**
91      * Process a "start" event for this Engine.
92      */

93     protected void start() {
94
95         if (engine.getLogger().isDebugEnabled())
96             engine.getLogger().debug(sm.getString("engineConfig.start"));
97
98     }
99
100
101     /**
102      * Process a "stop" event for this Engine.
103      */

104     protected void stop() {
105
106         if (engine.getLogger().isDebugEnabled())
107             engine.getLogger().debug(sm.getString("engineConfig.stop"));
108
109     }
110
111
112 }
113