// check to see if either are null or not of the expected instance
// type
if (newDataElement == null || newDataElement.getValue() == null) {
resolution = Resolution.OVERRIDE;
System.out.println( String.format(
"Arbiter: Collision detected for key [%s], "
+ "Incoming element OVERRIDES", collisionKey));
} else if (existingElement == null
|| existingElement.getValue() == null) {
resolution = Resolution.KEEP;
System.out.println( String.format(
"Arbiter: Collision detected for key [%s], "
+ "Existing element is KEPT", collisionKey));
} else {
// Main branch
// UserProfile newUP = (UserProfile) newDataElement.getValue();
// UserProfile existingUP = (UserProfile) existingElement
// .getValue();
String domainForNewElement = newDataElement.getDomainName();
String domainForExistingElement = existingElement
.getDomainName();
String message = String
.format("Arbiter: Collision detected for key [%s]."
+ " Domains for existing obj: %s, for incoming obj: %s ",
collisionKey, domainForExistingElement,
domainForNewElement);
System.out.println( message);
if (ds == null) {
System.out.println(
"Arbiter: Data Source failed to initialize. Default policy - keep existing object");
return Resolution.KEEP;
}
UserProfile userProfileFromDB = retriveObjectFromSystemOfRecord(rowCollisionKey);
// Check if we really got the object
// if not - return
if (userProfileFromDB == null) {
message = String
.format("Arbiter: Cannot retrive object from the data base. Data Source is not set. Object for key [%s] has been kept as is in the grid.\n",
collisionKey);
System.out.println( message);
return Resolution.KEEP;
}
// Insert/update object in the map
try {
if (map.containsKey(rowCollisionKey)) {
map.update(rowCollisionKey, userProfileFromDB);
message = String
.format("Arbiter: Object for key [%s] retrived from DB and replaced data in the grid.\n",
collisionKey);
} else {
// this should not be happening
map.insert(rowCollisionKey, userProfileFromDB);
message = String
.format("Arbiter: WARNING: Object from db for key [%s] has been inserted in the grid.\n",