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.concurrent.ArrayBlockingQueue; 20 import java.util.concurrent.BlockingQueue; 21 import java.util.concurrent.LinkedBlockingQueue; 22 import java.util.concurrent.TimeUnit; 23 24 import javax.util.concurrent.ManagedExecutorService; 25 26 import org.apache.geronimo.concurrent.executor.ServerManagedExecutorService; 27 import org.apache.geronimo.concurrent.impl.GBeanBuilder; 28 import org.apache.geronimo.concurrent.impl.NotificationHelper; 29 import org.apache.geronimo.concurrent.impl.thread.GeronimoManagedThreadFactorySource; 30 import org.apache.geronimo.gbean.AbstractName; 31 import org.apache.geronimo.gbean.GBeanInfo; 32 import org.apache.geronimo.gbean.GBeanInfoBuilder; 33 import org.apache.geronimo.kernel.Kernel; 34 import org.apache.geronimo.management.EventProvider; 35 import org.apache.geronimo.management.ManagedConstants; 36 37 public class ServerManagedExecutorServiceGBean extends ComponentManagedExecutorServiceGBean implements EventProvider, org.apache.geronimo.management.ManagedExecutorService { 38 39 public static final GBeanInfo GBEAN_INFO; 40 41 private AbstractName name; 42 43 private ServerManagedThreadFactory threadFactory; 44 45 public ServerManagedExecutorServiceGBean(Kernel kernel, 46 AbstractName name, 47 ClassLoader classLoader, 48 int minPoolSize, 49 int maxPoolSize, 50 long keepAliveTime, 51 int queueCapacity, 52 GeronimoManagedThreadFactorySource threadFactorySource, 53 String[] contextHandlerClasses) { 54 super(classLoader, minPoolSize, maxPoolSize, keepAliveTime, queueCapacity, threadFactorySource, contextHandlerClasses); 55 this.name = name; 56 57 NotificationHelper notificationHelper = new NotificationHelper(kernel, name); 58 this.threadFactory = new ServerManagedThreadFactory(threadFactorySource.getManagedThreadFactory(), notificationHelper); 59 } 60 61 protected synchronized ManagedExecutorService getManagedExecutorService() { 62 if (this.executor == null) { 63 BlockingQueue<Runnable> queue = null; 64 if (this.queueCapacity <= 0) { 65 queue = new LinkedBlockingQueue<Runnable>(); 66 } else { 67 queue = new ArrayBlockingQueue<Runnable>(this.queueCapacity); 68 } 69 this.executor = new ServerManagedExecutorService(this.minPoolSize, 70 this.maxPoolSize, 71 this.keepAliveTime, 72 TimeUnit.MILLISECONDS, 73 queue, 74 this.threadFactory, 75 this.contextHandler); 76 } 77 return this.executor; 78 } 79 80 @Override 81 public Object $getResource(AbstractName moduleID) { 82 return new ManagedExecutorServiceModuleFacade(getManagedExecutorService(), moduleID); 83 } 84 85 public AbstractName getName() { 86 return this.name; 87 } 88 89 public String getObjectName() { 90 return this.name.getObjectName().getCanonicalName(); 91 } 92 93 public String[] getEventTypes() { 94 return this.threadFactory.getEventTypes(); 95 } 96 97 public String[] getHungTaskThreads() { 98 return this.threadFactory.getHungTaskThreads(); 99 } 100 101 public String[] getThreads() { 102 return this.threadFactory.getThreads(); 103 } 104 105 public boolean isEventProvider() { 106 return true; 107 } 108 109 public boolean isStateManageable() { 110 return true; 111 } 112 113 public boolean isStatisticsProvider() { 114 return false; 115 } 116 117 protected void verifyObjectName() { 118 GBeanBuilder.verifyObjectName(getObjectName(), 119 ManagedConstants.MANAGED_EXECUTOR_SERVICE, 120 ManagedConstants.MANAGED_EXECUTOR_SERVICE); 121 } 122 123 static { 124 GBeanInfoBuilder infoFactory = 125 GBeanInfoBuilder.createStatic(ServerManagedExecutorServiceGBean.class, 126 ManagedConstants.MANAGED_EXECUTOR_SERVICE); 127 128 infoFactory.addAttribute("classLoader", ClassLoader.class, false); 129 infoFactory.addAttribute("abstractName", AbstractName.class, false); 130 infoFactory.addAttribute("kernel", Kernel.class, false); 131 132 infoFactory.addAttribute("minPoolSize", int.class, true); 133 infoFactory.addAttribute("maxPoolSize", int.class, true); 134 infoFactory.addAttribute("keepAliveTime", long.class, true); 135 infoFactory.addAttribute("queueCapacity", int.class, true); 136 infoFactory.addAttribute("contextHandlers", String[].class, true); 137 138 infoFactory.addReference("threadFactory", GeronimoManagedThreadFactorySource.class); 139 140 infoFactory.addInterface(org.apache.geronimo.management.ManagedExecutorService.class); 141 142 infoFactory.setConstructor(new String[] { "kernel", 143 "abstractName", 144 "classLoader", 145 "minPoolSize", 146 "maxPoolSize", 147 "keepAliveTime", 148 "queueCapacity", 149 "threadFactory", 150 "contextHandlers" }); 151 152 GBEAN_INFO = infoFactory.getBeanInfo(); 153 } 154 155 public static GBeanInfo getGBeanInfo() { 156 return GBEAN_INFO; 157 } 158 159 }