Accessing the data grid with Java APIs

After creating a data grid in XSLD, configure the eXtreme Scale client with the Liberty elasticCacheClient-1.0 feature.

Before you begin

  • Before using elasticCacheClient feature to setup an eXtreme Scale client in Liberty, you need to have a data grid running on an eXtreme server. One way to do this is to create a data grid in XSLD. As a general example of steps, see Lesson 3: Creating a data grid.
  • Locate the server.xml file in xsld_install_root/wlp/usr/servers/cs-default-<hostname>

About this task

Enabling the elasticCacheClient-1.0 feature allows web applications that run on the web server to use eXtreme Scale client APIs.

Procedure

  1. Open the server.xml file and add the elasticCacheClient-1.0 feature.
    Example
    <featureManager> 
         <feature>elasticCacheClient-1.0</feature> 
    </featureManager>
  2. Access the data grid from a Java™ API.
    An example of how to connect to a data grid that uses a Java API in a servlet:
    import com.ibm.websphere.objectgrid.ElasticCacheClientConnectionHelper;
    import com.ibm.websphere.objectgrid.ObjectGrid;
    ……
    ObjectGrid aObjGrid = null;
    aObjGrid = ElasticCacheClientConnectionHelper.connect("gridname");
    Note: Add the <wlp>\dev\ibm-api\com.ibm.ws.xs.client_1.1.jar file to compile these APIs in a development environment.
  3. Connect to a different host.
    By default, the elasticCacheClient-1.0 feature provides a default configuration to connect to localhost: 2809.
    An example on how configuration can be added to the server.xml to connect to a different host.
    <elasticCacheClient >
         <elasticCacheCatalogCluster>
               <server host="remotehost" port="20031" />
         </elasticCacheCatalogCluster>
    </elasticCacheClient>