Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl.executor » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.concurrent.impl.executor;
   18   
   19   import java.util.List;
   20   
   21   import javax.util.concurrent.ManagedScheduledExecutorService;
   22   import javax.util.concurrent.ManagedThreadFactory;
   23   
   24   import org.apache.geronimo.concurrent.ManagedContextHandler;
   25   import org.apache.geronimo.concurrent.ManagedContextHandlerChain;
   26   import org.apache.geronimo.concurrent.executor.ComponentManagedScheduledExecutorService;
   27   import org.apache.geronimo.concurrent.executor.ManagedScheduledExecutorServiceFacade;
   28   import org.apache.geronimo.concurrent.impl.ContextHandlerUtils;
   29   import org.apache.geronimo.concurrent.impl.thread.GeronimoManagedThreadFactorySource;
   30   import org.apache.geronimo.concurrent.naming.ModuleAwareResourceSource;
   31   import org.apache.geronimo.gbean.AbstractName;
   32   import org.apache.geronimo.gbean.GBeanInfo;
   33   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   34   import org.apache.geronimo.gbean.GBeanLifecycle;
   35   import org.apache.geronimo.management.ManagedConstants;
   36   
   37   public class ComponentManagedScheduledExecutorServiceGBean implements GBeanLifecycle, ModuleAwareResourceSource {
   38   
   39       public static final GBeanInfo GBEAN_INFO;
   40   
   41       protected ManagedScheduledExecutorService executor;
   42   
   43       protected int corePoolSize;
   44       protected ManagedThreadFactory threadFactory;    
   45       protected ManagedContextHandlerChain contextHandler;
   46      
   47       public ComponentManagedScheduledExecutorServiceGBean(ClassLoader classLoader,
   48                                                            int corePoolSize,
   49                                                            GeronimoManagedThreadFactorySource threadFactorySource,
   50                                                            String[] contextHandlerClasses) {
   51           this.corePoolSize = corePoolSize;
   52           this.threadFactory = threadFactorySource.getManagedThreadFactory();
   53           List<ManagedContextHandler> handlers = 
   54               ContextHandlerUtils.loadHandlers(classLoader, contextHandlerClasses);
   55           this.contextHandler = new ManagedContextHandlerChain(handlers);
   56       }
   57   
   58       protected synchronized ManagedScheduledExecutorService getManagedScheduledExecutorService() {
   59           if (this.executor == null) {
   60               this.executor = new ComponentManagedScheduledExecutorService(this.corePoolSize, 
   61                                                                            this.threadFactory,
   62                                                                            this.contextHandler);
   63           }
   64           return this.executor;        
   65       }
   66       
   67       protected synchronized void shutdownExecutor() {
   68           if (this.executor != null) {
   69               this.executor.shutdown();
   70           }
   71       }
   72       
   73       public Object $getResource(AbstractName moduleID) {
   74           return new ManagedScheduledExecutorServiceFacade(getManagedScheduledExecutorService(), false);
   75       }
   76   
   77       public void doStart() throws Exception {
   78       }
   79   
   80       public void doFail() {
   81           shutdownExecutor();
   82       }
   83       
   84       public void doStop() throws Exception {
   85           doFail();
   86       }
   87   
   88       static {
   89           GBeanInfoBuilder infoFactory = 
   90               GBeanInfoBuilder.createStatic(ComponentManagedScheduledExecutorServiceGBean.class, 
   91                                             ManagedConstants.MANAGED_EXECUTOR_SERVICE);
   92   
   93           infoFactory.addAttribute("classLoader", ClassLoader.class, false);
   94           
   95           infoFactory.addAttribute("corePoolSize", int.class, true);
   96           infoFactory.addAttribute("contextHandlers", String[].class, true);
   97   
   98           infoFactory.addReference("threadFactory", GeronimoManagedThreadFactorySource.class);
   99   
  100           infoFactory.setConstructor(new String[] { "classLoader",
  101                                                     "corePoolSize", 
  102                                                     "threadFactory",
  103                                                     "contextHandlers" });
  104   
  105           GBEAN_INFO = infoFactory.getBeanInfo();
  106       }
  107   
  108       public static GBeanInfo getGBeanInfo() {
  109           return GBEAN_INFO;
  110       }
  111   
  112   }

Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl.executor » [javadoc | source]