[Java programming language only]

Configuring clients in the Spring framework

You can override client-side ObjectGrid settings with the Spring Framework.

About this task

The following example XML file shows how to build an ObjectGridConfiguration element, and use it to override some client side settings. You can create a similar configuration using programmatic configuration or by configuring the ObjectGrid descriptor XML file.

For information about how to use the ObjectGridClientBean and ObjectGridCatalogServiceDomainBean beans to support the Spring Framework Version 3.1 cache abstraction, see Configuring a Spring cache provider.

Procedure

  1. Create an XML file to configure clients with the Spring framework.
    <?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>
                  
                </bean>
                <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                  factory-method="createBackingMapConfiguration">
                    <constructor-arg type="java.lang.String" value="OrderLine" />
                      			<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. Load the XML file you created and build the ObjectGrid.
    BeanFactory beanFactory = new XmlBeanFactory(newUrlResource
    		("file:test/companyGridSpring.xml"));
    ObjectGrid companyGrid = (ObjectGrid) beanFactory.getBean("companyGrid");

    Read about the Spring framework overview for more information on creating an XML descriptor file.