It's all about the answers!

Ask a question

How to refresh community in RAM API


pan tianming (4765644) | asked Feb 23 '12, 9:20 p.m.
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.

10 answers



permanent link
Rogério Ramos da Silva (3352827) | answered Feb 24 '12, 7:06 a.m.
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:

But this will not get any community even if this community never deleted before.

permanent link
Manjiri Kamat (5132325) | answered Feb 27 '12, 1:24 a.m.
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.

permanent link
Manjiri Kamat (5132325) | answered Feb 27 '12, 1:30 a.m.
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);
}
}
}

permanent link
Rich Kulp (3.6k38) | answered Feb 27 '12, 1:05 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
None of your code is showing how you "deleted" the community. The problem could be there and not in the query of the community to determine if still existing.

permanent link
Manjiri Kamat (5132325) | answered Feb 28 '12, 12:50 a.m.
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?.

permanent link
Rogério Ramos da Silva (3352827) | answered Feb 28 '12, 7:28 a.m.
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:


...
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.

permanent link
Manjiri Kamat (5132325) | answered Feb 29 '12, 6:46 a.m.
Hi,

Yes you are correct.The session object is kind of desynchronized.
So deleting it through code will help us resolve the issue right?
or do you have any other suggestion to handle this issue by doing which we could still delete community from the RAM UI.

Thanks

permanent link
Rogério Ramos da Silva (3352827) | answered Feb 29 '12, 8:09 a.m.
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:


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

permanent link
Rich Kulp (3.6k38) | answered Feb 29 '12, 10:51 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
You are guaranteed on a successful return from ramSession.put(community, progress monitor) that the community is deleted.

permanent link
Manjiri Kamat (5132325) | answered Mar 01 '12, 12:19 a.m.
Hi All,

Thanks for the reply.We are considering the first suggestion given by ull to resolve the issue.

Thanks.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.