Hi,
I am a new to Hazelcast and I am trying to figure out how multiple maps with different types can be stored in a single Hazelcast Instance.
For example, I want a map with type <Integer, Endpoint> and a map with type <Integer, Detectable> in a single Hazelcast instance.
At the moment, I implemented a "redundant" version does the job of storing multiple maps.
I declared two mapConfig variables, with each of it utilizing a different implementation of a MapStore.
This method works, but it has too many redundant aspects, such as having to implement a MapStore class for every Map type.
The code below is part of my main function (EndpointMap and DetectableMap implements MapStore):
<HazelcastNode.java>
public class HazelcastNode {
public static IMap<Integer, Detectable> detectableMap;
public static IMap<Integer, Endpoint> endpointMap;
public static void main(String[] args) throws ClassNotFoundException, Exception{
// Basic Hazelcast Configurations
Config config = new Config();
EndpointMap simpleStore = new EndpointMap();
DetectableMap simpleStore2 = new DetectableMap();
MapConfig mapConfig = config.getMapConfig("endpointMap");
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setImplementation(simpleStore);
mapStoreConfig.setWriteDelaySeconds(0);
mapStoreConfig.setInitialLoadMode(InitialLoadMode.EAGER);
MapConfig mapConfig2 = config.getMapConfig("detectableMap");
MapStoreConfig mapStoreConfig2 = new MapStoreConfig();
mapStoreConfig2.setImplementation(simpleStore2);
mapStoreConfig2.setWriteDelaySeconds(0);
mapStoreConfig2.setInitialLoadMode(InitialLoadMode.EAGER);
mapConfig.setMapStoreConfig(mapStoreConfig);
mapConfig2.setMapStoreConfig(mapStoreConfig2);
// Create Hazelcast instance
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
endpointMap = hz.getMap("endpointMap");
detectableMap = hz.getMap("detectableMap");
System.out.println("Map Size:" + endpointMap.size());
System.out.println("Map Size:" + detectableMap.size());
}
}
I found out about MapStoreFactory, which seems be the solution to my problem, but I don't have
Could anyone give a simple example of MapStoreFactory implementation to my problem?
Thank you.