Author |
Message
|
Abhinay185127 |
Posted: Mon Aug 05, 2013 10:19 pm Post subject: Reg : Global Cache |
|
|
Acolyte
Joined: 20 May 2013 Posts: 58
|
Hi All,
I am using the following code to store date in global cache.
Code: |
try {
MbGlobalMap globalMap = MbGlobalMap.getGlobalMap();
String current = message.getRootElement().getFirstElementByPath("Path Given").getValueAsString();
String key = message.getRootElement().getFirstElementByPath("Path Given").getValueAsString();
value = (String)globalMap.get(key);
java.util.Date currentDate = formatter.parse(current);
java.util.Date valueDate = formatter.parse(value);
if (value == null|| currentDate.compareTo(valueDate)>0) {
MbGlobalMap.getGlobalMap().put(key, current);
out.propagate(assembly);
} else {
if (value.equalsIgnoreCase(current)) {
alt.propagate(assembly);
} else {
throw new MbUserException("MyClass", "throwValidation", " ", "3001", "date validation failed", null);
}
}
} catch (Throwable e) {
// Example Exception handling
MbUserException mbue = new MbUserException(this, "evaluate()", "",
"", e.toString(), null);
throw mbue;
}
} |
For the statement
Code: |
value = (String)globalMap.get(key); |
when i populate value with some random date it works. But when i retrieve since the key is not there in global cache it returns null but then throws an error.
But the reuirement is ifit is null then i have to populate the cache . Not gettinng where i am doinng wrong.[/code] |
|
Back to top |
|
 |
dogorsy |
Posted: Mon Aug 05, 2013 10:26 pm Post subject: Re: Reg : Global Cache |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
Abhinay185127 wrote: |
Hi All,
I am using the following code to store date in global cache.
Code: |
try {
MbGlobalMap globalMap = MbGlobalMap.getGlobalMap();
String current = message.getRootElement().getFirstElementByPath("Path Given").getValueAsString();
String key = message.getRootElement().getFirstElementByPath("Path Given").getValueAsString();
value = (String)globalMap.get(key);
java.util.Date currentDate = formatter.parse(current);
java.util.Date valueDate = formatter.parse(value);
if (value == null|| currentDate.compareTo(valueDate)>0) {
MbGlobalMap.getGlobalMap().put(key, current);
out.propagate(assembly);
} else {
if (value.equalsIgnoreCase(current)) {
alt.propagate(assembly);
} else {
throw new MbUserException("MyClass", "throwValidation", " ", "3001", "date validation failed", null);
}
}
} catch (Throwable e) {
// Example Exception handling
MbUserException mbue = new MbUserException(this, "evaluate()", "",
"", e.toString(), null);
throw mbue;
}
} |
For the statement
Code: |
value = (String)globalMap.get(key); |
when i populate value with some random date it works. But when i retrieve since the key is not there in global cache it returns null but then throws an error.
But the reuirement is ifit is null then i have to populate the cache . Not gettinng where i am doinng wrong.[/code] |
If your car does not start, would you post a question in this forum ? This is a java problem, so why ask in the Message Broker forum ? |
|
Back to top |
|
 |
Abhinay185127 |
Posted: Mon Aug 05, 2013 10:32 pm Post subject: |
|
|
Acolyte
Joined: 20 May 2013 Posts: 58
|
Hi
In my view i thought it is because since it is throwing an error while retrieving from global cache so it posted in WMB forum. |
|
Back to top |
|
 |
dogorsy |
Posted: Mon Aug 05, 2013 10:40 pm Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
Abhinay185127 wrote: |
Hi
In my view i thought it is because since it is throwing an error while retrieving from global cache so it posted in WMB forum. |
so, is it a message broker error or a java error ? what does the error message say ? |
|
Back to top |
|
 |
Abhinay185127 |
Posted: Mon Aug 05, 2013 11:43 pm Post subject: |
|
|
Acolyte
Joined: 20 May 2013 Posts: 58
|
It is giving a null pointer exception.
I believe this is because the key is not present inside the cache. But my understanding was that since key is not present it should return null which then can be checked but instead it throws null pointer excep.
Is this is how global cache will work. |
|
Back to top |
|
 |
iShakir |
Posted: Tue Aug 06, 2013 12:42 am Post subject: |
|
|
Apprentice
Joined: 07 Mar 2013 Posts: 47
|
Abhinay185127 wrote: |
It is giving a null pointer exception.
I believe this is because the key is not present inside the cache. But my understanding was that since key is not present it should return null which then can be checked but instead it throws null pointer excep.
Is this is how global cache will work. |
On what line are you getting the null pointer exception? Is it when you do the get, or when you call the next line to parse? |
|
Back to top |
|
 |
Abhinay185127 |
Posted: Tue Aug 06, 2013 12:51 am Post subject: |
|
|
Acolyte
Joined: 20 May 2013 Posts: 58
|
I am getting an error just before the if conndition. |
|
Back to top |
|
 |
iShakir |
Posted: Tue Aug 06, 2013 12:58 am Post subject: |
|
|
Apprentice
Joined: 07 Mar 2013 Posts: 47
|
Abhinay185127 wrote: |
I am getting an error just before the if conndition. |
So the users above are correct. You're issue is not with the global cache nor wmb, more with the formatter.parse function that can't handle null as an input.
This seems like an error condition you're going to need to handle. |
|
Back to top |
|
 |
vishnurajnr |
Posted: Tue Aug 06, 2013 1:36 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
The "value" is NULL. Hence you should check for NULL before parsing directly.
Just like
Code: |
if(value!=null){
java.util.Date valueDate = formatter.parse(value);
} |
Its JAVA Exception handling... _________________ -------
A man is great by deeds, not by birth...! |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 07, 2013 8:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Don't know which implementation of date formatter you use. Make sure it is threadsafe or use the ThreadLocal form of it.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Abhinay185127 |
Posted: Fri Aug 09, 2013 1:21 am Post subject: |
|
|
Acolyte
Joined: 20 May 2013 Posts: 58
|
Hi yes that null value was creating problem for the formatter function.
Thanks a lot.
One query is there any way thru which we can clear the entire cache at one go instaed of removing key one by one |
|
Back to top |
|
 |
iShakir |
Posted: Fri Aug 09, 2013 2:42 am Post subject: |
|
|
Apprentice
Joined: 07 Mar 2013 Posts: 47
|
|
Back to top |
|
 |
|