<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://www.springframework.org/schema/beans"
  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">
  <!--
      Alter configuration below as needed.
  -->
  <bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
    <!-- Enabling Apache Ignite Persistent Store. -->
    <property name="dataStorageConfiguration">
      <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
        <property name="defaultDataRegionConfiguration">
          <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
            <property name="persistenceEnabled" value="true"/>
            <property name="metricsEnabled" value="true"/>

            <!-- 700 GB maximum size. -->
            <property name="maxSize" value="#{ 700L * 1024 * 1024 * 1024}"/>
            <property name="checkpointPageBufferSize" value="#{ 2L * 1024 * 1024 * 1024}"/>
          </bean>
        </property>
        <property name="dataRegionConfigurations">
          <list>
              <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                <property name="name" value="Batch_Campaigns_Region"/>
                <property name="initialSize" value="#{ 500L * 1024 * 1024}"/>
                <property name="maxSize" value="#{ 30000L * 1024 * 1024}"/>
                <property name="persistenceEnabled" value="false"/>
                <property name="metricsEnabled" value="true"/>
              </bean>
              <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                <property name="name" value="SMS_Texts_Region"/>
                <property name="initialSize" value="#{ 500L * 1024 * 1024}"/>
                <property name="maxSize" value="#{ 30000L * 1024 * 1024}"/>
                <property name="persistenceEnabled" value="false"/>
                <property name="metricsEnabled" value="true"/>
              </bean>
          </list>
        </property>
        <property name="walSegmentSize" value="#{ 2000L * 1024 * 1024}"/>
        <property name="maxWalArchiveSize" value="#{ 12L * 2000 * 1024 * 1024}"/>

        <property name="checkpointFrequency" value="60000"/>
        <property name="checkpointThreads" value="20"/>
        <property name="writeThrottlingEnabled" value="False"/>

        <property name="pageSize" value="#{ 4 * 1024}"/>
      </bean>
    </property>


    <property name="communicationSpi">
      <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
        <property name="socketWriteTimeout" value="10000"/>
        <property name="messageQueueLimit" value="60000"/>
      </bean>
    </property>

    <property name="discoverySpi">
      <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
        <property name="ipFinder">
          <bean
            class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
            <property name="addresses">
              <list>
                <value>10.**.**.10</value>
                <value>10.**.**.11</value>
                <value>10.**.**.12</value>
                <value>10.**.**.13</value>
                <value>10.**.**.14</value>
                <value>10.**.**.15</value>
                <value>10.**.**.16</value>
                <value>10.**.**.17</value>
                <value>10.**.**.18</value>
                <value>10.**.**.19</value>
                <value>10.**.**.20</value>
                <value>10.**.**.21</value>
                <value>10.**.**.22</value>
                <value>10.**.**.23</value>
                <value>10.**.**.24</value>
              </list>
            </property>
          </bean>
        </property>
        <property name="networkTimeout" value="80000"/>
      </bean>
    </property>

    <property name="atomicConfiguration">
      <bean class="org.apache.ignite.configuration.AtomicConfiguration">
        <property name="cacheMode" value="REPLICATED"/>
        <property name="atomicSequenceReserveSize" value="0"/>
      </bean>
    </property>

    <!-- Enabling authentication. -->
    <property name="authenticationEnabled" value="true"/>

    <!-- Other Ignite configurations. -->
<!--
    <property name="peerClassLoadingEnabled" value="true"/>

    <property name="peerClassLoadingLocalClassPathExclude">
      <list>
        <value>ru.pele.server.config</value>
        <value>ru.pele.server.controller</value>
        <value>ru.pele.server.service</value>
        <value>ru.pele.server.util</value>
        <value>ru.pele.server.validators</value>
      </list>
    </property>
-->
    <property name="gridLogger">
      <bean class="org.apache.ignite.logger.slf4j.Slf4jLogger"/>
    </property>

    <property name="rebalanceThreadPoolSize" value="1"/>
    <property name="failureDetectionTimeout" value="60000"/>

    <property name="includeEventTypes">
      <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_EXPIRED"/>
    </property>

    <property name="serviceConfiguration">
      <list>
        <bean class="org.apache.ignite.services.ServiceConfiguration">
          <property name="name" value="TaskManagerService"/>
          <property name="maxPerNodeCount" value="1"/>
          <property name="totalCount" value="1"/>
          <property name="service">
            <ref bean="taskManagerService"/>
          </property>
        </bean>
        <bean class="org.apache.ignite.services.ServiceConfiguration">
          <property name="name" value="offlineCampaignTimeoutService"/>
          <property name="maxPerNodeCount" value="1"/>
          <property name="totalCount" value="1"/>
          <property name="service">
            <ref bean="offlineCampaignTimeoutService"/>
          </property>
        </bean>
        <bean class="org.apache.ignite.services.ServiceConfiguration">
            <property name="name" value="contactHistoryEventSender"/>
            <property name="maxPerNodeCount" value="1"/>
            <property name="totalCount" value="0"/>
            <property name="service">
                <ref bean="contactHistoryEventSender"/>
            </property>
        </bean>
      </list>
    </property>

    <property name="stripedPoolSize" value="32"/>
    <property name="serviceThreadPoolSize" value="32"/>
    <property name="queryThreadPoolSize" value="32"/>
    <property name="publicThreadPoolSize" value="32"/>
    <property name="systemThreadPoolSize" value="32"/>

    <property name="executorConfiguration">
      <list>
        <bean class="org.apache.ignite.configuration.ExecutorConfiguration">
          <property name="name" value="contactHistoryIndexCleanerThreadPool"/>
          <property name="size" value="32"/>
        </bean>
      </list>
    </property>

    <property name="transactionConfiguration">
      <bean class="org.apache.ignite.configuration.TransactionConfiguration">
        <property name="txTimeoutOnPartitionMapExchange" value="10000"/>
      </bean>
    </property>
  </bean>

  <bean id="taskManagerService" class="ru.pele.server.service.taskmanager.TaskManagerService"/>
  <bean id="offlineCampaignTimeoutService" class="ru.pele.server.service.offlinecampaign.OfflineCampaignTimeoutService"/>
  <bean id="contactHistoryEventSender" class="ru.pele.server.model.kafka.analytics.IgniteContactHistoryEventSender"/>

</beans>
