Coverage Report - org.mule.module.management.agent.JmxAgentConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
JmxAgentConfigurer
0%
0/56
0%
0/12
1.333
 
 1  
 /*
 2  
  * $Id: JmxAgentConfigurer.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.module.management.agent;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.context.MuleContextAware;
 14  
 import org.mule.api.registry.RegistrationException;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.commons.logging.LogFactory;
 18  
 
 19  
 import java.util.Collections;
 20  
 import java.util.HashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.management.MBeanServer;
 24  
 import javax.management.remote.rmi.RMIConnectorServer;
 25  
 
 26  
 /**
 27  
  * Mule now binds to a platform mbeanserver by default and jmx agent is always registered via a
 28  
  * bootstrap process. Thus a namespace handler creates this configurer class instead which propagates
 29  
  * user settings to a jmx agent in the registry (instead of trying to register a duplicate jmx agent).
 30  
  */
 31  
 public class JmxAgentConfigurer implements MuleContextAware
 32  
 {
 33  
 
 34  
     // populated with values below in a static initializer
 35  
     public static final Map DEFAULT_CONNECTOR_SERVER_PROPERTIES;
 36  
 
 37  
     /**
 38  
      * Logger used by this class
 39  
      */
 40  0
     protected static final Log logger = LogFactory.getLog(JmxAgentConfigurer.class);
 41  
 
 42  
     protected MuleContext muleContext;
 43  
 
 44  
     /**
 45  
      * Should MBeanServer be discovered.
 46  
      */
 47  0
     protected boolean locateServer = true;
 48  
     // don't create mbean server by default, use a platform mbean server
 49  0
     private boolean createServer = false;
 50  
     private String connectorServerUrl;
 51  
     private MBeanServer mBeanServer;
 52  0
     private Map connectorServerProperties = null;
 53  0
     private boolean enableStatistics = true;
 54  0
     private boolean createRmiRegistry = true;
 55  
 
 56  
     /**
 57  
      * Username/password combinations for JMX Remoting authentication.
 58  
      */
 59  0
     private Map credentials = new HashMap();
 60  
 
 61  
     static
 62  
     {
 63  0
         Map props = new HashMap(1);
 64  0
         props.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true");
 65  0
         DEFAULT_CONNECTOR_SERVER_PROPERTIES = Collections.unmodifiableMap(props);
 66  0
     }
 67  
 
 68  
     public JmxAgentConfigurer()
 69  0
     {
 70  0
         connectorServerProperties = new HashMap(DEFAULT_CONNECTOR_SERVER_PROPERTIES);
 71  0
     }
 72  
 
 73  
     /**
 74  
      * @return Returns the createServer.
 75  
      */
 76  
     public boolean isCreateServer()
 77  
     {
 78  0
         return createServer;
 79  
     }
 80  
 
 81  
     /**
 82  
      * @param createServer The createServer to set.
 83  
      */
 84  
     public void setCreateServer(boolean createServer)
 85  
     {
 86  0
         this.createServer = createServer;
 87  0
     }
 88  
 
 89  
     /**
 90  
      * @return Returns the locateServer.
 91  
      */
 92  
     public boolean isLocateServer()
 93  
     {
 94  0
         return locateServer;
 95  
     }
 96  
 
 97  
     /**
 98  
      * @param locateServer The locateServer to set.
 99  
      */
 100  
     public void setLocateServer(boolean locateServer)
 101  
     {
 102  0
         this.locateServer = locateServer;
 103  0
     }
 104  
 
 105  
     /**
 106  
      * @return Returns the connectorServerUrl.
 107  
      */
 108  
     public String getConnectorServerUrl()
 109  
     {
 110  0
         return connectorServerUrl;
 111  
     }
 112  
 
 113  
     /**
 114  
      * @param connectorServerUrl The connectorServerUrl to set.
 115  
      */
 116  
     public void setConnectorServerUrl(String connectorServerUrl)
 117  
     {
 118  0
         this.connectorServerUrl = connectorServerUrl;
 119  0
     }
 120  
 
 121  
     /**
 122  
      * @return Returns the enableStatistics.
 123  
      */
 124  
     public boolean isEnableStatistics()
 125  
     {
 126  0
         return enableStatistics;
 127  
     }
 128  
 
 129  
     /**
 130  
      * @param enableStatistics The enableStatistics to set.
 131  
      */
 132  
     public void setEnableStatistics(boolean enableStatistics)
 133  
     {
 134  0
         this.enableStatistics = enableStatistics;
 135  0
     }
 136  
 
 137  
     /**
 138  
      * @return Returns the mBeanServer.
 139  
      */
 140  
     public MBeanServer getMBeanServer()
 141  
     {
 142  0
         return mBeanServer;
 143  
     }
 144  
 
 145  
     /**
 146  
      * @param mBeanServer The mBeanServer to set.
 147  
      */
 148  
     public void setMBeanServer(MBeanServer mBeanServer)
 149  
     {
 150  0
         this.mBeanServer = mBeanServer;
 151  0
     }
 152  
 
 153  
     /**
 154  
      * Getter for property 'connectorServerProperties'.
 155  
      *
 156  
      * @return Value for property 'connectorServerProperties'.
 157  
      */
 158  
     public Map getConnectorServerProperties()
 159  
     {
 160  0
         return connectorServerProperties;
 161  
     }
 162  
 
 163  
     /**
 164  
      * Setter for property 'connectorServerProperties'. Set to {@code null} to use defaults ({@link
 165  
      * #DEFAULT_CONNECTOR_SERVER_PROPERTIES}). Pass in an empty map to use no parameters. Passing a non-empty map will
 166  
      * replace defaults.
 167  
      *
 168  
      * @param connectorServerProperties Value to set for property 'connectorServerProperties'.
 169  
      */
 170  
     public void setConnectorServerProperties(Map connectorServerProperties)
 171  
     {
 172  0
         this.connectorServerProperties = connectorServerProperties;
 173  0
     }
 174  
 
 175  
 
 176  
     /**
 177  
      * Setter for property 'credentials'.
 178  
      *
 179  
      * @param newCredentials Value to set for property 'credentials'.
 180  
      */
 181  
     public void setCredentials(final Map newCredentials)
 182  
     {
 183  0
         this.credentials.clear();
 184  0
         if (newCredentials != null && !newCredentials.isEmpty())
 185  
         {
 186  0
             this.credentials.putAll(newCredentials);
 187  
         }
 188  0
     }
 189  
 
 190  
     public boolean isCreateRmiRegistry()
 191  
     {
 192  0
         return createRmiRegistry;
 193  
     }
 194  
 
 195  
     public void setCreateRmiRegistry(boolean createRmiRegistry)
 196  
     {
 197  0
         this.createRmiRegistry = createRmiRegistry;
 198  0
     }
 199  
 
 200  
     public void setMuleContext(MuleContext context)
 201  
     {
 202  0
         this.muleContext = context;
 203  
         try
 204  
         {
 205  
             // by the time mule context is injected, other attributes will have been set already
 206  0
             JmxAgent agent = muleContext.getRegistry().lookupObject(JmxAgent.class);
 207  
             // in case it is injected, otherwise will follow the init logic
 208  0
             if (getMBeanServer() != null)
 209  
             {
 210  0
                 agent.setMBeanServer(getMBeanServer());
 211  
             }
 212  0
             if (getConnectorServerUrl() != null)
 213  
             {
 214  0
                 agent.setConnectorServerUrl(getConnectorServerUrl());
 215  
             }
 216  0
             if (getConnectorServerProperties() != null && !getConnectorServerProperties().isEmpty())
 217  
             {
 218  0
                 agent.setConnectorServerProperties(getConnectorServerProperties());
 219  
             }
 220  
             // these can be copied as is
 221  0
             agent.setCreateServer(isCreateServer());
 222  0
             agent.setLocateServer(isLocateServer());
 223  0
             agent.setEnableStatistics(isEnableStatistics());
 224  0
             agent.setCreateRmiRegistry(isCreateRmiRegistry());
 225  
         }
 226  0
         catch (RegistrationException e)
 227  
         {
 228  0
             throw new RuntimeException(e);
 229  0
         }
 230  0
     }
 231  
 
 232  
     public void setName(String name)
 233  
     {
 234  
         // ignore the name, spring wants it
 235  0
     }
 236  
 }