Map Iterator

  Search Here
Searching XAP 6.0 Documentation

                                               

Summary: Used to get objects matching multiple templates in one call.

Overview

There are scenarios where the IMap.get operation that returns a single Entry object does not fit and there is a need to return a collection of Entries from the cache.
In such a case, you may use the IMap.values() or IMap.entrySet() methods. Still, these methods are not scalable to cope with a large number of objects, return all cache instances without ability to filter objects based on their keys, and do not allow getting objects that might written into the cache after the IMap.values() or IMap.entrySet() call.

The GSIterator constructs a match set (a collection of Entry instances) that incrementally returns the necessary Entries. The GSIterator constructs a proxy object that can be used to access a match set created by a space. The match set will initially contain some population of entries specified by the operation that created it. These Entries can be retrieved by calling the next method. A successful call to next will remove the returned Entry from the match set. Match sets can end up in one of two terminal states: exhausted or invalidated.

For more details on the GSIterator, refet to the [JavaSpaces API section, GSIterator.].

Example

In the following example code, a sample application puts several objects into a cache, defines a template, and then uses the GSIterator to retrieve the cached objects.

IMap cache = (IMap)CacheFinder.find("jini://*/*/mySpace");                
say("Cache has " + cache.size() + " values");                
IJSpace space = cache.getMasterSpace();                      
say("Clean map-cache...");                                   
space.clean();                                               
                                                              
say("Values are addes to the cache...");                     
cache.put("Key1", "value_1");                                
cache.put("Key2", "value_2");                                
cache.put("Key3", "value_3");                                
say("Cache has " + cache.size()+" values");                  
                                                             
Collection templates = new ArrayList();                      
Envelope ee = new Envelope();                                
templates.add(ee);                                           
                                                             
GSIterator gsIterator = new GSIterator(space, // space ref.  
        templates,     // templates collection               
        100,         // buffer "window" size                 
        true,         // with history true                   
        1000);        // lease  10 seconds                   
                                                              
say("Do the Iterator loop...");                              
while (gsIterator.hasNext()) {                               
    ExternalEntry entry = (ExternalEntry)gsIterator.next();  
    Object key = Envelope.getKey(entry);                     
    Object value = Envelope.getValue(entry);                 
    say("Map-Key: " + key + " Value: " + value);             
}


GigaSpaces 6.0 Documentation Contents (Current Page in Bold)

    Java

    C++

    .NET

    Middleware Capabilities

    Configuration and Management

Add GigaSpaces wiki search to your browser search engines!
(works on Firefox 2 and Internet Explorer 7)

Labels

 
(None)