Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.jetty7.connector » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   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   
   21   package org.apache.geronimo.jetty7.connector;
   22   
   23   import java.util.concurrent.RejectedExecutionException;
   24   import java.util.concurrent.TimeUnit;
   25   
   26   import org.slf4j.Logger;
   27   import org.slf4j.LoggerFactory;
   28   import org.apache.geronimo.system.threads.ThreadPool;
   29   
   30   /**
   31    * @version $Rev: 759104 $ $Date: 2009-03-27 04:21:58 -0700 (Fri, 27 Mar 2009) $
   32    */
   33   public class JettyThreadPool implements org.eclipse.jetty.util.thread.ThreadPool {
   34   
   35       private static final Logger log = LoggerFactory.getLogger(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.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
   60       }
   61   
   62       public int getThreads() {
   63           return executor.getPoolSize();
   64       }
   65   
   66       public int getIdleThreads() {
   67           return executor.getMaximumPoolSize() - executor.getPoolSize();
   68       }
   69   
   70       public boolean isLowOnThreads() {
   71           return executor.getPoolSize() >= executor.getMaximumPoolSize();
   72       }
   73   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.jetty7.connector » [javadoc | source]