How to refresh community in RAM API

We have the following case in RAM
1) Use the RAM API codes to create RAM community
2) Delete community in the RAM
3) Try to retrive this community
Result:
RAM codes still can get this community.
Our codes to get community like this:
session.getCommunity(communityname);
We add codes to remove this community in RAM session , like this:
session.remove(session.getCommunity(communityname));
RAMCommunity community = session.getCommunity(communityname);
But this will not get any community even if this community never deleted before.
So how we clean the community in session to force RAM search community again?
Thanks.
1) Use the RAM API codes to create RAM community
2) Delete community in the RAM
3) Try to retrive this community
Result:
RAM codes still can get this community.
Our codes to get community like this:
session.getCommunity(communityname);
We add codes to remove this community in RAM session , like this:
session.remove(session.getCommunity(communityname));
RAMCommunity community = session.getCommunity(communityname);
But this will not get any community even if this community never deleted before.
So how we clean the community in session to force RAM search community again?
Thanks.
10 answers

Hi Pantian,
I don't know exactly what you're doing, but follow your code logic I'm able to retrieve this information without problem. Would you like to explain all are you doing?
In my case I created a new comunity like you, so I follow your piece of code to remove* and after I've tried to fetch some communities by name.
*The remove method actually doesn't remove the community though. The help says: remove an object from the local cache, and I tried it.
After fetching the community used on remove method I got a null value, trying to fetch another and existent community I'm able to retrieve it.
So what about:
I don't know exactly what you're doing, but follow your code logic I'm able to retrieve this information without problem. Would you like to explain all are you doing?
In my case I created a new comunity like you, so I follow your piece of code to remove* and after I've tried to fetch some communities by name.
*The remove method actually doesn't remove the community though. The help says: remove an object from the local cache, and I tried it.
After fetching the community used on remove method I got a null value, trying to fetch another and existent community I'm able to retrieve it.
So what about:
But this will not get any community even if this community never deleted before.

Hi,
The scenario we had is like :
1)First created a community,this gets created in our db and also in RAM
2)Then we deleted this community from the db as well from the RAM
3)Again try adding the same community
The issue seen :
Our code that checks if this community already exists before adding it again the second time returns true even when this community got deleted in the step 2.
To handle this we added the session.remove code to remove the cached object as you said but after doing this then we encountered another issue
The second scenario is :
1)First created a community,this gets created in our db and also in RAM
2)Then we deleted this community from the db only
The issue seen :
Because of the newly added remove call before the getCommunity call,we get false when actually the community is present in the RAM
So can you please tell us on how the first scenario can be handled.
After fixing that the second should get resolved.
The scenario we had is like :
1)First created a community,this gets created in our db and also in RAM
2)Then we deleted this community from the db as well from the RAM
3)Again try adding the same community
The issue seen :
Our code that checks if this community already exists before adding it again the second time returns true even when this community got deleted in the step 2.
To handle this we added the session.remove code to remove the cached object as you said but after doing this then we encountered another issue
The second scenario is :
1)First created a community,this gets created in our db and also in RAM
2)Then we deleted this community from the db only
The issue seen :
Because of the newly added remove call before the getCommunity call,we get false when actually the community is present in the RAM
So can you please tell us on how the first scenario can be handled.
After fixing that the second should get resolved.

Our code is like :
public boolean ifExistCommunity(String communityname) throws RAMAccessException {
synchronized(this.session){
try {
LOG.debug("Removing the community from the session object");
session.remove(session.getCommunity(communityname));
LOG.debug("Removed the community from the session object");
RAMCommunity community = session.getCommunity(communityname);
if (community == null) {
return false;
}
return true;
} catch (RAMRuntimeException e) {
throw new RAMAccessException(e.getMessage(), e);
}
}
}
public boolean ifExistCommunity(String communityname) throws RAMAccessException {
synchronized(this.session){
try {
LOG.debug("Removing the community from the session object");
session.remove(session.getCommunity(communityname));
LOG.debug("Removed the community from the session object");
RAMCommunity community = session.getCommunity(communityname);
if (community == null) {
return false;
}
return true;
} catch (RAMRuntimeException e) {
throw new RAMAccessException(e.getMessage(), e);
}
}
}

Hi,
We delete the community using the RAM UI and not through the code.
So when we try adding the same community from our application again the below code returns true.
public boolean ifExistCommunity(String communityname) throws RAMAccessException {
synchronized(this.session){
try {
RAMCommunity community = session.getCommunity(communityname);
if (community == null) {
return false;
}
return true;
} catch (RAMRuntimeException e) {
throw new RAMAccessException(e.getMessage(), e);
}
}
}
So this gave us the picture that the community remains cached in the session object due to which it returns true,hence in order to handle this we modified our above code to the one shown below.
public boolean ifExistCommunity(String communityname) throws RAMAccessException {
synchronized(this.session){
try {
LOG.debug("Removing the community from the session object");
session.remove(session.getCommunity(communityname));
LOG.debug("Removed the community from the session object");
RAMCommunity community = session.getCommunity(communityname);
if (community == null) {
return false;
}
return true;
} catch (RAMRuntimeException e) {
throw new RAMAccessException(e.getMessage(), e);
}
}
}
This did resolve the issue of adding a community the second time which does not exist in the RAM.
But then the other issue we saw was that for an existing community in RAM it returns false.
Can you please give us some pointers on how session can be synchronised when we delete the community from the RAM UI?.
We delete the community using the RAM UI and not through the code.
So when we try adding the same community from our application again the below code returns true.
public boolean ifExistCommunity(String communityname) throws RAMAccessException {
synchronized(this.session){
try {
RAMCommunity community = session.getCommunity(communityname);
if (community == null) {
return false;
}
return true;
} catch (RAMRuntimeException e) {
throw new RAMAccessException(e.getMessage(), e);
}
}
}
So this gave us the picture that the community remains cached in the session object due to which it returns true,hence in order to handle this we modified our above code to the one shown below.
public boolean ifExistCommunity(String communityname) throws RAMAccessException {
synchronized(this.session){
try {
LOG.debug("Removing the community from the session object");
session.remove(session.getCommunity(communityname));
LOG.debug("Removed the community from the session object");
RAMCommunity community = session.getCommunity(communityname);
if (community == null) {
return false;
}
return true;
} catch (RAMRuntimeException e) {
throw new RAMAccessException(e.getMessage(), e);
}
}
}
This did resolve the issue of adding a community the second time which does not exist in the RAM.
But then the other issue we saw was that for an existing community in RAM it returns false.
Can you please give us some pointers on how session can be synchronised when we delete the community from the RAM UI?.

Hi,
Instead of remove a community by UI, why don't you remove it on the same piece of code?
I'm guessing you didn't think about it, so I'd like to give you my collaboration:
Removing a community by UI and then executing your code seems a desynchronized action which could be causing the mistake.
Correct me if I'm wrong.
Instead of remove a community by UI, why don't you remove it on the same piece of code?
I'm guessing you didn't think about it, so I'd like to give you my collaboration:
...
RAMSession s = new RAMSession(host, user, passwd);
RAMCommunity c = session.getCommunity(communityname);
c.setAction(RAMAction.DELETE);
s.puts(c, new NullProgressMonitor());
...
Removing a community by UI and then executing your code seems a desynchronized action which could be causing the mistake.
Correct me if I'm wrong.

To be honest I'd not realized the tests aim.
If you should to make this in a single transation, OK the example will help you, otherwise if others requirements are envolved, I need to understand better.
Looking for your scenario, I would make like this:
If you should to make this in a single transation, OK the example will help you, otherwise if others requirements are envolved, I need to understand better.
Looking for your scenario, I would make like this:
String COMM = "YourCommunity";
RAMSession s = new RAMSession(host,user,passwd);
RAMCommunity c = s.createCommunity(COMM);
/* some useful code with the created community*/
c.setAction(RAMAction.DELETE);
s.puts(c, new NullProgressMonitor());
/* any other validations here? Maybe*/
c = s.createCommunity(COMM); // at this point you should have not found any community called YourCommunity