ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Reg : Global Cache

Post new topic  Reply to topic
 Reg : Global Cache « View previous topic :: View next topic » 
Author Message
Abhinay185127
PostPosted: Mon Aug 05, 2013 10:19 pm    Post subject: Reg : Global Cache Reply with quote

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
View user's profile Send private message
dogorsy
PostPosted: Mon Aug 05, 2013 10:26 pm    Post subject: Re: Reg : Global Cache Reply with quote

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
View user's profile Send private message
Abhinay185127
PostPosted: Mon Aug 05, 2013 10:32 pm    Post subject: Reply with quote

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
View user's profile Send private message
dogorsy
PostPosted: Mon Aug 05, 2013 10:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Abhinay185127
PostPosted: Mon Aug 05, 2013 11:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
iShakir
PostPosted: Tue Aug 06, 2013 12:42 am    Post subject: Reply with quote

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
View user's profile Send private message
Abhinay185127
PostPosted: Tue Aug 06, 2013 12:51 am    Post subject: Reply with quote

Acolyte

Joined: 20 May 2013
Posts: 58

I am getting an error just before the if conndition.
Back to top
View user's profile Send private message
iShakir
PostPosted: Tue Aug 06, 2013 12:58 am    Post subject: Reply with quote

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
View user's profile Send private message
vishnurajnr
PostPosted: Tue Aug 06, 2013 1:36 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Wed Aug 07, 2013 8:48 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Abhinay185127
PostPosted: Fri Aug 09, 2013 1:21 am    Post subject: Reply with quote

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
View user's profile Send private message
iShakir
PostPosted: Fri Aug 09, 2013 2:42 am    Post subject: Reply with quote

Apprentice

Joined: 07 Mar 2013
Posts: 47

Abhinay185127 wrote:
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


Not via an MbGlobalMap object. You can run:

Code:
mqsicacheadmin <broker_name> -c clearGrid -m <map_name>


Alternatively, you can define an eviction policy which will programatically evict data based on last update time. The relevant docs are:

mqsicacheadmin: http://publib.boulder.ibm.com/infocenter/wmbhelp/v8r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fbn23783_.htm

eviction: http://publib.boulder.ibm.com/infocenter/wmbhelp/v8r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fbn23783_.htm[/url]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Reg : Global Cache
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.