You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2005/07/26 19:17:44 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves SemaphoreValve.java LocalStrings.properties
remm 2005/07/26 10:17:44
Modified: catalina/src/share/org/apache/catalina/valves
SemaphoreValve.java LocalStrings.properties
Log:
- Oops, fix impl using Lifecycle.
Revision Changes Path
1.2 +109 -13 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/SemaphoreValve.java
Index: SemaphoreValve.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/SemaphoreValve.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SemaphoreValve.java 26 Jul 2005 12:45:22 -0000 1.1
+++ SemaphoreValve.java 26 Jul 2005 17:17:43 -0000 1.2
@@ -23,8 +23,13 @@
import javax.servlet.ServletException;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleListener;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
+import org.apache.catalina.util.LifecycleSupport;
+import org.apache.catalina.util.StringManager;
/**
@@ -38,18 +43,8 @@
*/
public class SemaphoreValve
- extends ValveBase {
-
-
- // ------------------------------------------------------------ Constructor
-
-
- /**
- * Create a new StandardHost component with the default basic Valve.
- */
- public SemaphoreValve() {
- semaphore = new Semaphore(concurrency, fairness);
- }
+ extends ValveBase
+ implements Lifecycle {
// ----------------------------------------------------- Instance Variables
@@ -63,11 +58,30 @@
/**
+ * The string manager for this package.
+ */
+ private StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
+ /**
* Semaphore.
*/
protected Semaphore semaphore = null;
+ /**
+ * The lifecycle event support for this component.
+ */
+ protected LifecycleSupport lifecycle = new LifecycleSupport(this);
+
+
+ /**
+ * Has this component been started yet?
+ */
+ private boolean started = false;
+
+
// ------------------------------------------------------------- Properties
@@ -87,6 +101,88 @@
public void setFairness(boolean fairness) { this.fairness = fairness; }
+ // ------------------------------------------------------ Lifecycle Methods
+
+
+ /**
+ * Add a lifecycle event listener to this component.
+ *
+ * @param listener The listener to add
+ */
+ public void addLifecycleListener(LifecycleListener listener) {
+
+ lifecycle.addLifecycleListener(listener);
+
+ }
+
+
+ /**
+ * Get the lifecycle listeners associated with this lifecycle. If this
+ * Lifecycle has no listeners registered, a zero-length array is returned.
+ */
+ public LifecycleListener[] findLifecycleListeners() {
+
+ return lifecycle.findLifecycleListeners();
+
+ }
+
+
+ /**
+ * Remove a lifecycle event listener from this component.
+ *
+ * @param listener The listener to add
+ */
+ public void removeLifecycleListener(LifecycleListener listener) {
+
+ lifecycle.removeLifecycleListener(listener);
+
+ }
+
+
+ /**
+ * Prepare for the beginning of active use of the public methods of this
+ * component. This method should be called after <code>configure()</code>,
+ * and before any of the public methods of the component are utilized.
+ *
+ * @exception LifecycleException if this component detects a fatal error
+ * that prevents this component from being used
+ */
+ public void start() throws LifecycleException {
+
+ // Validate and update our current component state
+ if (started)
+ throw new LifecycleException
+ (sm.getString("semaphoreValve.alreadyStarted"));
+ lifecycle.fireLifecycleEvent(START_EVENT, null);
+ started = true;
+
+ semaphore = new Semaphore(concurrency, fairness);
+
+ }
+
+
+ /**
+ * Gracefully terminate the active use of the public methods of this
+ * component. This method should be the last one called on a given
+ * instance of this component.
+ *
+ * @exception LifecycleException if this component detects a fatal error
+ * that needs to be reported
+ */
+ public void stop() throws LifecycleException {
+
+ // Validate and update our current component state
+ if (!started)
+ throw new LifecycleException
+ (sm.getString("semaphoreValve.notStarted"));
+ lifecycle.fireLifecycleEvent(STOP_EVENT, null);
+ started = false;
+
+ semaphore = null;
+
+ }
+
+
// --------------------------------------------------------- Public Methods
1.9 +2 -0 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/LocalStrings.properties,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- LocalStrings.properties 15 Jan 2005 16:51:35 -0000 1.8
+++ LocalStrings.properties 26 Jul 2005 17:17:43 -0000 1.9
@@ -1,5 +1,7 @@
accessLogValve.alreadyStarted=Access Logger has already been started
accessLogValve.notStarted=Access Logger has not yet been started
+semaphoreValve.alreadyStarted=Semaphore valve has already been started
+semaphoreValve.notStarted=Semaphore valve has not yet been started
certificatesValve.alreadyStarted=Certificates Valve has already been started
certificatesValve.notStarted=Certificates Valve has not yet been started
interceptorValve.alreadyStarted=Interceptor Valve has already been started
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org