we can delete entire data in specific region but is it possible to delete one specific key and its value in gemfire if yes then how? And if no then why?
GeodeConfiguration class
@Configuration public class GeodeConfiguration {
@SuppressWarnings("rawtypes")
@Bean
Region gemfireRegion() throws InterruptedException {
ClientCache cache = new ClientCacheFactory()
.setPdxSerializer(
new ReflectionBasedAutoSerializer(PropertiesCache
.getInstance()
.getProperty("pdxSerializerValue")))
.addPoolLocator(
PropertiesCache.getInstance().getProperty("hostname"),
10334).create();
Region<String, String> region = cache
.<String, String> createClientRegionFactory(
ClientRegionShortcut.CACHING_PROXY)
.setEntryTimeToLive(new ExpirationAttributes(50))
.create(PropertiesCache.getInstance().getProperty("region"));
return region;
}
}
Mobilecontroller class
@Controller public class MobileController {
@Autowired
Operations operations;
Msg msg = new Msg();
final static Logger logger = Logger.getLogger(MobileController.class);
@RequestMapping(value = "/mobile", method = RequestMethod.POST)
public void dataFromEs(@RequestParam("name") String name,
@RequestParam("message") String message,
@RequestParam("mobileNo") String[] mobileNo) throws IOException,
JSONException {
JSONObject obj = new JSONObject();
obj.put("userName", name);
obj.put("message", message);
JSONObject mainObj = new JSONObject();
JSONArray jsonArray = new JSONArray();
for (int counter = 0; counter < mobileNo.length; counter++) {
// 1st object
JSONObject list1 = new JSONObject();
list1.put("mobilenumber", mobileNo[counter]);
jsonArray.put(list1);
}
mainObj.put("data", obj);
obj.put("mobileno", jsonArray);
logger.info("jsonString----------->: " + jsonArray);
logger.info(mainObj);
msg.setKey(name);
msg.setValue(mainObj.toString());
operations.saveMessageData(msg);
sendMSG(name);
}
public void sendMSG(String name) throws ClientProtocolException,
IOException, JSONException {
String objMobileNo;
String objMessage;
String objUserName;
String userStatus;
JSONObject root = new JSONObject(operations.getDataValue(name));
JSONObject jsonObject = root.getJSONObject("data");
objUserName = (String) jsonObject.get("userName");
objMessage = (String) jsonObject.get("message");
logger.info("UserName ----> " + objUserName);
logger.info("Message sent ---> " + objMessage);
JSONArray mobArray = jsonObject.getJSONArray("mobileno");
// now get the first element:
for (int count = 0; count < mobArray.length(); count++) {
objMobileNo = (String) mobArray.getJSONObject(count).get(
"mobilenumber");
logger.info("Mobile number ----> " + objMobileNo);
JSONObject obj = new JSONObject();
JSONObject objDraftOne = new JSONObject();
JSONObject objDraftTwo = new JSONObject();
JSONObject jsonObjectToSave = new JSONObject();
JSONObject jsonObjectToSaveDraft = new JSONObject();
JSONArray jsonArray = new JSONArray();
objDraftTwo.put("mobilenumber", objMobileNo);
jsonArray.put(objDraftTwo);
objDraftOne.put("mobileno", jsonArray);
objDraftOne.put("userName", objUserName);
objDraftOne.put("message", objMessage);
jsonObjectToSaveDraft.put("data", objDraftOne);
obj.put("userName", objUserName);
obj.put("message", objMessage);
obj.put("mobilenumber", objMobileNo);
jsonObjectToSave.put("data", obj);
HttpClient client = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(
"https://xyzotp.bdt.xyz.com/sendSMS");
StringEntity params = new StringEntity(jsonObjectToSave.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
HttpResponse response = client.execute(request);
String responseAsString = EntityUtils
.toString(response.getEntity());
JSONObject responseObjectStatus = new JSONObject(responseAsString);
userStatus = (String) responseObjectStatus.get("message");
logger.info("Message Status: " + userStatus);
if (!userStatus.equals("Message sent successfully")) {
logger.info(jsonObjectToSaveDraft);
}
}
}
}
In the above code the name is the key which is going to change every time and we want to remove the key and its value which is passed