IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
    
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerworks > My developerWorks >  Dashboard > WebSphere eXtreme Scale V6.1 User Guide > ... > Integrating ObjectGrid with WebSphere Application Server > Integrating ObjectGrid in a Java 2 Platform, Enterprise Edition (J2EE) environment
developerWorks
Log In   View a printable version of the current page.
Overview Connect Spaces Forums Wikis
Integrating ObjectGrid in a Java 2 Platform, Enterprise Edition (J2EE) environment
Added by kristip, last edited by bnewport on Nov 19, 2007  (view change)
Labels: 
(None)

Getting Started Examples Reference API documentation

See the WebSphere eXtreme Scale Wiki for links to eXtreme Scale Version 7.0 documentation.
If you log in with your developerWorks ID, you can leave comments and feedback for the development team.

ObjectGrid supports both servlet and Enterprise JavaBeans (EJB) programming models in the Java 2 Platform, Enterprise Edition (J2EE) environment. Use the following scenarios to enable a J2EE application with ObjectGrid.

Integrating with WebSphere

If your J2EE server is WebSphere V6.0.2 or better then you should have augmented your ND install with XD DataGrid. This enables special support for WebSphere which simplifies using ObjectGrid with ND J2EE applications. It's usually a simple matter of placing the object grid and deployment xml files in your J2EE modules and then start the application cluster. The object grids defined by your application will be automatically started within the ND cluster member JVMs.

Local ObjectGrid scenario

Procedure

  1. Define an ObjectGrid configuration. Define an ObjectGrid configuration either with XML files, through the programmatic interface, or with a combination of XML files and programmatic configuration. For more information, see Introduction to ObjectGrid configuration.
  2. Create a URL object. If the ObjectGrid configuration is in an XML file, then create a URL object that points to that XML file. You can use this URL object to create ObjectGrid instances by using the ObjectGridManager API. If the ObjectGrid configuration XML file is included in a Web archive (WAR) or Enterprise JavaBeans (EJB) Java archive (JAR) file, it is accessible as a resource to the class loader for both the Web and EJB module. For example, if the ObjectGrid configuration XML file is in the WEB−INF folder of the Web module WAR file, servlets that are in that WAR file can create a URL object with the following pattern:
    URL url =className.class.getClassLoader().
    getResource("META−INF/objectgrid−definition.xml");
    URL objectgridUrl = ObjectGridCreationServlet.class.getClassLoader().
    getResource("WEB−INF/objectgrid−definition.xml");
  3. Create or get ObjectGrid instances. Use the ObjectGridManager API to get and create ObjectGrid instances. With the ObjectGridManager API, you can create ObjectGrid instances with XML and use utility methods to quickly create a simple ObjectGrid instance. Applications must use the ObjectGridManagerFactory API to get a reference to the ObjectGridManager API. See the following example:
    import com.ibm.websphere.objectgrid.ObjectGridManager;
    import com.ibm.websphere.objectgrid.ObjectGridManagerFactory ;
    ...
    ObjectGridManager objectGridManager = ObjectGridManagerFactory.
    getObjectGridManager();
    ObjectGrid ivObjectGrid = objectGridManager.
    createObjectGrid(objectGridName, objectgridUrl, true, true);

    For more information about the ObjectGridManager API, see the ObjectGridManager interface topic.

  4. Initialize the ObjectGrid instances. Use the initialize method in the ObjectGrid interface to begin bootstrapping the ObjectGrid and Session instances. This initialize method is considered optional because the first call to the getSession method performs an implicit initialization. After this method is invoked, the ObjectGrid configuration is considered complete and is ready for runtime use. Any additional configuration method invocations, such as calling the defineMap(String mapName) method, result in an exception.
  5. Get a Session and ObjectMap instance. A session is a container for ObjectMap instances. A thread must get its own Session object to interact with the ObjectGrid core. You can think of this technique as a session that can only be used by a single thread at a time. The session is shareable across threads if it uses only one thread at a time. However, if a J2EE connection or transaction infrastructure is used, the session object is not shareable across threads. A good analogy for this object is a Java Database Connectivity (JDBC) connection to a database. An ObjectMap map is a handle to a named map. Maps must have homogenous keys and values. An ObjectMap instance can be used only by the thread that is currently associated with the session that was used to get this ObjectMap instance. Multiple threads cannot share Session and ObjectMap objects concurrently. Keywords are applied within a transaction. A transaction rollback rolls back any keyword association that is applied during this transaction.
    A programming example follows:
    Session ivSession = ivObjectGrid.getSession();
    ObjectMap ivEmpMap = ivSession.getMap("employees");
    ObjectMap ivOfficeMap = ivSession.getMap("offices");
    ObjectMap ivSiteMap = ivSession.getMap("sites");
    ObjectMap ivCounterMap = ivSession.getMap("counters");
  6. Begin a session, read or write objects, and commit or roll back the session. Map operations must be within a transactional context. Use the begin method of the Session object to begin an explicit transactional context. After the session begins, applications can start performing map operations. The most common operations include get, update, insert, and remove method calls for objects against maps. At the end of map operations, call the commit or rollback method of the Session object to either commit an explicit transactional context or roll back an explicit transactional context. A programming example follows:
    ivSession.begin();
    Integer key = new Integer(1);
    if (ivCounterMap.containsKey(key) == false) {
    	ivCounterMap.insert(key, new Counter(10));
    }
    ivSession.commit();

Distributed ObjectGrid scenario

This distributed ObjectGrid scenario differs from local ObjectGrid scenario only in the method in which the ObjectGrid instance is obtained. The following programming example demonstrates how to get a distributed ObjectGrid instance:

//Use ObjectGridManagerFactory to get the reference to the ObjectGridManager API
ObjectGridManager objectGridManager = ObjectGridManagerFactory.getObjectGridManager();

//Obtain the ClientClusterContext represents the ObjectGrid cluster from
//ObjectGridManager
//Assuming the WebSphere server also host an ObjectGrid server
//that is a member of the ObjectGrid cluster.
ClientClusterContext context = objectGridManager.connect(null, null);

//Get the ObejctGrid instance from the ObjectGridManager a specific
//ClientClusterContext.
ObjectGrid ivObjectGrid= objectGridManager.getObjectGrid(context,"objectgridName");

Results

You performed the basic programming steps for enabling a J2EE application with ObjectGrid.

What to do next

See Building ObjectGrid enabled Java 2 Platform, Enterprise Edition (J2EE) applications and Considerations for the integration of Java 2 Platform, Enterprise Edition (J2EE) applications and ObjectGrid for more information.

Wiki Disclaimer and License
© Copyright IBM Corporation 2007,2009. All Rights Reserved.


 
    About IBM Privacy Contact