extreme scale util class (二)

2014-11-24 08:24:25 · 作者: · 浏览: 8
ecurityConfiguration clientSecurityConfig = null;
if (csConfigFile != null) {
clientSecurityConfig = ClientSecurityConfigurationFactory.getClientSecurityConfiguration(csConfigFile);
}
ccc = ogManager.connect(connectionString, clientSecurityConfig, new File(
"objectGridClient.xml").toURI().toURL());
System.err.println(" >>> ClientClusterContext obtained, " + ccc);
System.err.println(" >>> Cluster name is " + ccc.getClusterName());
} catch (ConnectException e) {
System.out.printf("Connection error: %s\n", e.getCause());
throw new ConnectException(e);
} catch (Exception e) {
System.out.printf("\nXSInit: Exception while getting the grid: %s\n", e.getCause());
}

// Retrieve the ObjectGrid client connection and return it.
try {
grid = ogManager.getObjectGrid(ccc, gridName);
System.out.println(" >>> Grid '" + gridName + "' obtained, " + grid);

} catch (ObjectGridRuntimeException e) {
System.out
.printf("\nXSInit: Exception while accessing the grid: '%s'. Check the validity of the grid name.\n",
gridName);
}
}
} else {
System.out.println("Connection string format should be host:port[,host:port]");
}
return grid;
}

public static void createEntry(ObjectGrid grid, String mapName,
String uniqueId) throws Exception {
// Get Backing Map
BackingMap bm = grid.getMap(mapName);
if (bm == null) {
System.out.printf(
" Map '%s' does not exist on this grid. Exiting \n",
mapName);
System.exit(1);
}
// Get a session
Session sess = grid.getSession();
// Get the ObjectMap
ObjectMap map1 = null;
try {
map1 = sess.getMap(mapName);

} catch (UndefinedMapException e){
System.out.printf(
" Map '%s' does not exist on this grid. Exiting \n",
mapName);
System.exit(1);
}

UserProfile myUserProfile = null;

myUserProfile = (UserProfile) map1.get(uniqueId);

if (myUserProfile == null) {
String probeKey = uniqueId;
// UUID.randomUUID().toString();
System.out
.printf("\nPLACING UserProfile OBJECT IN THE GRID with key as follows:[%s]\n",
probeKey);
myUserProfile = getUserProfile(probeKey, 5);

map1.insert(probeKey, myUserProfile);

myUserProfile = (UserProfile) map1.get(probeKey);
if (myUserProfile == null) {
System.out.printf(
"\nCall support. Cannot allocate probe object in the following system:"
+ "\nHost/port: '%s'" + "\nGrid : '%s'"
+ "\nMap : '%s'\n", connectionString,
grid.getName(), m