Modified: tomcat/trunk/java/org/apache/catalina/valves/SemaphoreValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/SemaphoreValve.java?rev=1187018&r1=1187017&r2=1187018&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/SemaphoreValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/SemaphoreValve.java Thu Oct 20 19:52:47 2011 @@ -5,9 +5,9 @@ * 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. @@ -60,18 +60,18 @@ public class SemaphoreValve extends Valv * Semaphore. */ protected Semaphore semaphore = null; - + // ------------------------------------------------------------- Properties - + /** * Concurrency level of the semaphore. */ protected int concurrency = 10; public int getConcurrency() { return concurrency; } public void setConcurrency(int concurrency) { this.concurrency = concurrency; } - + /** * Fairness of the semaphore. @@ -79,7 +79,7 @@ public class SemaphoreValve extends Valv protected boolean fairness = false; public boolean getFairness() { return fairness; } public void setFairness(boolean fairness) { this.fairness = fairness; } - + /** * Block until a permit is available. @@ -87,7 +87,7 @@ public class SemaphoreValve extends Valv protected boolean block = true; public boolean getBlock() { return block; } public void setBlock(boolean block) { this.block = block; } - + /** * Block interruptibly until a permit is available. @@ -95,7 +95,7 @@ public class SemaphoreValve extends Valv protected boolean interruptible = false; public boolean getInterruptible() { return interruptible; } public void setInterruptible(boolean interruptible) { this.interruptible = interruptible; } - + /** * Start this component and implement the requirements @@ -106,7 +106,7 @@ public class SemaphoreValve extends Valv */ @Override protected synchronized void startInternal() throws LifecycleException { - + semaphore = new Semaphore(concurrency, fairness); setState(LifecycleState.STARTING); @@ -128,7 +128,7 @@ public class SemaphoreValve extends Valv semaphore = null; } - + // --------------------------------------------------------- Public Methods @@ -165,7 +165,7 @@ public class SemaphoreValve extends Valv shouldRelease = false; permitDenied(request, response); return; - } + } } else { semaphore.acquireUninterruptibly(); } @@ -188,22 +188,22 @@ public class SemaphoreValve extends Valv } - + /** * Subclass friendly method to add conditions. - * @param request - * @param response + * @param request + * @param response */ public boolean controlConcurrency(Request request, Response response) { return true; } - + /** * Subclass friendly method to add error handling when a permit isn't * granted. - * @param request - * @param response + * @param request + * @param response * @throws IOException * @throws ServletException */ @@ -211,6 +211,6 @@ public class SemaphoreValve extends Valv throws IOException, ServletException { // NO-OP by default } - + }
Modified: tomcat/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java?rev=1187018&r1=1187017&r2=1187018&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java Thu Oct 20 19:52:47 2011 @@ -38,7 +38,7 @@ import org.apache.tomcat.util.res.String * This valve allows to detect requests that take a long time to process, which might * indicate that the thread that is processing it is stuck. * Based on code proposed by TomLu in Bugzilla entry #50306 - * + * * @author slaurent * */ @@ -53,7 +53,7 @@ public class StuckThreadDetectionValve e * Logger */ private static final Log log = LogFactory.getLog(StuckThreadDetectionValve.class); - + /** * The string manager for this package. */ @@ -64,30 +64,30 @@ public class StuckThreadDetectionValve e * Keeps count of the number of stuck threads detected */ private final AtomicInteger stuckCount = new AtomicInteger(0); - + /** * In seconds. Default 600 (10 minutes). */ private int threshold = 600; - + /** * The only references we keep to actual running Thread objects are in * this Map (which is automatically cleaned in invoke()s finally clause). * That way, Threads can be GC'ed, eventhough the Valve still thinks they * are stuck (caused by a long monitor interval) */ - private ConcurrentHashMap<Long, MonitoredThread> activeThreads = + private final ConcurrentHashMap<Long, MonitoredThread> activeThreads = new ConcurrentHashMap<Long, MonitoredThread>(); /** * */ - private Queue<CompletedStuckThread> completedStuckThreadsQueue = + private final Queue<CompletedStuckThread> completedStuckThreadsQueue = new ConcurrentLinkedQueue<CompletedStuckThread>(); /** * Specify the threshold (in seconds) used when checking for stuck threads. * If <=0, the detection is disabled. The default is 600 seconds. - * + * * @param threshold * The new threshold in seconds */ @@ -103,7 +103,7 @@ public class StuckThreadDetectionValve e return threshold; } - + /** * Required to enable async support. */ @@ -166,7 +166,7 @@ public class StuckThreadDetectionValve e @Override public void invoke(Request request, Response response) throws IOException, ServletException { - + if (threshold <= 0) { // short-circuit if not monitoring stuck threads getNext().invoke(request, response); @@ -183,7 +183,7 @@ public class StuckThreadDetectionValve e requestUrl.append("?"); requestUrl.append(request.getQueryString()); } - MonitoredThread monitoredThread = new MonitoredThread(Thread.currentThread(), + MonitoredThread monitoredThread = new MonitoredThread(Thread.currentThread(), requestUrl.toString()); activeThreads.put(key, monitoredThread); @@ -216,7 +216,7 @@ public class StuckThreadDetectionValve e } } // Check if any threads previously reported as stuck, have finished. - for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); + for (CompletedStuckThread completedStuckThread = completedStuckThreadsQueue.poll(); completedStuckThread != null; completedStuckThread = completedStuckThreadsQueue.poll()) { int numStuckThreads = stuckCount.decrementAndGet(); @@ -224,7 +224,7 @@ public class StuckThreadDetectionValve e completedStuckThread.getTotalActiveTime(), numStuckThreads); } } - + public long[] getStuckThreadIds() { List<Long> idList = new ArrayList<Long>(); for (MonitoredThread monitoredThread : activeThreads.values()) { @@ -282,7 +282,7 @@ public class StuckThreadDetectionValve e int val = this.state.getAndSet(MonitoredThreadState.DONE.ordinal()); return MonitoredThreadState.values()[val]; } - + boolean isMarkedAsStuck() { return this.state.get() == MonitoredThreadState.STUCK.ordinal(); } @@ -290,8 +290,8 @@ public class StuckThreadDetectionValve e private static class CompletedStuckThread { - private String threadName; - private long totalActiveTime; + private final String threadName; + private final long totalActiveTime; public CompletedStuckThread(String threadName, long totalActiveTime) { this.threadName = threadName; Modified: tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java?rev=1187018&r1=1187017&r2=1187018&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java Thu Oct 20 19:52:47 2011 @@ -5,17 +5,15 @@ * 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; @@ -53,11 +51,11 @@ public abstract class ValveBase extends implements Contained, Valve { //------------------------------------------------------ Constructor - + public ValveBase() { this(false); } - + public ValveBase(boolean asyncSupported) { this.asyncSupported = asyncSupported; } @@ -67,7 +65,7 @@ public abstract class ValveBase extends * Does this valve support Servlet 3+ async requests? */ protected boolean asyncSupported; - + /** * The Container whose pipeline this Valve is a component of. */ @@ -103,7 +101,7 @@ public abstract class ValveBase extends //-------------------------------------------------------------- Properties - + /** * Return the Container with which this Valve is associated, if any. */ @@ -208,7 +206,7 @@ public abstract class ValveBase extends /** * Process a Comet event. This method will rarely need to be provided by - * a subclass, unless it needs to reassociate a particular object with + * a subclass, unless it needs to reassociate a particular object with * the thread that is processing the request. * * @param request The servlet request to be processed @@ -230,11 +228,11 @@ public abstract class ValveBase extends @Override protected void initInternal() throws LifecycleException { super.initInternal(); - + containerLog = getContainer().getLogger(); } - - + + /** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. @@ -244,7 +242,7 @@ public abstract class ValveBase extends */ @Override protected synchronized void startInternal() throws LifecycleException { - + setState(LifecycleState.STARTING); } @@ -261,8 +259,8 @@ public abstract class ValveBase extends setState(LifecycleState.STOPPING); } - - + + /** * Return a String rendering of this object. */ @@ -284,13 +282,13 @@ public abstract class ValveBase extends @Override public String getObjectNameKeyProperties() { StringBuilder name = new StringBuilder("type=Valve"); - + Container container = getContainer(); name.append(MBeanUtils.getContainerKeyProperties(container)); - + int seq = 0; - + // Pipeline may not be present in unit testing Pipeline p = container.getPipeline(); if (p != null) { @@ -310,7 +308,7 @@ public abstract class ValveBase extends } } } - + if (seq > 0) { name.append(",seq="); name.append(seq); @@ -323,7 +321,7 @@ public abstract class ValveBase extends } name.append(",name="); name.append(className); - + return name.toString(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org