WebSphere Extended Deployment, Version 6.0.x
             Operating Systems: AIX, HP-UX, Linux, Solaris, Windows, z/OS


Running the ObjectGrid sample application on the command line

Use this topic to run ObjectGrid-enabled applications on a Java command line and test your ObjectGrid configuration.

Before you begin

[Version 6.0.1 and later] Before you begin this task, install the mixed server environment, including the standalone ObjectGrid. See Installing a remote monitor and a stand-alone ObjectGrid from WebSphere Extended Deployment in a mixed environment for more information.

You must have a Software Development Kit (SDK) installed. You also must have access to the ObjectGrid sample applications. See Getting started with ObjectGrid for more information.

About this task

Use this task to quickly run an application with ObjectGrid enabled. For more details about using the ObjectGrid API, see the WebSphere Extended Deployment Library page for the ObjectGrid Programming Guide.

Procedure

  1. Check your Software Development Kit (SDK) version. ObjectGrid requires an IBM SDK 1.4.2 or higher. To test your Java environment before running the ObjectGrid sample application, perform the following steps:
    1. Open a command-line prompt.
    2. Type the following command:
      java -version
      If the command runs correctly, text similar to the following example displays:
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2) 
      Classic VM (build 1.4.2, J2RE 1.4.2 IBM Windows 32 build cn142-20040820 
      (JIT enabled: jitc))
      [Version 6.0.1 and later] Note: You can also run these samples using a Java 2 Platform, Standard Edition (J2SE) Version 1.3.x Software Development Kit (SDK). For more information, see ObjectGrid packaging.
      If an error displays, ensure that the SDK is installed and is in your CLASSPATH.
  2. Run the ObjectGrid sample application. The sample application illustrates a simple case that involves employees, offices, and work locations. The sample application creates an ObjectGrid instance with maps for each object type. Each map has entries inserted and manipulated to demonstrate the ObjectGrid caching function.
    1. Open a command line and navigate to the working directory. Copy the objectgrid.jar, asm.jar, and cglib.jar files from the /ObjectGrid/lib folder to a working directory. Copy the /ObjectGrid/samples/objectgridSamples.jar to the working directory.
    2. Issue the following command:
      cd working_directory
      java -cp "objectgrid.jar;objectgridSamples.jar;asm.jar;cglib.jar"
      	com.ibm.websphere.samples.objectgrid.basic.ObjectGridSample
      The system displays output that is similar to the following text. This output has been shortened for publishing purposes:
      Initializing ObjectGridSample ...
      resourcePath: META−INF/objectgrid−definition.xml
      objectgridUrl: 
      	jar:file:/C:/temp/objg/objectgridSample.jar!/
      	META−INF/objectgrid−definition.xml
      EmployeeOptimisticCallback returning version object for employee 
      	= Perry Cheng, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Hao Lee, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Ken Huang, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Jerry Anderson, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Kevin Bockhold, version = 0
      −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
      com.ibm.websphere.samples.objectgrid.basic.ObjectGridSample status:
      ivObjectGrid Name = clusterObjectGrid
      ivObjectGrid = com.ibm.ws.objectgrid.ObjectGridImpl@187b81e4
      ivSession = com.ibm.ws.objectgrid.SessionImpl@6b0d81e4
      ivEmpMap = com.ibm.ws.objectgrid.ObjectMapImpl@6b1841e4
      ivOfficeMap = com.ibm.ws.objectgrid.ObjectMapImpl@6ba081e4
      ivSiteMap = com.ibm.ws.objectgrid.ObjectMapImpl@6bae01e4
      ivCounterMap = com.ibm.ws.objectgrid.ObjectMapImpl@697b41e4
      −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
      interactiveMode = false
      Action = populateMaps
      CounterOptimisticCallback returning version object for 
      	counter name = Counter1, version = 0
      CounterOptimisticCallback returning version object for 
      	counter name = Counter2, version = 0
      CounterOptimisticCallback returning version object for 
      	counter name = Counter3, version = 0
      ivCounterMap operations committed
      ivOfficeMap operations committed
      ... ending with:
      CounterOptimisticCallback returning version object for 
      	counter name = Counter1, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Ken Huang, version = 0
      CounterOptimisticCallback returning version object for 
      	counter name = Counter2, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Perry Cheng, version = 0
      CounterOptimisticCallback returning version object for counter name = 
      	Counter3, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Jerry Anderson, version = 0
      CounterOptimisticCallback returning version object for
      	 counter name = Counter4, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Hao Lee, version = 0
      EmployeeOptimisticCallback returning version object for employee = 
      	Kevin Bockhold, version = 1
      DONE cleanup
  3. [Version 6.0.1 and later] Run the distributed ObjectGrid sample application.

    The com.ibm.websphere.samples.objectgrid.basic.ObjectGridSample program uses a local ObjectGrid instance as the data cache. All objects are cached in the local Java virtual machine (JVM). To use a distributed ObjectGrid that is deployed in an ObjectGrid cluster, use the com.ibm.websphere.samples.objectgrid.distributed.DistributedObjectGridSample program. The DistributedObjectGridSample program is included in the objectgridSamples.jar .

    1. Start an ObjectGrid cluster. For more information about starting a standalone ObjectGrid cluster to use with the distributed ObjectGrid sample, see Starting the standalone sample ObjectGrid cluster.
    2. After you have the ObjectGrid server started, you can run the distributed ObjectGrid sample application with the following command:
       java -cp "objectgrid.jar;objectgridSamples.jar;asm.jar;cglib.jar" 
      com.ibm.websphere.samples.objectgrid.distributed.DistributedObjectGridSample
    After the required ObjectGrid cluster is started, the DistributedObjectGridSample program has similar output to the ObjectGridSample program.

Results

You ran the ObjectGrid sample application on a Java command line to test the ObjectGrid functionality.

What to do next

The source for this sample is in the objectgridSamples.jar file, specifically in the com\ibm\websphere\samples\objectgrid\basic\ObjectGridSample.java and com\ibm\websphere\samples\objectgrid\distributed\DistributedObjectGridSample.java files. For more information about ObjectGrid, see ObjectGrid resources.



Related reference
ObjectGrid resources
Task topic    

Terms of Use | Feedback

Last updated: Oct 16, 2009 11:15:27 AM EDT
http://publib.boulder.ibm.com/infocenter/wxdinfo/v6r0/index.jsp?topic=/com.ibm.websphere.xd.doc/info/objectgrid/tobgstart.html