HCOLL-321 Initial commit for FilePerMap implementation - make lastVal work.

This commit is contained in:
danielshaya
2015-05-06 11:50:17 +01:00
parent ce8c92d24d
commit cc6f19557b
2 changed files with 25 additions and 9 deletions
@@ -4,18 +4,26 @@ package net.openhft.chronicle.map;
* Created by daniel on 23/04/15.
*/
public class FPMEvent {
public enum EventType {NEW, UPDATE, DELETE}
private EventType eventType;
private boolean programmatic;
private String key;
private String value;
private String lastValue;
public FPMEvent(EventType eventType, boolean programmatic, String key, String value) {
public FPMEvent(EventType eventType, boolean programmatic, String key, String lastValue, String value) {
this.eventType = eventType;
this.programmatic = programmatic;
this.key = key;
this.value = value;
this.lastValue = lastValue;
}
public String getLastValue() {
return lastValue;
}
public void setLastValue(String lastValue) {
this.lastValue = lastValue;
}
public EventType getEventType() {
@@ -57,6 +65,11 @@ public class FPMEvent {
", programmatic=" + programmatic +
", key='" + key + '\'' +
", value='" + value + '\'' +
", lastValue='" + lastValue + '\'' +
'}';
}
public enum EventType {NEW, UPDATE, DELETE}
}
@@ -270,17 +270,20 @@ public class FilePerKeyMap implements Map<String, String> {
String mapVal = getFileContents(p);
lastUpdate.put(p.toFile(), mapVal);
if(isProgrammaticUpdate(p.toFile())){
fireEvent(new FPMEvent(FPMEvent.EventType.NEW, true, mapKey,mapVal));
fireEvent(new FPMEvent(FPMEvent.EventType.NEW, true, mapKey,null, mapVal));
}else {
fireEvent(new FPMEvent(FPMEvent.EventType.NEW, false, mapKey, mapVal));
fireEvent(new FPMEvent(FPMEvent.EventType.NEW, false, mapKey, null, mapVal));
}
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
Path p = dirPath.resolve(fileName);
String lastVal = lastUpdate.get(p.toFile());
lastUpdate.remove(p.toFile());
if(isProgrammaticUpdate(p.toFile())){
fireEvent(new FPMEvent(FPMEvent.EventType.DELETE, true, mapKey, null));
fireEvent(new FPMEvent(FPMEvent.EventType.DELETE, true, mapKey, lastVal, null));
}else {
fireEvent(new FPMEvent(FPMEvent.EventType.DELETE, false, mapKey, null));
fireEvent(new FPMEvent(FPMEvent.EventType.DELETE, false, mapKey, lastVal, null));
}
} else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
Path p = dirPath.resolve(fileName);
@@ -296,9 +299,9 @@ public class FilePerKeyMap implements Map<String, String> {
}
if(isProgrammaticUpdate(p.toFile())){
fireEvent(new FPMEvent(FPMEvent.EventType.UPDATE, true, mapKey,mapVal));
fireEvent(new FPMEvent(FPMEvent.EventType.UPDATE, true, mapKey,lastVal,mapVal));
}else {
fireEvent(new FPMEvent(FPMEvent.EventType.UPDATE, false, mapKey, mapVal));
fireEvent(new FPMEvent(FPMEvent.EventType.UPDATE, false, mapKey,lastVal,mapVal));
}
}
}