<?xml version="1.0" encoding="UTF-8"?>

<!--
    Keep/Load and Save the

    1. GenericDomainEventEntry
    3. Snapshot GenericDomainEventEntry

-->

<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">


    <util:constant static-field="javax.cache.expiry.Duration.FIVE_MINUTES"
                   id="DUR_FIVE_MINUTES"/>

    <util:constant static-field="javax.cache.expiry.Duration.ONE_HOUR"
                   id="DUR_ONE_HOUR"/>


    <!-- On its Small context it should be REPLICATED and TRANSACTIONAL -->
    <bean class="org.apache.ignite.configuration.CacheConfiguration" id="AbsDomainCache" abstract="true">

        <property name="cacheMode" value="PARTITIONED"/>

        <property name="readFromBackup" value="false"/>

        <property name="readThrough" value="false"/>
        <property name="writeThrough" value="true"/>

        <property name="writeBehindEnabled" value="true"/>

        <property name="writeBehindBatchSize" value="8192"/>

        <property name="writeBehindFlushFrequency" value="4000"/>

        <property name="expiryPolicyFactory">
            <bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
                <constructor-arg type="javax.cache.expiry.Duration" ref="DUR_FIVE_MINUTES"/>
            </bean>
        </property>

        <property name="nodeFilter" ref="defNodeFilter"/>

        <property name="affinity">
            <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
                <property name="partitions" value="#{T(com.tophold.trade.kafka.KafkaIgniteConstants).BOOKER_PART}"/>
            </bean>
        </property>

    </bean>


    <bean id="GenericDomainEventEntry" parent="AbsDomainCache">

        <property name="cacheMode" value="LOCAL"/>

        <property name="name">
            <value>BookerGenericDomainEventEntry${exchanger}</value>
        </property>

        <property name="onheapCacheEnabled" value="false"/>

        <property name="cacheStoreFactory">
            <bean class="com.tophold.trade.ignite.axon.GenericDomainEventEntryJdbcStoreFactory">
                <property name="dataSourceBean" value="eventStoreDatasource"/>
            </bean>
        </property>
        <property name="dataRegionName" value="Axon_Event_Region"/>

    </bean>

    <bean id="SnapshotGenericDomainEventEntry" parent="AbsDomainCache">
        <property name="name">
            <value>BookerSnapshotGenericDomainEventEntry${exchanger}</value>
        </property>

        <property name="cacheMode" value="LOCAL"/>
        <property name="readThrough" value="true"/>
        <!--<property name="backups" value="1"/>-->

        <property name="atomicityMode" value="TRANSACTIONAL"/>

        <property name="writeBehindBatchSize" value="128"/>
        <property name="onheapCacheEnabled" value="false"/>
        <property name="writeBehindFlushFrequency" value="2000"/>
        <property name="dataRegionName" value="Axon_Event_Region"/>

        <property name="expiryPolicyFactory">
            <bean class="javax.cache.expiry.ModifiedExpiryPolicy" factory-method="factoryOf">
                <constructor-arg type="javax.cache.expiry.Duration" ref="DUR_ONE_HOUR"/>
            </bean>
        </property>

        <property name="cacheStoreFactory">
            <bean class="com.tophold.trade.ignite.axon.GenericDomainEventEntryJdbcStoreFactory">
                <property name="dataSourceBean" value="eventStoreDatasource"/>
                <property name="snapshot" value="true"/>
                <property name="batchSize" value="128"/>
            </bean>
        </property>

    </bean>

</beans>