Erstellen MBean Java

Ich versuche, eine Klasse die Implementierung einer MBean-Schnittstelle, so kann ich befragen, die Eigenschaften zur Laufzeit. Die Klasse, die ich bin versucht zu befragen, ist wie folgt

public class ProfileCache implements ProfileCacheInterfaceMBean{

    private Logger logger = Logger.getLogger(ProfileCache.class);
    private ConcurrentMap<String, Profile> cache;


    public ProfileCache(ConcurrentMap<String, Profile> 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<String, Profile> getCache() {
        if(cache == null){
            cache = new ConcurrentHashMap<String, Profile>();
        }
        return cache;
    }


}

Die Schnittstelle sieht wie folgt aus

import com.vimba.profile.Profile;

public interface ProfileCacheInterfaceMBean {

    ConcurrentMap<String, Profile> getCache();

}

Und ich starten Sie den MBean wie diese

        cacheImpl = new ProfileCache(factory.createCacheFromDB());
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName profileCache = new ObjectName("org.javalobby.tnt.jmx:type=ProfileCacheInterfaceMBean");  
        mbs.registerMBean(cacheImpl, profileCache);

Aber ich bekomme immer wieder die unten Ausnahme und ich bin nicht sicher, was ich ändern muss

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)

Ich denke, potenziell es ist, weil es gibt eine Karte?

  • Vielen Dank für so einen hilfreichen Kommentar, wenn ich verstanden habe, was gemeint war, hätte ich nicht hier gepostet. Kein Zweifel, dein Sarkasmus helfen sollte, bekommen Sie ein paar mehr Punkte - gute Arbeit
  • Das war eine echte Frage. Eh, der Teil der Ausnahme, verstehst du nicht? Um zu beginnen, die mit "nicht implementiert" --> Gibt an, dass Ihre Klasse muss das interface implementieren.
  • Dies ist die Quelle meiner Verwirrung, als das tutorial, ich folgte nicht dieses interface implementieren - vielleicht sollte ich einfach gehen und rtfm
  • Die Umbenennung der Verwaltete Bean-Klasse name zu Ende "YourClasssNameMXBean" für mich gearbeitet.
InformationsquelleAutor Biscuit128 | 2014-08-14
Schreibe einen Kommentar