users@shoal.java.net

Re: [Shoal-Users] Proper usage of the distributed cache

From: Shreedhar Ganapathy <Shreedhar.Ganapathy_at_Sun.COM>
Date: Sun, 02 Nov 2008 08:25:15 -0800

Hi Long
Sorry for the delay in our responses. The team is attending to high
priority issues with upcoming releases of Sailfin and GlassFish.

Some comments that may help you get closer to running this successfully:
1. Are you running this test on the same machine?
2. Do you see any log output indicating that the two Shoal GMS members
are communicating?
3. The DSC instance is per group currently in GMS so you dont have to
specify groupName in each write or read op.
In your code dsc.getFromCache(this.groupName,this.nodeName,
KEY_CACHE_HEALTHMONITOR); can change to
dsc.getFromCache(this.componentName (if any, else leave it null),
this.nodeName, KEY_CACHE_HEALTHMONITOR);

4. Likewise, in dsc.addToCache(this.groupName, this.nodeName,
KEY_CACHE_HEALTHMONITOR, token); you can change to
dsc.addToCache(this.componentName (or leave it null), this.nodeName,
KEY_CACHE_HEALTHMONITOR, token);

Placing the groupName in the place where the node name is expected may
result in an overwrite to the last member who wrote the value to the DSC.

5. What is SimpleToken ? It appears to be an AtomicInteger or
AtomicLong, and gets assigned as :
token = VALUE_INSTANTIATED;
I presume VALUE_INSTANTIATED is an instance of an Atomic....

6. Upon start of the thread, your run() method would execute and end
leaving the thread to be scheduled for GC. That would be not adequate
time for the members to have shared their cache in the group. I don't
see any semantics for group membership to reach a quorum of two or more
in the run method before you start querying for state or write state.
That may be needed in your code.
You can do that by querying GroupHandle.getAllCurrentMembers().size() >=
2 so that the DSC is queried or written to only after the quorum is
established.

hth
Shreedhar




Cao, Long wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_shoal.dev.java.net
> For additional commands, e-mail: users-help_at_shoal.dev.java.net
>
>