Is there a possibility to keep a single map store

2019-07-04 17:12发布

问题:

Currently am using Hazelcast and persistence database as Hbase,

So far I have 10 maps, for each map am using a map store, So Am using 10 mapstore classes (i.e) In all the 10 classes am implementing the MapStore. It creates a complexity in maintenance.

So What I did is, I kept a generic map store and implemented the same class for all the maps, It has the ability to accept it, To make it clear, I did something like

Map1 - com.test.GenericMapStore
Map2 - com.test.GenericMapStore
Map3 - com.test.GenericMapStore
...
Map10 - com.test.GenericMapStore

It gets mapped as above,

But for the methods in store, storeAll, loadAllKeys, loadAll am able to check the instance of object and find the mapName ---- Not a good way

But for methods like delete, deleteAll, load - I dont have any clue to find the mapName,

Pls tell me like any way to use a singleMapStore for all the maps???

So I need a map store implementation where, for all methods in mapstore, I need the PARAM called mapName to be passed, So In case, If I have common Implementation, I can make use of it just by using MAP NAME param in all the methods,

Example : Store(String key, Object object, String mapName), StoreAll(Map, String mapName), delete(String key, String mapName) delete(Collections keys, String mapName) ...

If there is a way already available, Pls do let me know...

Thanks hazelcast team,,, You ppl are doing the great job... Much Apprecaiated...

Thanks and Regards, Harry

回答1:

You should be able to achieve this with a MapStoreFactory (docs). The MapStoreFactory is called with the name of the map and you can pass that name into the GenericMapStore.

In you MapStoreFactory :

public MapLoader newMapStore(mapName, props) { 
    return new GenericMapStore(mapName); 
}

then in GenericMapStore you will have the mapName for each operation.