【问题标题】:How to create cache expiry policy in ignite server by xml?如何通过 xml 在 ignite 服务器中创建缓存过期策略?
【发布时间】:2020-07-04 13:06:11
【问题描述】:

这是我的 example-default.xml,

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd">
    <bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <!-- Set to true to enable distributed class loading for examples, default is false. -->
        <property name="peerClassLoadingEnabled" value="true"/>

        <!-- Enable task execution events for examples. -->
        <property name="includeEventTypes">
            <list>
                <!--Task execution events-->
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>

                <!--Cache events-->
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
                <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
            </list>
        </property>

        <property name="CacheExpiryPolicy">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
           <property name="expiryPolicyFactory">
               <bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
                  <constructor-arg>
                      <bean class="javax.cache.expiry.Duration">
                          <constructor-arg value="MINUTES"/>
                          <constructor-arg value="5"/>
                      </bean>
                  </constructor-arg>
               </bean>
           </property>
        </bean>
        </property>

但上面给出的 Bean 属性 'CacheExpiryPolicy' 不可写或具有无效的 setter 方法。 setter 的参数类型是否与 getter 的返回类型匹配?

我该如何解决这个问题?

【问题讨论】:

    标签: java ignite


    【解决方案1】:

    我发现了一个关于这个的 apache-ignite-users 论坛问题。

    请参考这个here

    因此,根据该论坛参考,最终更新的 xml 是:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/util
            http://www.springframework.org/schema/util/spring-util.xsd">
    
        <!-- Added cache expiry policy -->
        <bean id="cacheExpiryPolicy"
            class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
            <constructor-arg>
                <bean class="javax.cache.expiry.CreatedExpiryPolicy">
                    <constructor-arg>
                        <bean class="javax.cache.expiry.Duration">
                            <constructor-arg value="MINUTES" />
                            <constructor-arg value="5" />
                        </bean>
                    </constructor-arg>
                </bean>
            </constructor-arg>
        </bean>
    
        <bean abstract="true" id="ignite.cfg"
            class="org.apache.ignite.configuration.IgniteConfiguration">
            <!-- Set to true to enable distributed class loading for examples, default 
                is false. -->
            <property name="peerClassLoadingEnabled" value="true" />
    
            <!-- Enable task execution events for examples. -->
            <property name="includeEventTypes">
                <list>
                    <!--Task execution events -->
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED" />
    
                    <!--Cache events -->
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ" />
                    <util:constant
                        static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED" />
                </list>
            </property>
    
            <!-- set the cacheConfiguration property -->
            <property name="cacheConfiguration">
                <list>
                    <bean
                        class="org.apache.ignite.configuration.CacheConfiguration">
                        <property name="name" value="default" />
                        <property name="atomicityMode" value="ATOMIC" />
                        <property name="expiryPolicyFactory">
                            <bean parent="cacheExpiryPolicy" />
                        </property>
                    </bean>
                </list>
            </property>
        </bean>
    </beans>
    

    【讨论】:

    • @JAYAPRAKASH 它应该。你必须检查。
    【解决方案2】:

    这是来自documentation的示例:

    <property name="cacheConfiguration">
                <list>
                    <bean class="org.apache.ignite.configuration.CacheConfiguration">
                        <property name="name" value="cacheWithExpiryPolicy"/>
                        <property name="expiryPolicyFactory">
                            <bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
                                <constructor-arg>
                                    <bean class="javax.cache.expiry.Duration">
                                        <constructor-arg value="MINUTES"/>
                                        <constructor-arg value="5"/>
                                    </bean>
                                </constructor-arg>
                            </bean>
                        </property>
                    </bean>
                </list>
    </property>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 2020-10-19
      • 1970-01-01
      • 2019-10-12
      • 1970-01-01
      • 2011-02-14
      • 2013-01-23
      相关资源
      最近更新 更多