01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.geronimo.jetty6.connector;
21:
22: import java.util.concurrent.RejectedExecutionException;
23: import java.util.concurrent.TimeUnit;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.apache.geronimo.system.threads.ThreadPool;
28:
29: /**
30: * @version $Rev: 582977 $ $Date: 2007-10-08 14:14:38 -0700 (Mon, 08 Oct 2007) $
31: */
32: public class JettyThreadPool implements org.mortbay.thread.ThreadPool {
33:
34: private static final Log log = LogFactory
35: .getLog(JettyThreadPool.class);
36: private final ThreadPool executor;
37: private final String name;
38:
39: public JettyThreadPool(ThreadPool executor, String name) {
40: this .executor = executor;
41: this .name = name;
42: }
43:
44: public boolean dispatch(Runnable runnable) {
45: try {
46: executor.execute(name, runnable);
47: return true;
48: } catch (RejectedExecutionException e) {
49: log.warn("Unable to execute task", e);
50: return false;
51: } catch (InterruptedException e) {
52: log.warn("Thread interrupted", e);
53: return false;
54: }
55: }
56:
57: public void join() throws InterruptedException {
58: //umm, this is doubtful
59: executor
60: .awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
61: }
62:
63: public int getThreads() {
64: return executor.getPoolSize();
65: }
66:
67: public int getIdleThreads() {
68: return executor.getMaximumPoolSize() - executor.getPoolSize();
69: }
70:
71: public boolean isLowOnThreads() {
72: return executor.getPoolSize() >= executor.getMaximumPoolSize();
73: }
74: }
|