Coverage Report - org.apache.camel.component.jmx.JMXEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
JMXEndpoint
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.component.jmx;
 19  
 
 20  
 import javax.management.MBeanServer;
 21  
 import javax.management.Notification;
 22  
 import javax.management.ObjectName;
 23  
 import javax.management.monitor.CounterMonitor;
 24  
 import org.apache.camel.Consumer;
 25  
 import org.apache.camel.Processor;
 26  
 import org.apache.camel.Producer;
 27  
 import org.apache.camel.impl.DefaultEndpoint;
 28  
 import org.apache.commons.logging.Log;
 29  
 import org.apache.commons.logging.LogFactory;
 30  
 
 31  
 /**
 32  
  * Creates a CounterMonitor for jmx attributes
 33  
  *
 34  
  * @version $Revision: 523016 $
 35  
  */
 36  0
 public class JMXEndpoint extends DefaultEndpoint<JMXExchange> {
 37  
 
 38  0
         private static final Log log=LogFactory.getLog(JMXEndpoint.class);
 39  
         private String name;
 40  
         private ObjectName ourName;
 41  
         private String observedObjectName;
 42  
         private String attributeName;
 43  0
         private long granularityPeriod=5000;
 44  
         private Number threshold;
 45  
         private Number offset;
 46  
         private MBeanServer mbeanServer;
 47  0
         private CounterMonitor counterMonitor=new CounterMonitor();
 48  
 
 49  
         protected JMXEndpoint(String endpointUri,JMXComponent component){
 50  0
                 super(endpointUri,component);
 51  0
                 observedObjectName=endpointUri;
 52  0
         }
 53  
 
 54  
         /**
 55  
          * @return a Producer
 56  
          * @throws Exception
 57  
          * @see org.apache.camel.Endpoint#createProducer()
 58  
          */
 59  
         public Producer<JMXExchange> createProducer() throws Exception{
 60  0
                 throw new RuntimeException("Not supported");
 61  
         }
 62  
 
 63  
         /**
 64  
          * @param proc
 65  
          * @return a Consumer
 66  
          * @throws Exception
 67  
          * @see org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor)
 68  
          */
 69  
         public Consumer<JMXExchange> createConsumer(Processor proc)
 70  
                 throws Exception{
 71  0
                 ObjectName observedName=new ObjectName(observedObjectName);
 72  0
                 if(name==null){
 73  0
                         String type=observedName.getKeyProperty("type");
 74  0
                         type=type!=null?type:"UNKNOWN";
 75  0
                         name=mbeanServer.getDefaultDomain()+":type=CounterMonitor_"+type;
 76  
                 }
 77  0
                 JMXConsumer result=new JMXConsumer(this,proc);
 78  0
                 ourName=new ObjectName(name);
 79  0
                 counterMonitor.setNotify(true);
 80  0
                 counterMonitor.addObservedObject(observedName);
 81  0
                 counterMonitor.setObservedAttribute(attributeName);
 82  0
                 counterMonitor.setGranularityPeriod(granularityPeriod);
 83  0
                 counterMonitor.setDifferenceMode(false);
 84  0
                 counterMonitor.setInitThreshold(threshold);
 85  0
                 counterMonitor.setOffset(offset);
 86  0
                 mbeanServer.registerMBean(counterMonitor,ourName);
 87  0
                 mbeanServer.addNotificationListener(ourName,result,null,new Object());
 88  0
                 return result;
 89  
         }
 90  
 
 91  
         public boolean isSingleton(){
 92  0
                 return true;
 93  
         }
 94  
 
 95  
         public JMXExchange createExchange(Notification notification){
 96  0
                 return new JMXExchange(getContext(),notification);
 97  
         }
 98  
 
 99  
         public JMXExchange createExchange(){
 100  0
                 return new JMXExchange(getContext(),null);
 101  
         }
 102  
 
 103  
         
 104  
     public String getAttributeName(){
 105  0
             return attributeName;
 106  
     }
 107  
 
 108  
         
 109  
     public void setAttributeName(String attributeName){
 110  0
             this.attributeName=attributeName;
 111  0
     }
 112  
 
 113  
         
 114  
     public long getGranularityPeriod(){
 115  0
             return granularityPeriod;
 116  
     }
 117  
 
 118  
         
 119  
     public void setGranularityPeriod(long granularityPeriod){
 120  0
             this.granularityPeriod=granularityPeriod;
 121  0
     }
 122  
 
 123  
         
 124  
     public String getName(){
 125  0
             return name;
 126  
     }
 127  
 
 128  
         
 129  
     public void setName(String name){
 130  0
             this.name=name;
 131  0
     }
 132  
 
 133  
         
 134  
     public Number getOffset(){
 135  0
             return offset;
 136  
     }
 137  
 
 138  
         
 139  
     public void setOffset(Number offset){
 140  0
             this.offset=offset;
 141  0
     }
 142  
 
 143  
         
 144  
     public Number getThreshold(){
 145  0
             return threshold;
 146  
     }
 147  
 
 148  
         
 149  
     public void setThreshold(Number threshold){
 150  0
             this.threshold=threshold;
 151  0
     }
 152  
 
 153  
         
 154  
     public MBeanServer getMbeanServer(){
 155  0
             return mbeanServer;
 156  
     }
 157  
 
 158  
         
 159  
     public void setMbeanServer(MBeanServer mbeanServer){
 160  0
             this.mbeanServer=mbeanServer;
 161  0
     }
 162  
 }