Coverage Report - org.apache.camel.management.InstrumentationLifecycleStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
InstrumentationLifecycleStrategy
0% 
0% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.management;
 19  
 
 20  
 import java.util.Collection;
 21  
 
 22  
 import javax.management.JMException;
 23  
 
 24  
 import org.apache.camel.CamelContext;
 25  
 import org.apache.camel.Endpoint;
 26  
 import org.apache.camel.InstrumentationAgent;
 27  
 import org.apache.camel.LifecycleStrategy;
 28  
 import org.apache.camel.Route;
 29  
 import org.apache.camel.Service;
 30  
 import org.apache.camel.impl.DefaultCamelContext;
 31  
 import org.apache.camel.impl.ServiceSupport;
 32  
 
 33  
 public class InstrumentationLifecycleStrategy implements LifecycleStrategy {
 34  
         InstrumentationAgent agent;
 35  
         CamelNamingStrategy naming;
 36  
         
 37  0
         public InstrumentationLifecycleStrategy(InstrumentationAgent agent) {
 38  0
                 this.agent = agent;
 39  0
                 naming = new CamelNamingStrategy(agent.getMBeanServer().getDefaultDomain()); 
 40  0
         }
 41  
         
 42  
         public void onContextCreate(CamelContext context) {
 43  0
                 if (context instanceof DefaultCamelContext) {
 44  
                         try {        
 45  0
                                 DefaultCamelContext dc = (DefaultCamelContext)context;
 46  0
                                 ManagedService ms = new ManagedService(dc);
 47  0
                                 agent.register(ms, naming.getObjectName(dc));
 48  
                         }
 49  0
                         catch(JMException e) {
 50  
                                 // log a WARN
 51  0
                         }
 52  
                 }
 53  0
         }
 54  
         
 55  
         public void onEndpointAdd(Endpoint endpoint) {
 56  
                 try {
 57  0
                         ManagedEndpoint me = new ManagedEndpoint(endpoint);
 58  0
                         agent.register(me, naming.getObjectName(me));
 59  
                 }
 60  0
                 catch(JMException e) {
 61  
                         // log a WARN
 62  0
                 }
 63  0
         }
 64  
 
 65  
         public void onRoutesAdd(Collection<Route> routes) {
 66  0
                 for (Route route: routes) {
 67  
                         try {
 68  0
                                 ManagedRoute mr = new ManagedRoute(route);
 69  0
                                 agent.register(mr, naming.getObjectName(mr));
 70  
                         }
 71  0
                         catch(JMException e) {
 72  
                                 // log a WARN
 73  0
                         }
 74  0
                 }
 75  0
         }
 76  
 
 77  
         public void onServiceAdd(CamelContext context, Service service) {
 78  0
                 if (service instanceof ServiceSupport) {
 79  
                         try {
 80  0
                                 ManagedService ms = new ManagedService((ServiceSupport)service);
 81  0
                                 agent.register(ms, naming.getObjectName(context, ms));
 82  
                         }
 83  0
                         catch(JMException e) {
 84  
                                 // log a WARN
 85  0
                         }
 86  
                 }
 87  0
         }
 88  
 }