Issue with saving multiple Maps in a single Hazelcast Instance

509 views
Skip to first unread message

Chung Jaehoon

unread,
Jan 26, 2017, 9:22:55 AM1/26/17
to Hazelcast
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.

Ali Gurbuz

unread,
Jan 26, 2017, 10:46:38 AM1/26/17
to Hazelcast
here is an example

private void test() throws ExecutionException, InterruptedException {

Config config = new Config();
    MapConfig fooMapConfig = config.getMapConfig("foo");
MapConfig barMapConfig = config.getMapConfig("bar");


MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true).setFactoryClassName(MyMapStoreFactory.class.getName());

fooMapConfig.setMapStoreConfig(mapStoreConfig);
barMapConfig.setMapStoreConfig(mapStoreConfig);

HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
}

class MyMapStoreFactory implements MapStoreFactory {

@Override
public MapLoader newMapStore(String mapName, Properties properties) {
return new MyMapStore(mapName, properties);
}
}

class MyMapStore implements MapStore {

final String mapName;

final Properties properties;

public MyMapStore(String mapName, Properties properties) {
this.mapName = mapName;
this.properties = properties;
}

@Override
public void store(Object key, Object value) {

}

@Override
public void storeAll(Map map) {

}

@Override
public void delete(Object key) {

}

@Override
public void deleteAll(Collection keys) {

}

@Override
public Object load(Object key) {
return null;
}

@Override
public Map loadAll(Collection keys) {
return null;
}

@Override
public Iterable loadAllKeys() {
return null;
}
}


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+unsubscribe@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/9d785af6-339c-422a-9d4d-9808c2d7cd63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Ali Gurbuz
Distinguished Engineer

Mahir İz Cad. No:35, Altunizade, İstanbul
a...@hazelcast.com 
+90 507 857 7815
skype: isbiroglu
@aligurbuz

Chung Jaehoon

unread,
Jan 26, 2017, 12:42:35 PM1/26/17
to Hazelcast
Thank You so much!
They work really well.

Just one more question.
What is the best way to do a left join of Maps in Hazelcast?
I reckon there is no predicate functionality for joins in Hazelcast.

Thank you

2017년 1월 26일 목요일 오후 2시 22분 55초 UTC, Chung Jaehoon 님의 말:
Reply all
Reply to author
Forward
0 new messages