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