如何通过xml在ignite服务器中创建缓存过期策略?

问题描述 投票:0回答:2

这是我的示例-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
2个回答
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>

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>
© www.soinside.com 2019 - 2024. All rights reserved.