title: Creating MBean in Java
body: <p>I am trying to make a class implement an MBean Interface so I can interrogate the properties at runtime. The class I am trying to interrogate is as follows</p>
  
  <pre><code>public class ProfileCache implements ProfileCacheInterfaceMBean{
  
      private Logger logger = Logger.getLogger(ProfileCache.class);
      private ConcurrentMap&lt;String, Profile&gt; cache;
  
  
      public ProfileCache(ConcurrentMap&lt;String, Profile&gt; cache){
          this.cache = cache;     
      }
  
      /**
       * Update the cache entry for a given user id
       * @param userid the user id to update for 
       * @param profile the new profile to store
       * @return true if the cache update
       */
      public boolean updateCache(String userid, Profile profile) {
          if (cache == null || cache.size() == 0) {
              throw new RuntimeException("Unable to update the cache");
          }
          if (cache.containsKey(userid)) {
              if (profile != null) {
                  cache.put(userid, profile);
                  logger.info("Updated the cache for user: "
                              + userid + "  profile: " + profile);
                  return true;
              }
          }
          return false;
      }
  
      @Override
      public ConcurrentMap&lt;String, Profile&gt; getCache() {
          if(cache == null){
              cache = new ConcurrentHashMap&lt;String, Profile&gt;();
          }
          return cache;
      }
  
  
  }
  </code></pre>
  
  <p>The interface looks like this</p>
  
  <pre><code>import com.vimba.profile.Profile;
  
  public interface ProfileCacheInterfaceMBean {
  
      ConcurrentMap&lt;String, Profile&gt; getCache();
  
  }
  </code></pre>
  
  <p>And i start the MBean like this</p>
  
  <pre><code>        cacheImpl = new ProfileCache(factory.createCacheFromDB());
          MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
          ObjectName profileCache = new ObjectName("org.javalobby.tnt.jmx:type=ProfileCacheInterfaceMBean");  
          mbs.registerMBean(cacheImpl, profileCache);
  </code></pre>
  
  <p>However i keep getting the below exception and I am not sure what I need to change</p>
  
  <pre><code>javax.management.NotCompliantMBeanException: MBean class com.vimba.cache.ProfileCache does not implement DynamicMBean, and neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class com.vimba.cache.ProfileCache is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: com.vimba.cache.ProfileCache: Class com.vimba.cache.ProfileCache is not a JMX compliant MXBean)
  </code></pre>
  
  <p>I think potentially it's because it returns a Map?</p>