diff --git a/.classpath b/.classpath deleted file mode 100644 index 1acdfe11ada954114aa68fce754ff012ee95853f..0000000000000000000000000000000000000000 --- a/.classpath +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/src/de/tud/kom/p2psim/impl/vehicular/caching/CooperativeCachingComponent.java b/src/de/tud/kom/p2psim/impl/vehicular/caching/CooperativeCachingComponent.java index 0277378313c7beaed035c4105eb536fa053e2d0d..724d2791c1816c833557689706c56692739959c2 100644 --- a/src/de/tud/kom/p2psim/impl/vehicular/caching/CooperativeCachingComponent.java +++ b/src/de/tud/kom/p2psim/impl/vehicular/caching/CooperativeCachingComponent.java @@ -43,60 +43,59 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute; public class CooperativeCachingComponent extends DefaultCachingComponent -implements CachingComponent, ConnectivityListener { + implements CachingComponent, ConnectivityListener { - private double _vehicularRate = 2.0; // hard-coded value; 2 vehicle per second + private double vehicularRate = 0.0; public CooperativeCachingComponent(Host pHost, CacheInvalidationStrategy pInvalidationStrategy, CacheReplacementStrategy pReplacementStrategy, CacheDecisionStrategy pDecisionStrategy) { - super(pHost, pInvalidationStrategy, pReplacementStrategy, pDecisionStrategy); + super(pHost, pInvalidationStrategy, pReplacementStrategy, + pDecisionStrategy); } @Override - public List getCacheEntries(Class pCacheEntryClass) { + public List getCacheEntries( + Class pCacheEntryClass) { if (_cache.containsKey(pCacheEntryClass)) { - - List cacheEntries = _cache.get(pCacheEntryClass); + List cacheEntries = _cache + .get(pCacheEntryClass); List results = new ArrayList<>(); + PointInformation recentPubObj = cacheEntries + .get(cacheEntries.size() - 1); + if (recentPubObj.getAttribute( + AvailableInformationAttributes.VEHICULAR_RATE) != null) { + vehicularRate = (double) recentPubObj.getAttribute( + AvailableInformationAttributes.VEHICULAR_RATE); + } + for (int i = 0; i < cacheEntries.size(); i++) { PointInformation object = cacheEntries.get(i); - long nextUpdate; - if (i + 1 < cacheEntries.size()) { - nextUpdate = cacheEntries.get(i + 1).getDetectionDate(); - } else { - nextUpdate = Time.getCurrentTime(); - } - - if (_invalidationStrategy.checkInformation(object)) { cacheEntries.remove(i--); continue; } - results.add((T) object); - - long timeDiff = (long) (Time.SECOND / _vehicularRate); - - for (long timestamp = object.getDetectionDate() + timeDiff; timestamp < nextUpdate ; timestamp += timeDiff) { - PointInformation pointInformation = object.clonePointInformation(); - pointInformation.setDetectionTime(timestamp); - results.add((T) pointInformation); + } + // add No. of virtual entry = vehicularRate + if (vehicularRate > 1.0 && cacheEntries.size() > 1) { + PointInformation virtualObj = cacheEntries + .get(cacheEntries.size() - 2).clonePointInformation(); + for (int i = 0; i < vehicularRate; i++) { + results.add(results.size() - 1, (T) virtualObj); } } - return results; } return null; } -// @Override -// public void storeCacheEntry(T pCacheEntry) { -// // Check if vehicular rate is given -// super.storeCacheEntry(pCacheEntry); -// } - + // @Override + public void storeCacheEntry(T pCacheEntry) { + super.storeCacheEntry(pCacheEntry); + } + } diff --git a/src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java b/src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java index 2fcc2b3f0e84f8a7b96a3fe8e99a7dd879064598..2abd9f194ea149cfdf532a706927a25e6fd840af 100755 --- a/src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java +++ b/src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java @@ -105,11 +105,9 @@ implements CachingComponent, ConnectivityListener { } @Override - public List getCacheEntries( - Class pCacheEntryClass) { + public List getCacheEntries(Class pCacheEntryClass) { if (_cache.containsKey(pCacheEntryClass)) { - List cacheEntries = _cache - .get(pCacheEntryClass); + List cacheEntries = _cache.get(pCacheEntryClass); List results = new ArrayList<>(); for (int i = 0; i < cacheEntries.size(); i++) {