Product overview > Tutorials, examples, and samples > Java SE security tutorial

Java SE security tutorial - Step 1

Start servers and clients

  1. Start a catalog server named catalogServer...

    cd objectgridRoot/bin
    ./ catalogServer

  2. Launch a container server named c0... c0 -objectGridFile ../xml/SimpleApp.xml 
                        -deploymentPolicyFile ../xml/SimpleDP.xml 
                        -catalogServiceEndpoints localhost:2809 

  3. Launch the client...

    java -classpath ../lib/objectgrid.jar;../applib/secsample.jar 

  4. The output of this program is...

    The customer name for ID 0001 is fName lName

Show mapsizes of the "accounting" grid

$ cd objectgridRoot/bin

$./ -g accounting -m mapSet1 -mapSizes Connect to Catalog service at localhost:1099 *** Displaying Results for Grid - accounting, MapSet - mapSet1 *** Listing Maps for c0 Map Name: customer Partition #: 0 Map Size: 1 Shard Type: Primary Server Total: 1 Total Domain Count: 1

Stop servers

To stop container server c0. c0 -catalogServiceEndPoints localhost:2809

You will see the following message.

CWOBJ2512I: ObjectGrid server c0 stopped.

You can stop a catalog server using...

./ catalogServer -catalogServiceEndPoints localhost:2809

If you shut down the catalog server, we will see the following message.

CWOBJ2512I: ObjectGrid server catalogServer stopped. Required files

The file below is the Java class for SimpleApp.



public class SimpleApp 
    public static void main(String[] args) throws Exception 

        SimpleApp app = new SimpleApp();;

     * read and write the map 
     * @throws Exception
    protected void run(String[] args) throws Exception 
        ObjectGrid og = getObjectGrid(args);

        Session session = og.getSession();

        ObjectMap customerMap = session.getMap("customer");

        String customer = (String) customerMap.get("0001");

        if (customer == null) 
            customerMap.insert("0001", "fName lName");
        } else 
            customerMap.update("0001", "fName lName");
        customer = (String) customerMap.get("0001");

        System.out.println("The customer name for ID 0001 is " + customer);

     * Get the ObjectGrid
     * @return an ObjectGrid instance
     * @throws Exception
    protected ObjectGrid getObjectGrid(String[] args) throws Exception 
        ObjectGridManager ogManager = ObjectGridManagerFactory.getObjectGridManager();

        // Create an ObjectGrid 
        ClientClusterContext ccContext = ogManager.connect("localhost:2809", null, null);
        ObjectGrid og = ogManager.getObjectGrid(ccContext, "accounting");

        return og;



The getObjectGrid method in this class obtains an ObjectGrid, and the run method reads a record from the customer map and updates the value.

To run this sample in a distributed environment, an ObjectGrid descriptor XML file SimpleApp.xml, and a deployment XML file, SimpleDP.xml, are created. The files are featured in the following example:


<?xml version="1.0" encoding="UTF-8"?>
<objectGridConfig xmlns:xsi="" 
    xsi:schemaLocation=" ../objectGrid.xsd" 
<objectGrid name="accounting">
<backingMap name="customer" readOnly="false" copyKey="true"/>

The following XML file configures the deployment environment.


<?xml version="1.0" encoding="UTF-8"?>
<deploymentPolicy xmlns:xsi=""
    xsi:schemaLocation=" ../deploymentPolicy.xsd"

    <objectgridDeployment objectgridName="accounting">
        <mapSet name="mapSet1" numberOfPartitions="1" minSyncReplicas="0" maxSyncReplicas="2" 
            <map ref="customer"/>

This is a simple ObjectGrid configuration with one ObjectGrid instance named "accounting" and one map named "customer" (within the mapSet "mapSet1"). The SimpleDP.xml file features one map set that is configured with 1 partition and 0 minimum required replicas.

Next step of tutorial

Parent topic:

Java SE security tutorial: overview

Next topic:

Java SE security tutorial - Step 2


Search Tips   |   Advanced Search