use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.
the class PNCounterService method clearCRDTState.
@Override
public boolean clearCRDTState(Map<String, VectorClock> vectorClocks) {
boolean allCleared = true;
for (Entry<String, VectorClock> vectorClockEntry : vectorClocks.entrySet()) {
final String counterName = vectorClockEntry.getKey();
final VectorClock vectorClock = vectorClockEntry.getValue();
final PNCounterImpl counter = counters.get(counterName);
if (counter == null) {
continue;
}
if (counter.markMigrated(vectorClock)) {
counters.remove(counterName);
statsMap.remove(counterName);
} else {
allCleared = false;
}
}
return allCleared;
}
use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.
the class ReplicatedVectorClocks method getLatestReplicatedVectorClock.
/**
* Returns the vector clock map for the given {@code serviceName}.
* For each CRDT belonging to that service, the map contains the latest
* successfully replicated vector clocks to any replica.
*
* @param serviceName the CRDT service name
* @return the last successfully replicated vector clock for all CRDTs for
* the given {@code serviceName}
* @see CRDTReplicationAwareService
*/
public Map<String, VectorClock> getLatestReplicatedVectorClock(String serviceName) {
final HashMap<String, VectorClock> latestVectorClocks = new HashMap<>();
for (Entry<ReplicatedVectorClockId, Map<String, VectorClock>> clockEntry : replicatedVectorClocks.entrySet()) {
final ReplicatedVectorClockId id = clockEntry.getKey();
final Map<String, VectorClock> clock = clockEntry.getValue();
if (id.serviceName.equals(serviceName)) {
for (Entry<String, VectorClock> crdtReplicatedClocks : clock.entrySet()) {
final String crdtName = crdtReplicatedClocks.getKey();
final VectorClock vectorClock = crdtReplicatedClocks.getValue();
final VectorClock latestVectorClock = latestVectorClocks.get(crdtName);
if (latestVectorClock == null || vectorClock.isAfter(latestVectorClock)) {
latestVectorClocks.put(crdtName, vectorClock);
}
}
}
}
return latestVectorClocks;
}
Aggregations