/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.catalina.valves;
/** * <p> * Implementation of a Valve that limits concurrency. * </p> * <p> * This Valve may be attached to any Container, depending on the granularity of the concurrency control you wish to * perform. Note that internally, some async requests may require multiple serial requests to complete what - to the * user - appears as a single request. * </p> * * @author Remy Maucherat
*/ publicclass SemaphoreValve extends ValveBase {
// ------------------------------------------------------ Constructor public SemaphoreValve() { super(true);
}
/** * Start this component and implement the requirements of * {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error that prevents this component from being * used
*/
@Override protectedsynchronizedvoid startInternal() throws LifecycleException {
semaphore = new Semaphore(concurrency, fairness); super.startInternal();
}
/** * Stop this component and implement the requirements of * {@link org.apache.catalina.util.LifecycleBase#stopInternal()}. * * @exception LifecycleException if this component detects a fatal error that prevents this component from being * used
*/
@Override protectedsynchronizedvoid stopInternal() throws LifecycleException { super.stopInternal();
semaphore = null;
}
// --------------------------------------------------------- Public Methods
/** * Do concurrency control on the request using the semaphore. * * @param request The servlet request to be processed * @param response The servlet response to be created * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs
*/
@Override publicvoid invoke(Request request, Response response) throws IOException, ServletException {
/** * Subclass friendly method to add conditions. * * @param request The Servlet request * @param response The Servlet response * * @return <code>true</code> if the concurrency control should occur on this request
*/ publicboolean controlConcurrency(Request request, Response response) { returntrue;
}
/** * Subclass friendly method to add error handling when a permit isn't granted. * * @param request The Servlet request * @param response The Servlet response * * @throws IOException Error writing output * @throws ServletException Other error
*/ publicvoid permitDenied(Request request, Response response) throws IOException, ServletException { // NO-OP by default
}
}
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.