Maps of Lists (IMap<String,IList>)

223 views
Skip to first unread message

rmpe...@gmail.com

unread,
Sep 18, 2014, 9:35:00 AM9/18/14
to haze...@googlegroups.com
Hi guys, im trying to share Maps with Lists between nodes. First i will describe my use case and maybe you have another solution than what im trying to do.

I want to hide or separate Hazelcast infrastructure from "normal" code, something like:


//this is what i have working today, i'm just working with distributed lists

public class ClassWithHazelcastInfrastructure{

    IList<Data1> myCachedList1;
    IList<Data2> myCachedList2;
    IList<DataN> myCachedListN;

   public void initCaches(){
         myCachedList1 = CacheManager.getList("list1");
         myCachedList1.addAll(findAllData1()) ;
        //same to other lists
     
   }


 public List<Data> getData1(){
        return myCachedList1;
 }

public void addData1(Data1 entry){
    myCachedList1.add(entry);
}

}

now what i want to achieve:

public class NormalClassWithoutHazelcastInfrastructure{
   
List<Data1> myNormalList1;
List<Data1> myNormalList2;
List<Data1> myNormalList3;

public void initCaches(){
         myNormalList1= CacheManager.registerList("list1", findAllData1()); 
        //same to other lists
     
   }

  public List<Data> getData1(){
        return myCachedList1;
 }

public void addData1(Data1 entry){
    CacheManager.addEntry("list1",entry);
}


}

As i dont know how many lists user will have i think of a map of lists in my cache manager:

My fisrt atempt was to have IMap<String, List> in CacheManager

but it will not work cause the entries are proxied and changes to the proxy wont reflect to other member of the topology,


my second approach was to Have IMap<String, IList> but it will not work cause IList isnt "proxyable" right?

 
registerList and addEntry would be somethink like:

public <T extends BaseEntity> List<T> registerList(String listKey, List<T> theList){
    mapList.lock(listKey);//the imap of lists
    IList ilist = instance.getList(listKey);
    ilist.addAll(theList);
    listasMap.put(listKey,ilist);
    listasMap.unlock(listKey);
    return ilist;
  }

  public <T extends BaseEntity> void addEntry(String key, T entry){
    listasMap.lock(key);
    listasMap.get(key).add(entry);
    listasMap.unlock(key);
  }

  public <T extends BaseEntity> List<T> getList(String listKey){
    return mapList.get(listKey);
  }
 


what do you think, there is a way to do what i want or it is not recommended?

thanks in advance.

Message has been deleted

john meyer

unread,
Nov 10, 2014, 11:01:26 PM11/10/14
to haze...@googlegroups.com
    IList ilist = instance.getList(listKey); will it be thread safe? because other instance can access the list by listKey
Reply all
Reply to author
Forward
0 new messages