001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.impl; 018 019import java.util.concurrent.ExecutorService; 020import java.util.concurrent.ScheduledExecutorService; 021 022import org.apache.camel.CamelContext; 023import org.apache.camel.ExtendedCamelContext; 024import org.apache.camel.impl.engine.BaseExecutorServiceManager; 025import org.apache.camel.model.OptionalIdentifiedDefinition; 026import org.apache.camel.spi.NodeIdFactory; 027import org.apache.camel.spi.ThreadPoolProfile; 028 029/** 030 * Default {@link org.apache.camel.spi.ExecutorServiceManager}. 031 */ 032public class DefaultExecutorServiceManager extends BaseExecutorServiceManager { 033 034 public DefaultExecutorServiceManager(CamelContext camelContext) { 035 super(camelContext); 036 } 037 038 @Override 039 public ExecutorService newThreadPool(Object source, String name, ThreadPoolProfile profile) { 040 return super.newThreadPool(forceId(source), name, profile); 041 } 042 043 @Override 044 public ExecutorService newCachedThreadPool(Object source, String name) { 045 return super.newCachedThreadPool(forceId(source), name); 046 } 047 048 @Override 049 public ScheduledExecutorService newScheduledThreadPool(Object source, String name, ThreadPoolProfile profile) { 050 return super.newScheduledThreadPool(forceId(source), name, profile); 051 } 052 053 protected Object forceId(Object source) { 054 if (source instanceof OptionalIdentifiedDefinition) { 055 NodeIdFactory factory = getCamelContext().adapt(ExtendedCamelContext.class).getNodeIdFactory(); 056 ((OptionalIdentifiedDefinition)source).idOrCreate(factory); 057 } 058 return source; 059 } 060 061}