/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see .
*
*/
package de.tud.kom.p2psim.impl.vehicular.caching;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.invalidation.CacheInvalidationStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.CacheReplacementStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.JamInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public class DefaultCachingComponent
implements CachingComponent, ConnectivityListener {
private Map, List> _cache = new HashMap<>();
private Map _lastColorValues = new HashMap<>();
private Host _host;
private CacheInvalidationStrategy _invalidationStrategy;
private CacheReplacementStrategy _replacementStrategy;
private CacheDecisionStrategy _decisionStrategy;
private int _minObservations = 0;
private double[] informationRatios = new double[] {1, 0.75, 0.5, 0.25, 0};
public DefaultCachingComponent(Host pHost,
CacheInvalidationStrategy pInvalidationStrategy,
CacheReplacementStrategy pReplacementStrategy,
CacheDecisionStrategy pDecisionStrategy) {
_host = pHost;
if (_host != null) {
NetInterface wifi = _host.getNetworkComponent().getByName(NetInterfaceName.WIFI);
if (wifi != null) {
wifi.addConnectivityListener(this);
} else {
NetInterface cellular = _host.getNetworkComponent().getByName(NetInterfaceName.MOBILE);
cellular.addConnectivityListener(this);
}
}
_invalidationStrategy = pInvalidationStrategy;
_replacementStrategy = pReplacementStrategy;
_decisionStrategy = pDecisionStrategy;
}
@Override
public List getDecidedCacheEntries(
Class pCacheEntryClass) {
List cacheEntries = getCacheEntries(pCacheEntryClass);
if (cacheEntries == null) {
return null;
}
Map