...
Before we can instantiate a ConsistentMap, we need to get a reference to the StorageService; you can do this by uncommented in the StorageService reference near the top of the DistributedNetworkStore class.
First, start by defining a couple fields:
Code Block |
---|
/*
* TODO Lab 5: Replace the ConcurrentMap with ConsistentMap
*/
private Map<String, Set<HostId>> networks;
private ConsistentMap<String, Set<HostId>> nets; |
Once you change the ConcurrentMap to a ConsistentMap, we will need to update the way the map is created in the activate() method. Here is how we can ask the storage service for a ConcurrentMap:we can ask the storage service for a ConcurrentMap:
Code Block |
---|
/**
* TODO Lab 5: Replace the ConcurrentHashMap with ConsistentMap
*
* You should use storageService.consistentMapBuilder(), and the
* serializer: Serializer.using(KryoNamespaces.API |
Code Block |
networks = storageService.<String, Set<HostId>>consistentMapBuilder() */ nets = storageService.<String, Set<HostId>>consistentMapBuilder() .withSerializer(Serializer.using(KryoNamespaces.API)) .withName("byon-networks") .build(); networks = nets.buildasJavaMap(); |
You will notice a few compilation errors after making this change. This is because the ConcurrentMap returns a Versioned<Value>, rather than just a Value. You should fix the compilation errors marked by Lab 5 TODOs.
...