Configuration des clients dans l'infrastructure Spring

Vous pouvez remplacer les paramètres ObjectGrid côté client avec l'infrastructure Spring.

Pourquoi et quand exécuter cette tâche

L'exemple de fichier XML suivant montre comment générer un élément ObjectGridConfiguration et l'utiliser pour remplacer certains paramètres côté client. Vous pouvez créer une configuration similaire en utilisant la configuration à l'aide d'un programme ou en configurant le fichier XML de descripteur d'ObjectGrid.

[Version 8.5 and later] Pour plus d'informations sur la façon d'utiliser les beans ObjectGridClientBean et ObjectGridCatalogServiceDomainBean pour la prise en charge de l'abstraction de cache Spring Framework version 3.1, voir Configuration d'un fournisseur de cache Spring.

Procédure

  1. Créez un fichier XML pour configurer des clients avec l'infrastructure Spring.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    		"http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
      <bean id="companyGrid" factory-bean="manager" factory-method="getObjectGrid"
        singleton="true">
        <constructor-arg type="com.ibm.websphere.objectgrid.ClientClusterContext">
          <ref bean="client" />
        </constructor-arg>
        <constructor-arg type="java.lang.String" value="CompanyGrid" />
    </bean>
    
      <bean id="manager" class="com.ibm.websphere.objectgrid.ObjectGridManagerFactory"
        factory-method="getObjectGridManager" singleton="true">
        <property name="overrideObjectGridConfigurations">
          <map>
            <entry key="DefaultDomain">
              <list>
                <ref bean="ogConfig" />
              </list>
            </entry>
          </map>
        </property>
      </bean>
    
      <bean id="ogConfig"
        class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
        factory-method="createObjectGridConfiguration">
        <constructor-arg type="java.lang.String">
          <value>CompanyGrid</value>
        </constructor-arg>
        <property name="plugins">
          <list>
    	  <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
              factory-method="createPlugin">
              <constructor-arg type="com.ibm.websphere.objectgrid.config.PluginType"
                value="TRANSACTION_CALLBACK" />
              <constructor-arg type="java.lang.String"
                value="com.company.MyClientTxCallback" />
            </bean>
            <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
              factory-method="createPlugin">
              <constructor-arg type="com.ibm.websphere.objectgrid.config.PluginType"
                value="OBJECTGRID_EVENT_LISTENER" />
              <constructor-arg type="java.lang.String" value="" />
            </bean>
          </list>
    	</property>
          <property name="backingMapConfigurations">
            <list>
    	    <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                factory-method="createBackingMapConfiguration">
                <constructor-arg type="java.lang.String" value="Customer" />
                  <property name="plugins">
    		    <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                      factory-method="createPlugin">
                      <constructor-arg type="com.ibm.websphere.objectgrid.config.PluginType"
    			  value="EVICTOR" />
    			<constructor-arg type="java.lang.String"
                        value="com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor" />
                    </bean>
                  </property>
                  <property name="numberOfBuckets" value="1429" />
                </bean>
                <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                  factory-method="createBackingMapConfiguration">
                    <constructor-arg type="java.lang.String" value="OrderLine" />
                      <property name="numberOfBuckets" value="701" />
    			<property name="timeToLive" value="800" />
    			<property name="ttlEvictorType">
                        <value type="com.ibm.websphere.objectgrid.
    											TTLType">LAST_ACCESS_TIME</value>
    			</property>
                </bean>
              </list>
            </property>
          </bean>
    
          <bean id="client" factory-bean="manager" factory-method="connect"
            singleton="true">
            <constructor-arg type="java.lang.String">
    	    <value>localhost:2809</value>
            </constructor-arg>
    	  <constructor-arg
              type="com.ibm.websphere.objectgrid.security.
    						config.ClientSecurityConfiguration">
              <null />
            </constructor-arg>
    	  <constructor-arg type="java.net.URL">
    	    <null />
            </constructor-arg>
          </bean>
    </beans>
  2. Chargez le fichier XML que vous avez créé et générez l'ObjectGrid.
    BeanFactory beanFactory = new XmlBeanFactory(newUrlResource
    		("file:test/companyGridSpring.xml"));
    ObjectGrid companyGrid = (ObjectGrid) beanFactory.getBean("companyGrid");

    Voir Présentation de l'infrastructure Spring pour plus d'informations sur la création d'un fichier descripteur XML.