users@shoal.java.net

Proper usage of the distributed cache

From: Cao, Long <long.cao_at_ngc.com>
Date: Mon, 27 Oct 2008 17:54:06 -0500

Hi there,

I am trying to create a simple program to utilize the distributed cache
provided by project shoal. One of the problems I am having is being able
to retrieve an object I want to share with a remote client from the
cache. My setup is having 2 shoal gms clients executing. The cache usage
code:

        class StateUpdater implements Runnable {
                    private final GroupManagementService gms;
                    private final String groupName;
                private final String nodeName;
            
                    public StateUpdater(GroupManagementService gms, String
groupName, String nodeName) {
                            this.gms = gms;
                            this.groupName = groupName;
                            this.nodeName = nodeName;
                    }
            
                /**
                 * {_at_inheritDoc}
                 */
                @Override
                public void run() {
                        DistributedStateCache dsc =
gms.getGroupHandle().getDistributedStateCache();
                        
                        try {
                                SimpleToken token = (SimpleToken)
dsc.getFromCache(this.groupName,
        
this.nodeName, KEY_CACHE_HEALTHMONITOR);
                                logger.info("value of token inside
cache: " + token);
                                
                                if (null != token) {
                                        token.increment();
                                }else {
                                        logger.severe("warning, unable
to find token!");
                                        token = VALUE_INSTANTIATED;
                                }
                                dsc.addToCache(this.groupName,
this.nodeName, KEY_CACHE_HEALTHMONITOR, token);
                        } catch (GMSException e) {
                                logger.warning(e.getLocalizedMessage());
                                e.printStackTrace();
                        }
                }
            }



I am wondering if anyone can give me a pointers as to where I went wrong
in using the code? I instantiate the 2 clients using the same groupName
value, different nodename value. One client is executed first. Another
is then executed after a while for the token to be properly placed on
the cache.


Cheers,
--Long

-
Long Cao
Software Engineer
Northrop Grumman Integrated Systems
e: long.cao_at_ngc.com