From cc6f19557bb958bed700c9f3728da8903adab1e3 Mon Sep 17 00:00:00 2001 From: danielshaya Date: Wed, 6 May 2015 11:50:17 +0100 Subject: [PATCH] HCOLL-321 Initial commit for FilePerMap implementation - make lastVal work. --- .../net/openhft/chronicle/map/FPMEvent.java | 19 ++++++++++++++++--- .../openhft/chronicle/map/FilePerKeyMap.java | 15 +++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/FPMEvent.java b/src/main/java/net/openhft/chronicle/map/FPMEvent.java index bf7278e83..5f63d05d5 100644 --- a/src/main/java/net/openhft/chronicle/map/FPMEvent.java +++ b/src/main/java/net/openhft/chronicle/map/FPMEvent.java @@ -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} + + } diff --git a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java index 299995227..851aa905d 100644 --- a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java +++ b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java @@ -270,17 +270,20 @@ public class FilePerKeyMap implements Map { 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 { } 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)); } } }