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.management; 018 019import java.util.Iterator; 020import java.util.concurrent.ThreadPoolExecutor; 021 022import org.apache.camel.CamelContext; 023import org.apache.camel.Component; 024import org.apache.camel.Consumer; 025import org.apache.camel.DelegateProcessor; 026import org.apache.camel.Endpoint; 027import org.apache.camel.NamedNode; 028import org.apache.camel.Processor; 029import org.apache.camel.Producer; 030import org.apache.camel.Route; 031import org.apache.camel.Service; 032import org.apache.camel.cluster.CamelClusterService; 033import org.apache.camel.component.bean.BeanProcessor; 034import org.apache.camel.component.log.LogEndpoint; 035import org.apache.camel.health.HealthCheckRegistry; 036import org.apache.camel.management.mbean.ManagedAggregateProcessor; 037import org.apache.camel.management.mbean.ManagedBeanProcessor; 038import org.apache.camel.management.mbean.ManagedBrowsableEndpoint; 039import org.apache.camel.management.mbean.ManagedCamelContext; 040import org.apache.camel.management.mbean.ManagedCamelHealth; 041import org.apache.camel.management.mbean.ManagedChoice; 042import org.apache.camel.management.mbean.ManagedClaimCheck; 043import org.apache.camel.management.mbean.ManagedClusterService; 044import org.apache.camel.management.mbean.ManagedComponent; 045import org.apache.camel.management.mbean.ManagedConsumer; 046import org.apache.camel.management.mbean.ManagedConvertBody; 047import org.apache.camel.management.mbean.ManagedConvertHeader; 048import org.apache.camel.management.mbean.ManagedConvertVariable; 049import org.apache.camel.management.mbean.ManagedCustomLoadBalancer; 050import org.apache.camel.management.mbean.ManagedDataFormat; 051import org.apache.camel.management.mbean.ManagedDelayer; 052import org.apache.camel.management.mbean.ManagedDisabled; 053import org.apache.camel.management.mbean.ManagedDoCatch; 054import org.apache.camel.management.mbean.ManagedDoFinally; 055import org.apache.camel.management.mbean.ManagedDoTry; 056import org.apache.camel.management.mbean.ManagedDynamicRouter; 057import org.apache.camel.management.mbean.ManagedEndpoint; 058import org.apache.camel.management.mbean.ManagedEnricher; 059import org.apache.camel.management.mbean.ManagedEventNotifier; 060import org.apache.camel.management.mbean.ManagedFailoverLoadBalancer; 061import org.apache.camel.management.mbean.ManagedFilter; 062import org.apache.camel.management.mbean.ManagedIdempotentConsumer; 063import org.apache.camel.management.mbean.ManagedLog; 064import org.apache.camel.management.mbean.ManagedLoop; 065import org.apache.camel.management.mbean.ManagedMarshal; 066import org.apache.camel.management.mbean.ManagedMulticast; 067import org.apache.camel.management.mbean.ManagedPollEnricher; 068import org.apache.camel.management.mbean.ManagedProcess; 069import org.apache.camel.management.mbean.ManagedProcessor; 070import org.apache.camel.management.mbean.ManagedProducer; 071import org.apache.camel.management.mbean.ManagedRandomLoadBalancer; 072import org.apache.camel.management.mbean.ManagedRecipientList; 073import org.apache.camel.management.mbean.ManagedRemoveHeader; 074import org.apache.camel.management.mbean.ManagedRemoveHeaders; 075import org.apache.camel.management.mbean.ManagedRemoveProperties; 076import org.apache.camel.management.mbean.ManagedRemoveProperty; 077import org.apache.camel.management.mbean.ManagedRemoveVariable; 078import org.apache.camel.management.mbean.ManagedResequencer; 079import org.apache.camel.management.mbean.ManagedRollback; 080import org.apache.camel.management.mbean.ManagedRoundRobinLoadBalancer; 081import org.apache.camel.management.mbean.ManagedRoute; 082import org.apache.camel.management.mbean.ManagedRouteController; 083import org.apache.camel.management.mbean.ManagedRoutingSlip; 084import org.apache.camel.management.mbean.ManagedSamplingThrottler; 085import org.apache.camel.management.mbean.ManagedScheduledPollConsumer; 086import org.apache.camel.management.mbean.ManagedScript; 087import org.apache.camel.management.mbean.ManagedSendDynamicProcessor; 088import org.apache.camel.management.mbean.ManagedSendProcessor; 089import org.apache.camel.management.mbean.ManagedService; 090import org.apache.camel.management.mbean.ManagedSetBody; 091import org.apache.camel.management.mbean.ManagedSetExchangePattern; 092import org.apache.camel.management.mbean.ManagedSetHeader; 093import org.apache.camel.management.mbean.ManagedSetHeaders; 094import org.apache.camel.management.mbean.ManagedSetProperty; 095import org.apache.camel.management.mbean.ManagedSetVariable; 096import org.apache.camel.management.mbean.ManagedSetVariables; 097import org.apache.camel.management.mbean.ManagedSplitter; 098import org.apache.camel.management.mbean.ManagedStep; 099import org.apache.camel.management.mbean.ManagedStickyLoadBalancer; 100import org.apache.camel.management.mbean.ManagedStop; 101import org.apache.camel.management.mbean.ManagedSupervisingRouteController; 102import org.apache.camel.management.mbean.ManagedSuspendableRoute; 103import org.apache.camel.management.mbean.ManagedThreadPool; 104import org.apache.camel.management.mbean.ManagedThreads; 105import org.apache.camel.management.mbean.ManagedThrottler; 106import org.apache.camel.management.mbean.ManagedThroughputLogger; 107import org.apache.camel.management.mbean.ManagedThrowException; 108import org.apache.camel.management.mbean.ManagedTopicLoadBalancer; 109import org.apache.camel.management.mbean.ManagedTransformer; 110import org.apache.camel.management.mbean.ManagedUnmarshal; 111import org.apache.camel.management.mbean.ManagedValidate; 112import org.apache.camel.management.mbean.ManagedWeightedLoadBalancer; 113import org.apache.camel.management.mbean.ManagedWireTapProcessor; 114import org.apache.camel.model.AggregateDefinition; 115import org.apache.camel.model.CatchDefinition; 116import org.apache.camel.model.DynamicRouterDefinition; 117import org.apache.camel.model.EnrichDefinition; 118import org.apache.camel.model.ExpressionNode; 119import org.apache.camel.model.FinallyDefinition; 120import org.apache.camel.model.IdempotentConsumerDefinition; 121import org.apache.camel.model.LoadBalanceDefinition; 122import org.apache.camel.model.LoopDefinition; 123import org.apache.camel.model.MarshalDefinition; 124import org.apache.camel.model.PollEnrichDefinition; 125import org.apache.camel.model.ProcessDefinition; 126import org.apache.camel.model.ProcessorDefinition; 127import org.apache.camel.model.RecipientListDefinition; 128import org.apache.camel.model.RoutingSlipDefinition; 129import org.apache.camel.model.ScriptDefinition; 130import org.apache.camel.model.SetBodyDefinition; 131import org.apache.camel.model.SetHeaderDefinition; 132import org.apache.camel.model.SetHeadersDefinition; 133import org.apache.camel.model.SetPropertyDefinition; 134import org.apache.camel.model.SetVariableDefinition; 135import org.apache.camel.model.SetVariablesDefinition; 136import org.apache.camel.model.SplitDefinition; 137import org.apache.camel.model.TransformDefinition; 138import org.apache.camel.model.TryDefinition; 139import org.apache.camel.model.UnmarshalDefinition; 140import org.apache.camel.model.ValidateDefinition; 141import org.apache.camel.model.loadbalancer.CustomLoadBalancerDefinition; 142import org.apache.camel.processor.CatchProcessor; 143import org.apache.camel.processor.ChoiceProcessor; 144import org.apache.camel.processor.ClaimCheckProcessor; 145import org.apache.camel.processor.Delayer; 146import org.apache.camel.processor.DisabledProcessor; 147import org.apache.camel.processor.DynamicRouter; 148import org.apache.camel.processor.Enricher; 149import org.apache.camel.processor.ExchangePatternProcessor; 150import org.apache.camel.processor.FilterProcessor; 151import org.apache.camel.processor.FinallyProcessor; 152import org.apache.camel.processor.LogProcessor; 153import org.apache.camel.processor.LoopProcessor; 154import org.apache.camel.processor.MulticastProcessor; 155import org.apache.camel.processor.Pipeline; 156import org.apache.camel.processor.PollEnricher; 157import org.apache.camel.processor.RecipientList; 158import org.apache.camel.processor.RemoveHeaderProcessor; 159import org.apache.camel.processor.RemoveHeadersProcessor; 160import org.apache.camel.processor.RemovePropertiesProcessor; 161import org.apache.camel.processor.RemovePropertyProcessor; 162import org.apache.camel.processor.RemoveVariableProcessor; 163import org.apache.camel.processor.Resequencer; 164import org.apache.camel.processor.RollbackProcessor; 165import org.apache.camel.processor.RoutingSlip; 166import org.apache.camel.processor.SamplingThrottler; 167import org.apache.camel.processor.ScriptProcessor; 168import org.apache.camel.processor.SendDynamicProcessor; 169import org.apache.camel.processor.SendProcessor; 170import org.apache.camel.processor.SetBodyProcessor; 171import org.apache.camel.processor.SetHeaderProcessor; 172import org.apache.camel.processor.SetHeadersProcessor; 173import org.apache.camel.processor.SetPropertyProcessor; 174import org.apache.camel.processor.SetVariableProcessor; 175import org.apache.camel.processor.SetVariablesProcessor; 176import org.apache.camel.processor.Splitter; 177import org.apache.camel.processor.StepProcessor; 178import org.apache.camel.processor.StopProcessor; 179import org.apache.camel.processor.StreamResequencer; 180import org.apache.camel.processor.ThreadsProcessor; 181import org.apache.camel.processor.Throttler; 182import org.apache.camel.processor.ThrowExceptionProcessor; 183import org.apache.camel.processor.TransformProcessor; 184import org.apache.camel.processor.TryProcessor; 185import org.apache.camel.processor.WireTapProcessor; 186import org.apache.camel.processor.aggregate.AggregateProcessor; 187import org.apache.camel.processor.idempotent.IdempotentConsumer; 188import org.apache.camel.processor.loadbalancer.FailOverLoadBalancer; 189import org.apache.camel.processor.loadbalancer.LoadBalancer; 190import org.apache.camel.processor.loadbalancer.RandomLoadBalancer; 191import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer; 192import org.apache.camel.processor.loadbalancer.StickyLoadBalancer; 193import org.apache.camel.processor.loadbalancer.TopicLoadBalancer; 194import org.apache.camel.processor.loadbalancer.WeightedLoadBalancer; 195import org.apache.camel.processor.transformer.DataTypeProcessor; 196import org.apache.camel.spi.BrowsableEndpoint; 197import org.apache.camel.spi.DataFormat; 198import org.apache.camel.spi.ErrorHandler; 199import org.apache.camel.spi.EventNotifier; 200import org.apache.camel.spi.ManagementObjectStrategy; 201import org.apache.camel.spi.RouteController; 202import org.apache.camel.spi.SupervisingRouteController; 203import org.apache.camel.support.ScheduledPollConsumer; 204import org.apache.camel.support.processor.ConvertBodyProcessor; 205import org.apache.camel.support.processor.ConvertHeaderProcessor; 206import org.apache.camel.support.processor.ConvertVariableProcessor; 207import org.apache.camel.support.processor.MarshalProcessor; 208import org.apache.camel.support.processor.PredicateValidatingProcessor; 209import org.apache.camel.support.processor.ThroughputLogger; 210import org.apache.camel.support.processor.UnmarshalProcessor; 211 212/** 213 * Default {@link org.apache.camel.spi.ManagementObjectStrategy}. 214 */ 215public class DefaultManagementObjectStrategy implements ManagementObjectStrategy { 216 217 @Override 218 public Object getManagedObjectForCamelContext(CamelContext context) { 219 ManagedCamelContext mc = new ManagedCamelContext(context); 220 mc.init(context.getManagementStrategy()); 221 return mc; 222 } 223 224 @Override 225 public Object getManagedObjectForCamelHealth(CamelContext context, HealthCheckRegistry healthCheckRegistry) { 226 ManagedCamelHealth mch = new ManagedCamelHealth(context, healthCheckRegistry); 227 mch.init(context.getManagementStrategy()); 228 return mch; 229 } 230 231 @Override 232 public Object getManagedObjectForComponent(CamelContext context, Component component, String name) { 233 ManagedComponent mc = new ManagedComponent(name, component); 234 mc.init(context.getManagementStrategy()); 235 return mc; 236 } 237 238 @Override 239 public Object getManagedObjectForDataFormat(CamelContext context, DataFormat dataFormat) { 240 ManagedDataFormat md = new ManagedDataFormat(context, dataFormat); 241 md.init(context.getManagementStrategy()); 242 return md; 243 } 244 245 @Override 246 public Object getManagedObjectForEndpoint(CamelContext context, Endpoint endpoint) { 247 // we only want to manage singleton endpoints 248 if (!endpoint.isSingleton()) { 249 return null; 250 } 251 252 if (endpoint instanceof BrowsableEndpoint) { 253 ManagedBrowsableEndpoint me = new ManagedBrowsableEndpoint((BrowsableEndpoint) endpoint); 254 me.init(context.getManagementStrategy()); 255 return me; 256 } else { 257 ManagedEndpoint me = new ManagedEndpoint(endpoint); 258 me.init(context.getManagementStrategy()); 259 return me; 260 } 261 } 262 263 @Override 264 public Object getManagedObjectForRouteController(CamelContext context, RouteController routeController) { 265 ManagedService mrc; 266 if (routeController instanceof SupervisingRouteController) { 267 mrc = new ManagedSupervisingRouteController(context, (SupervisingRouteController) routeController); 268 } else { 269 mrc = new ManagedRouteController(context, routeController); 270 } 271 mrc.init(context.getManagementStrategy()); 272 return mrc; 273 } 274 275 @Override 276 public Object getManagedObjectForRoute(CamelContext context, Route route) { 277 ManagedRoute mr; 278 if (route.supportsSuspension()) { 279 mr = new ManagedSuspendableRoute(context, route); 280 } else { 281 mr = new ManagedRoute(context, route); 282 } 283 mr.init(context.getManagementStrategy()); 284 return mr; 285 } 286 287 @Override 288 public Object getManagedObjectForThreadPool( 289 CamelContext context, ThreadPoolExecutor threadPool, 290 String id, String sourceId, String routeId, String threadPoolProfileId) { 291 ManagedThreadPool mtp = new ManagedThreadPool(context, threadPool, id, sourceId, routeId, threadPoolProfileId); 292 mtp.init(context.getManagementStrategy()); 293 return mtp; 294 } 295 296 @Override 297 public Object getManagedObjectForEventNotifier(CamelContext context, EventNotifier eventNotifier) { 298 ManagedEventNotifier men = new ManagedEventNotifier(context, eventNotifier); 299 men.init(context.getManagementStrategy()); 300 return men; 301 } 302 303 @Override 304 public Object getManagedObjectForConsumer(CamelContext context, Consumer consumer) { 305 ManagedConsumer mc; 306 if (consumer instanceof ScheduledPollConsumer) { 307 mc = new ManagedScheduledPollConsumer(context, (ScheduledPollConsumer) consumer); 308 } else { 309 mc = new ManagedConsumer(context, consumer); 310 } 311 mc.init(context.getManagementStrategy()); 312 return mc; 313 } 314 315 @Override 316 public Object getManagedObjectForProducer(CamelContext context, Producer producer) { 317 ManagedProducer mp = new ManagedProducer(context, producer); 318 mp.init(context.getManagementStrategy()); 319 return mp; 320 } 321 322 @Override 323 public Object getManagedObjectForService(CamelContext context, Service service) { 324 ManagedService mc = new ManagedService(context, service); 325 mc.init(context.getManagementStrategy()); 326 return mc; 327 } 328 329 @Override 330 public Object getManagedObjectForClusterService(CamelContext context, CamelClusterService service) { 331 ManagedClusterService mcs = new ManagedClusterService(context, service); 332 mcs.init(context.getManagementStrategy()); 333 return mcs; 334 } 335 336 @Override 337 public Object getManagedObjectForProcessor( 338 CamelContext context, Processor processor, 339 NamedNode node, Route route) { 340 ManagedProcessor answer = null; 341 342 ProcessorDefinition<?> definition = (ProcessorDefinition<?>) node; 343 344 if (definition instanceof RecipientListDefinition) { 345 // special for RecipientListDefinition, as the processor is wrapped in a pipeline as last 346 Pipeline pipeline = (Pipeline) processor; 347 Iterator<Processor> it = pipeline.next().iterator(); 348 while (it.hasNext()) { 349 processor = it.next(); 350 } 351 } 352 353 // unwrap delegates as we want the real target processor 354 Processor target = processor; 355 while (target != null) { 356 357 // skip error handlers 358 if (target instanceof ErrorHandler) { 359 return false; 360 } 361 362 if (target instanceof ConvertBodyProcessor) { 363 answer = new ManagedConvertBody(context, (ConvertBodyProcessor) target, definition); 364 } else if (target instanceof ConvertHeaderProcessor) { 365 answer = new ManagedConvertHeader(context, (ConvertHeaderProcessor) target, definition); 366 } else if (target instanceof ConvertVariableProcessor) { 367 answer = new ManagedConvertVariable(context, (ConvertVariableProcessor) target, definition); 368 } else if (target instanceof ChoiceProcessor) { 369 answer = new ManagedChoice(context, (ChoiceProcessor) target, definition); 370 } else if (target instanceof ClaimCheckProcessor) { 371 answer = new ManagedClaimCheck(context, (ClaimCheckProcessor) target, definition); 372 } else if (target instanceof Delayer) { 373 answer = new ManagedDelayer(context, (Delayer) target, definition); 374 } else if (target instanceof DisabledProcessor) { 375 answer = new ManagedDisabled(context, (DisabledProcessor) target, definition); 376 } else if (target instanceof TryProcessor) { 377 answer = new ManagedDoTry(context, (TryProcessor) target, (TryDefinition) definition); 378 } else if (target instanceof CatchProcessor) { 379 answer = new ManagedDoCatch(context, (CatchProcessor) target, (CatchDefinition) definition); 380 } else if (target instanceof FinallyProcessor) { 381 answer = new ManagedDoFinally(context, (FinallyProcessor) target, (FinallyDefinition) definition); 382 } else if (target instanceof Throttler) { 383 answer = new ManagedThrottler(context, (Throttler) target, definition); 384 } else if (target instanceof DynamicRouter) { 385 answer = new ManagedDynamicRouter(context, (DynamicRouter) target, (DynamicRouterDefinition) definition); 386 } else if (target instanceof RoutingSlip) { 387 answer = new ManagedRoutingSlip(context, (RoutingSlip) target, (RoutingSlipDefinition) definition); 388 } else if (target instanceof FilterProcessor) { 389 answer = new ManagedFilter(context, (FilterProcessor) target, (ExpressionNode) definition); 390 } else if (target instanceof LogProcessor) { 391 answer = new ManagedLog(context, (LogProcessor) target, definition); 392 } else if (target instanceof LoopProcessor) { 393 answer = new ManagedLoop(context, (LoopProcessor) target, (LoopDefinition) definition); 394 } else if (target instanceof MarshalProcessor) { 395 answer = new ManagedMarshal(context, (MarshalProcessor) target, (MarshalDefinition) definition); 396 } else if (target instanceof UnmarshalProcessor) { 397 answer = new ManagedUnmarshal(context, (UnmarshalProcessor) target, (UnmarshalDefinition) definition); 398 } else if (target instanceof FailOverLoadBalancer) { 399 answer = new ManagedFailoverLoadBalancer( 400 context, (FailOverLoadBalancer) target, (LoadBalanceDefinition) definition); 401 } else if (target instanceof RandomLoadBalancer) { 402 answer = new ManagedRandomLoadBalancer( 403 context, (RandomLoadBalancer) target, (LoadBalanceDefinition) definition); 404 } else if (target instanceof RoundRobinLoadBalancer) { 405 answer = new ManagedRoundRobinLoadBalancer( 406 context, (RoundRobinLoadBalancer) target, (LoadBalanceDefinition) definition); 407 } else if (target instanceof StickyLoadBalancer) { 408 answer = new ManagedStickyLoadBalancer( 409 context, (StickyLoadBalancer) target, (LoadBalanceDefinition) definition); 410 } else if (target instanceof TopicLoadBalancer) { 411 answer = new ManagedTopicLoadBalancer(context, (TopicLoadBalancer) target, (LoadBalanceDefinition) definition); 412 } else if (target instanceof WeightedLoadBalancer) { 413 answer = new ManagedWeightedLoadBalancer( 414 context, (WeightedLoadBalancer) target, (LoadBalanceDefinition) definition); 415 } else if (target instanceof RecipientList) { 416 answer = new ManagedRecipientList(context, (RecipientList) target, (RecipientListDefinition) definition); 417 } else if (target instanceof Splitter) { 418 answer = new ManagedSplitter(context, (Splitter) target, (SplitDefinition) definition); 419 } else if (target instanceof MulticastProcessor) { 420 answer = new ManagedMulticast(context, (MulticastProcessor) target, definition); 421 } else if (target instanceof SamplingThrottler) { 422 answer = new ManagedSamplingThrottler(context, (SamplingThrottler) target, definition); 423 } else if (target instanceof Resequencer) { 424 answer = new ManagedResequencer(context, (Resequencer) target, definition); 425 } else if (target instanceof RollbackProcessor) { 426 answer = new ManagedRollback(context, (RollbackProcessor) target, definition); 427 } else if (target instanceof StreamResequencer) { 428 answer = new ManagedResequencer(context, (StreamResequencer) target, definition); 429 } else if (target instanceof SetBodyProcessor) { 430 answer = new ManagedSetBody(context, (SetBodyProcessor) target, (SetBodyDefinition) definition); 431 } else if (target instanceof RemoveHeaderProcessor) { 432 answer = new ManagedRemoveHeader(context, (RemoveHeaderProcessor) target, definition); 433 } else if (target instanceof RemoveHeadersProcessor) { 434 answer = new ManagedRemoveHeaders(context, (RemoveHeadersProcessor) target, definition); 435 } else if (target instanceof SetHeaderProcessor) { 436 answer = new ManagedSetHeader(context, (SetHeaderProcessor) target, (SetHeaderDefinition) definition); 437 } else if (target instanceof SetHeadersProcessor) { 438 answer = new ManagedSetHeaders(context, (SetHeadersProcessor) target, (SetHeadersDefinition) definition); 439 } else if (target instanceof SetVariableProcessor) { 440 answer = new ManagedSetVariable(context, (SetVariableProcessor) target, (SetVariableDefinition) definition); 441 } else if (target instanceof SetVariablesProcessor) { 442 answer = new ManagedSetVariables(context, (SetVariablesProcessor) target, (SetVariablesDefinition) definition); 443 } else if (target instanceof RemovePropertyProcessor) { 444 answer = new ManagedRemoveProperty(context, (RemovePropertyProcessor) target, definition); 445 } else if (target instanceof RemovePropertiesProcessor) { 446 answer = new ManagedRemoveProperties(context, (RemovePropertiesProcessor) target, definition); 447 } else if (target instanceof RemoveVariableProcessor) { 448 answer = new ManagedRemoveVariable(context, (RemoveVariableProcessor) target, definition); 449 } else if (target instanceof SetPropertyProcessor) { 450 answer = new ManagedSetProperty(context, (SetPropertyProcessor) target, (SetPropertyDefinition) definition); 451 } else if (target instanceof ExchangePatternProcessor) { 452 answer = new ManagedSetExchangePattern(context, (ExchangePatternProcessor) target, definition); 453 } else if (target instanceof ScriptProcessor) { 454 answer = new ManagedScript(context, (ScriptProcessor) target, (ScriptDefinition) definition); 455 } else if (target instanceof StepProcessor) { 456 answer = new ManagedStep(context, (StepProcessor) target, definition); 457 } else if (target instanceof StopProcessor) { 458 answer = new ManagedStop(context, (StopProcessor) target, definition); 459 } else if (target instanceof ThreadsProcessor) { 460 answer = new ManagedThreads(context, (ThreadsProcessor) target, definition); 461 } else if (target instanceof ThrowExceptionProcessor) { 462 answer = new ManagedThrowException(context, (ThrowExceptionProcessor) target, definition); 463 } else if (target instanceof TransformProcessor) { 464 answer = new ManagedTransformer(context, target, (TransformDefinition) definition); 465 } else if (target instanceof DataTypeProcessor && definition instanceof TransformDefinition) { 466 answer = new ManagedTransformer(context, target, (TransformDefinition) definition); 467 } else if (target instanceof PredicateValidatingProcessor) { 468 answer = new ManagedValidate(context, (PredicateValidatingProcessor) target, (ValidateDefinition) definition); 469 } else if (target instanceof WireTapProcessor) { 470 answer = new ManagedWireTapProcessor(context, (WireTapProcessor) target, definition); 471 } else if (target instanceof SendDynamicProcessor) { 472 answer = new ManagedSendDynamicProcessor(context, (SendDynamicProcessor) target, definition); 473 } else if (target instanceof SendProcessor) { 474 SendProcessor sp = (SendProcessor) target; 475 // special for sending to throughput logger 476 if (sp.getDestination() instanceof LogEndpoint) { 477 LogEndpoint le = (LogEndpoint) sp.getDestination(); 478 if (le.getLogger() instanceof ThroughputLogger) { 479 ThroughputLogger tl = (ThroughputLogger) le.getLogger(); 480 answer = new ManagedThroughputLogger(context, tl, definition); 481 } 482 } 483 // regular send processor 484 if (answer == null) { 485 answer = new ManagedSendProcessor(context, (SendProcessor) target, definition); 486 } 487 } else if (target instanceof BeanProcessor) { 488 answer = new ManagedBeanProcessor(context, (BeanProcessor) target, definition); 489 } else if (target instanceof IdempotentConsumer) { 490 answer = new ManagedIdempotentConsumer( 491 context, (IdempotentConsumer) target, (IdempotentConsumerDefinition) definition); 492 } else if (target instanceof AggregateProcessor) { 493 answer = new ManagedAggregateProcessor(context, (AggregateProcessor) target, (AggregateDefinition) definition); 494 } else if (target instanceof Enricher) { 495 answer = new ManagedEnricher(context, (Enricher) target, (EnrichDefinition) definition); 496 } else if (target instanceof PollEnricher) { 497 answer = new ManagedPollEnricher(context, (PollEnricher) target, (PollEnrichDefinition) definition); 498 } 499 500 // special for custom load balancer 501 if (definition instanceof LoadBalanceDefinition) { 502 LoadBalanceDefinition lb = (LoadBalanceDefinition) definition; 503 if (lb.getLoadBalancerType() instanceof CustomLoadBalancerDefinition) { 504 answer = new ManagedCustomLoadBalancer(context, (LoadBalancer) target, (LoadBalanceDefinition) definition); 505 } 506 } 507 508 if (answer != null) { 509 // break out as we found an answer 510 break; 511 } 512 513 // no answer yet, so unwrap any delegates and try again 514 if (target instanceof DelegateProcessor) { 515 target = ((DelegateProcessor) target).getProcessor(); 516 } else { 517 // no delegate so we dont have any target to try next 518 break; 519 } 520 } 521 522 if (answer == null && definition instanceof ProcessDefinition) { 523 answer = new ManagedProcess(context, target, (ProcessDefinition) definition); 524 } else if (answer == null) { 525 // fallback to a generic processor 526 answer = new ManagedProcessor(context, target, definition); 527 } 528 529 answer.setRoute(route); 530 answer.init(context.getManagementStrategy()); 531 return answer; 532 } 533 534}