在ehcache 3.1.2中启用JMX支持 [英] Enabling JMX Support in ehcache 3.1.2

查看:93
本文介绍了在ehcache 3.1.2中启用JMX支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用camel 2.18.1和camel-ehcache组件来构建简单的缓存.当缓存设置正常时,我发现很难使用ehcache 3.1.2(通过骆驼引入)来注册mbean.

I am using camel 2.18.1 and the camel-ehcache component to build a simple cache. While the cache setup is working okay, I am finding it difficult to register mbeans using ehcache 3.1.2 ( this is pulled in via camel).

阅读文档-尚不清楚如何通过3.x启用支持,因为API不再提供使用ManagementService注册mbean的标准方法.

Reading the documentations - it is not clear how one would enable support with 3.x as the standard way of registering mbeans using ManagementService is no longer available on the API.

文档与纯ehcache实现和JSR-107缓存实现有些混淆.

The documentation is a bit confusing with pure ehcache implementations and JSR-107 cache implementations.

尽管JSR-107 JCache实现具有打开JMX支持的选项,但连接xml配置和启动高速缓存似乎会在高速缓存启动时引发异常:

Though the JSR-107 JCache implementation have options to turn on JMX support, wiring the xml configuration and starting the cache looks to be throwing an exception on the cache startup :

Caused by: java.lang.IllegalArgumentException: Couldn't resolve Service org.ehcache.jsr107.config.Jsr107Service

我的供参考的xml配置如下: 是否有任何关于如何启用ehcache 3.x的JMX支持以及还需要哪些其他依赖项的指针?

My xml configuration for reference is below : Any pointers on how one would enable JMX support for ehcache 3.x and what additional dependencies would be required ?

<ehcache:config
        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
        xmlns:ehcache="http://www.ehcache.org/v3"
        xmlns:jcache="http://www.ehcache.org/v3/jsr107"
        xsi:schemaLocation="
        http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
        http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">

    <ehcache:service>
        <jcache:defaults jsr-107-compliant-atomics="true" enable-management="true" enable-statistics="true">
            <jcache:cache name="my-cache" template="myDefaultTemplate"/>

        </jcache:defaults>

    </ehcache:service>

    <ehcache:persistence directory="/var/cache"/>

    <ehcache:cache alias="cache-test">


        <!--
      OPTIONAL, defaults to no expiry
        Entries to the Cache can be made to expire after a given time
    -->
        <ehcache:expiry>
            <!--
              time to idle, the maximum time for an entry to remain untouched
                Entries to the Cache can be made to expire after a given time
                other options are:
                   * <ttl>, time to live;
                   * <class>, for a custom Expiry implementation; or
                   * <none>, for no expiry
            -->
            <ehcache:tti unit="minutes">2</ehcache:tti>
        </ehcache:expiry>

        <!--
            The maximal number of entries to be held in the Cache, prior to eviction starting
        -->
        <ehcache:heap unit="entries">200</ehcache:heap>


        <!--
           OPTIONAL
            Any further elements in another namespace
        -->
            <jcache:mbeans enable-statistics="true" enable-management="true" />
    </ehcache:cache>

    <!--
      OPTIONAL
        A <cache-template> defines a named template that can be used be <cache> definitions in this same file
        They have all the same property as the <cache> elements above
    -->
    <ehcache:cache-template name="myDefaultTemplate">
        <ehcache:expiry>
            <ehcache:none/>
        </ehcache:expiry>
        <!--
           OPTIONAL
            Any further elements in another namespace
        -->

    </ehcache:cache-template>


</ehcache:config>

推荐答案

很可能意味着您的CacheManager未使用JSR-107注册.如果我这样做,它会完美运行.您可以尝试做

Most likely it means that your CacheManager isn't registered using JSR-107. If I do so, it works perfectly. You can try by doing

public static void main(String[] args) throws Exception {
    ClassLoader classLoader = CheckJmx.class.getClassLoader();
    URI uri = classLoader.getResource("ehcache.xml").toURI();
    CachingProvider cachingProvider = Caching.getCachingProvider();
    try(CacheManager cm = ((CachingProvider) cachingProvider).getCacheManager(uri, classLoader)) {
        Thread.sleep(60_000);
    }
}

但是,当您未通过JSR-107注册时,Jsr107Service不可用.但是添加此服务对您毫无帮助.仅当通过JSR-107注册时,JMX MBean才可用.

However, when you are not registered through JSR-107, the Jsr107Service isn't available. But adding this service won't help you anyway. The JMX MBeans are only available when registered through JSR-107.

所以最好的选择是更改CacheManager创建代码以使用与上面类似的内容.

So you best bet is to change the CacheManager creation code to use something similar as above.

这篇关于在ehcache 3.1.2中启用JMX支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆