| | {include:pageTitle=OG_HEADER} |
| | |
| | h3. Setup |
| | |
| | If you want to use ObjectGrid alone in a simple Jave 2 Platform Standard Edition (J2SE) environment, you must have two jars: ogclient.jar and cglib.jar. These jars must be placed on the classpath of your JVM. The following section demonstrates how to write a simple Hello World program in a Windows environment, using ObjectGrid in a standalone environment. Use this example to learn, experiment with, or to write a complete application. |
| | |
| | If the JVM is not an IBM JVM then please make sure the IBM ORB is present as detailed in [Using a non-IBM JDK or JRE with ObjectGrid]. |
| | |
| | h3. Simple ObjectGrid Application |
| | |
| | In a J2SE environment, use one of the createObjectGrid methods on the ObjectGridManager interface as the mechanism for creating a core ObjectGrid to run in the current process. |
| | |
| | The following code defines an entity named Person to use with the ObjectGrid: |
| | {code:title=Person.java|borderStyle=solid} |
| | import com.ibm.websphere.projector.annotations.Entity; |
| | import com.ibm.websphere.projector.annotations.Id; |
| | |
| | @Entity |
| | public class Person |
| | { |
| | @Id String ssn; |
| | String name; |
| | } |
| | {code} |
| | See the ObjectGrid [ObjectGrid API documentation] for more information on the ObjectGrid programming model found in the following application code: |
| | {code:title=HelloWorld.java|borderStyle=solid} |
| | import com.ibm.websphere.objectgrid.ObjectGrid; |
| | import com.ibm.websphere.objectgrid.ObjectGridManagerFactory; |
| | import com.ibm.websphere.objectgrid.Session; |
| | import com.ibm.websphere.objectgrid.em.EntityManager; |
| | |
| | public class HelloWorld |
| | { |
| | static public void main(String[] argv) |
| | throws Exception |
| | { |
| | // boiler plate to get a standalone grid reference |
| | ObjectGrid grid = ObjectGridManagerFactory.getObjectGridManager().createObjectGrid(); |
| | |
| | grid.registerEntities(new Class[] { Person.class }); |
| | |
| | // get a session and then an em |
| | Session sess = grid.getSession(); |
| | EntityManager em = sess.getEntityManager(); |
| | |
| | // insert a Person |
| | em.getTransaction().begin(); |
| | Person p = new Person(); |
| | p.ssn = "1232"; |
| | p.name = "Pedro Platinum"; |
| | em.persist(p); |
| | em.getTransaction().commit(); |
| | |
| | // get it back |
| | em.getTransaction().begin(); |
| | p = (Person)em.find(Person.class, "1232"); |
| | System.out.println("Person name is " + p.name); |
| | em.getTransaction().commit(); |
| | |
| | System.exit(0); |
| | } |
| | } |
| | {code} |
| | |
| | h3. Running the Simple Application |
| | |
| | From the command-line, use the following command to launch the previous application: |
| | {code:title=helloWorld.bat} |
| | java -classpath .;c:\xd61\ogclient.jar;C:\xd61\cglib.jar HelloWorld |
| | {code} |
| | This example assumes a Java 5 JVM is on the path, ogclient.jar and cglib.jar are in the directory c:\xd61, and the classes are in the current directory. |
| | |
| |  | h3. Starting and stopping a the grid container |
| | | h3. Starting and stopping an ObjectGrid container |
| | |
 |  | See [Embedded server API] |
| | | See the [Embedded server API] topic for details on how to programmatically stop and start ObjectGrid containers in the dynamic deployment topology. |
| | |
 |  | h3. Enabling FFDC in J2SE mode |
| | | h3. Enabling ObjectGrid FFDC in a non-WebSphere Application Server process |
| | |
 |  | FFDC is IBMs first failure detection technology. This creates an ffdc folder in the logs folder and writes incidents to this folder. Each unexpected exception encountered by ObjectGrid will result in an incident being created. A specific exception only creates a single incident so that the folde doesn't fill if something happens in a loop for example. FFDC is very useful for troubleshooting. |
| | The default for FFDC in J2SE (running outside a WebSphere Application Server runtime) is FFDC disabled. The properties directory of the ObjectGrid installation contains some ffdc property files. These files must be on the class path to enable ffdc support when running outside WebSphere. There are three files in the folder: |
| | * ffdcRun.properties |
| | * ffdcStart.properties |
| | * ffdcStop.properties |
| | | [First Failure Data Capture files (FFDC)|http://www.ibm.com/support/docview.wss?uid=swg21273277] is a troubleshooting tool that logs exceptions and failures to a directory in the {{[objectgridRoot|Directory conventions]/logs/ffdc}} directory. Each unique unexpected exception encountered by ObjectGrid will result in a new incident log file. A specific exception only creates a single incident so that the directory doesn't fill up if something happens in a loop for example. FFDC is very useful for troubleshooting problems |
| | |
 |  | These three files just need to be on the class path. Other approaches would be to include them in your WAR module in the WEB-INF/classes folder etc. |
| | | FFDC is disabled by default when running ObjectGrid in a non-WebSphere process (a Java SE process). To enable FFDC, add the following three files to your application's classpath: |
| | * {{[objectgridRoot|Directory conventions]/properties/ffdcRun.properties}} |
| | * {{[objectgridRoot|Directory conventions]/properties/ffdcStart.properties}} |
| | * {{[objectgridRoot|Directory conventions]/properties/ffdcStop.properties}} |
| | |
 |  | If using a non-WebSphere application server or an application framework, the properties files can be copied into an application specific directory. For example, for Java EE web modules, you can copy the three FFDC files into the {{WEB-INF/classes}} directory. |
| | |
| | h3. Additional Information |
| | |
| | * [Local ObjectGrid configuration] |
| | * [Obtaining a reference to an ObjectGrid] |
| | * [Using a non-IBM JDK or JRE with ObjectGrid] |
 | | * [First Failure Data Capture files|http://www.ibm.com/support/docview.wss?uid=swg21273277] |
| | |
| | {include:pageTitle=OG_FOOTER} |