Commit 7e67d8f9 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

First working version of monitoring

parent 96cb29ed
...@@ -22,11 +22,15 @@ ...@@ -22,11 +22,15 @@
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction; package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent; import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
...@@ -35,7 +39,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties; ...@@ -35,7 +39,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle; import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSRequest; import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.impl.NoRoadSegmentPrediction;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionSiSType; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionSiSType;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
...@@ -45,19 +48,24 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType; ...@@ -45,19 +48,24 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
* @version 1.0 at 03.01.2018 * @version 1.0 at 03.01.2018
* *
*/ */
public class DefaultSiSPredictionManager implements SiSPredictionManager { public class DefaultSiSPredictionManager implements SiSPredictionManager, EventHandler {
private Map<SiSType<? extends Object>, Prediction<? extends Object>> availablePredictions = new HashMap<>(); private Map<SiSType<? extends Object>, Prediction<? extends Object>> availablePredictions = new HashMap<>();
private Map<SiSType<?extends Object>,
Map<INodeID, SiSValueContainer<? extends Object>>> availableData = new HashMap<>();
private Host host; private Host host;
private SiSComponent _siSComponent; private SiSComponent _siSComponent;
public DefaultSiSPredictionManager(Host host) { public DefaultSiSPredictionManager(Host host, List<Prediction<? extends Object>> pPredictions) {
this.host = host; this.host = host;
Prediction<? extends Object> prediction = new NoRoadSegmentPrediction(); for (Prediction<? extends Object> prediction : pPredictions) {
availablePredictions.put(prediction.getBasicSiSType(), prediction); availablePredictions.put(prediction.getBasicSiSType(), prediction);
}
} }
@Override @Override
...@@ -72,7 +80,11 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager { ...@@ -72,7 +80,11 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
_siSComponent.provide().nodeState(predictionSysType, _siSComponent.provide().nodeState(predictionSysType,
new PredictionSiSDataCallback<>(predictionSysType)); new PredictionSiSDataCallback<>(predictionSysType));
} }
availableData.put(entry.getKey(), new HashMap<>());
} }
Event.scheduleWithDelay(Time.SECOND, this, null, 0);
} catch (ComponentNotAvailableException e) { } catch (ComponentNotAvailableException e) {
} }
} }
...@@ -97,6 +109,16 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager { ...@@ -97,6 +109,16 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
throw new InformationNotAvailableException(); throw new InformationNotAvailableException();
} }
@Override
public <T> PredictionContainer<T> predict(INodeID pNodeID, PredictionSiSType<T> pType, T pValue, long pTime,
long pPredictionTimestamp) throws InformationNotAvailableException {
if (availablePredictions.containsKey(pType.getOriginalSiSType())) {
Prediction prediction = availablePredictions.get(pType.getOriginalSiSType());
return prediction.predict(pNodeID, pValue, pTime, pPredictionTimestamp);
}
throw new InformationNotAvailableException();
}
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private class PredictionSiSDataCallback<T extends Object> implements SiSDataCallback<PredictionContainer> { private class PredictionSiSDataCallback<T extends Object> implements SiSDataCallback<PredictionContainer> {
...@@ -106,17 +128,22 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager { ...@@ -106,17 +128,22 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
_sisType = sisType; _sisType = sisType;
} }
@SuppressWarnings("unchecked")
@Override @Override
public PredictionContainer<T> getValue(INodeID pNodeID, SiSProviderHandle pProviderHandle) public PredictionContainer<T> getValue(INodeID pNodeID, SiSProviderHandle pProviderHandle)
throws InformationNotAvailableException { throws InformationNotAvailableException {
T observation = _siSComponent.get().localObservationOf(pNodeID, _sisType.getOriginalSiSType(), SiSValueContainer<? extends Object> siSValueContainer = availableData.get(_sisType.getOriginalSiSType())
SiSRequest.NONE); .get(pNodeID);
long timestamp = _siSComponent.get()
.localObservationOfInfo(pNodeID, _sisType.getOriginalSiSType(), SiSRequest.NONE) if (siSValueContainer != null) {
.getLastUpdateTimestamp(); T observation = (T) siSValueContainer.getValue();
long timestamp = siSValueContainer.getTimestamp();
return predict(pNodeID, _sisType, observation, timestamp); return predict(pNodeID, _sisType, observation, timestamp);
} else {
throw new InformationNotAvailableException();
}
} }
@Override @Override
...@@ -130,5 +157,61 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager { ...@@ -130,5 +157,61 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
} }
} }
@Override
public void updateValue(SiSType<Object> type, INodeID id, Object value, long timestamp) {
if (availableData.containsKey(type)) {
availableData.get(type).put(id, new SiSValueContainer<Object>(value, timestamp));
}
}
@Override
public void eventOccurred(Object pContent, int pType) {
for (SiSType<? extends Object> type : availableData.keySet()) {
Map<INodeID, SiSValueContainer<? extends Object>> nodeValues = availableData.get(type);
Set<INodeID> observedNodes = _siSComponent.get().getObservedNodes(type, SiSRequest.NONE);
for (INodeID nodeID : observedNodes) {
try {
Object measurement = _siSComponent.get().localObservationOf(nodeID, type, SiSRequest.NONE);
if (nodeValues.containsKey(nodeID)) {
if (!nodeValues.get(nodeID).getValue().equals(measurement)) {
nodeValues.put(nodeID, new SiSValueContainer<Object>(measurement, Time.getCurrentTime()));
}
} else {
nodeValues.put(nodeID, new SiSValueContainer<Object>(measurement, Time.getCurrentTime()));
}
} catch (InformationNotAvailableException e) {
}
}
}
Event.scheduleWithDelay(Time.SECOND, this, null, 0);
}
private class SiSValueContainer<T extends Object> {
private T value;
private long timestamp;
public SiSValueContainer(T pValue, long pTimestamp) {
value = pValue;
timestamp = pTimestamp;
}
public T getValue() {
return value;
}
public long getTimestamp() {
return timestamp;
}
/**
* @param pTimestamp
* the timestamp to set
*/
public void setTimestamp(long pTimestamp) {
timestamp = pTimestamp;
}
}
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction; package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
...@@ -35,10 +36,31 @@ public interface Prediction<T extends Object> { ...@@ -35,10 +36,31 @@ public interface Prediction<T extends Object> {
/** /**
* @param pNodeID * @param pNodeID
* @param pObservation * @param pObservation
* @param pTimestamp * @param pObservationTimestamp
* @return * @return
*/ */
PredictionContainer<T> predict(INodeID pNodeID, T pObservation, long pTimestamp); default PredictionContainer<T> predict(INodeID pNodeID, T pObservation, long pObservationTimestamp) {
return predict(pNodeID, pObservation, pObservationTimestamp, Time.getCurrentTime());
}
PredictionContainer<T> predict(INodeID pNodeID, T pObservation, long pObservationTimestamp,
long pPredictionTimestamp);
default PredictionContainer<T> predict(INodeID pNodeID) {
return predict(pNodeID, Time.getCurrentTime());
}
default PredictionContainer<T> predict(INodeID pNodeID, long pPredictionTimestamp) {
throw new UnsupportedOperationException();
}
default void addObservation(INodeID pNodeID, T pObservation, long pTimestamp) {
predict(pNodeID, pObservation, pTimestamp);
}
default void clearData() {
}
SiSType<T> getBasicSiSType(); SiSType<T> getBasicSiSType();
} }
...@@ -26,6 +26,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.HostComponent; ...@@ -26,6 +26,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionSiSType; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionSiSType;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
/** /**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de) * @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
...@@ -49,4 +50,19 @@ public interface SiSPredictionManager extends HostComponent { ...@@ -49,4 +50,19 @@ public interface SiSPredictionManager extends HostComponent {
<T extends Object> PredictionContainer<T> predict(INodeID pNodeID, PredictionSiSType<T> pType, T pValue, long pTime) <T extends Object> PredictionContainer<T> predict(INodeID pNodeID, PredictionSiSType<T> pType, T pValue, long pTime)
throws InformationNotAvailableException; throws InformationNotAvailableException;
default <T extends Object> PredictionContainer<T> predict(PredictionSiSType<T> pType, T pValue, long pTime)
throws InformationNotAvailableException {
return predict(null, pType, pValue, pTime);
}
<T extends Object> PredictionContainer<T> predict(INodeID pNodeID, PredictionSiSType<T> pType, T pValue, long pTime,
long pPredictionTimestamp) throws InformationNotAvailableException;
default <T extends Object> PredictionContainer<T> predict(PredictionSiSType<T> pType, T pValue, long pTime,
long pPredictionTimestamp) throws InformationNotAvailableException {
return predict(null, pType, pValue, pTime, pPredictionTimestamp);
}
void updateValue(SiSType<Object> pType, INodeID pId, Object pValue, long pTimestamp);
} }
...@@ -19,32 +19,26 @@ ...@@ -19,32 +19,26 @@
*/ */
package de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.impl; package de.tudarmstadt.maki.simonstrator.api.component.sis.type;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.Prediction;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.ListBasedPredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.PredictionContainer;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
/** /**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de) * @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 08.01.2018 * @version 1.0 at 03.01.2018
* *
*/ */
public class NoRoadSegmentPrediction implements Prediction<RoadNetworkEdge> { public class EmptyPredictionContainer<T extends Object> implements PredictionContainer<T> {
@Override @Override
public PredictionContainer<RoadNetworkEdge> predict(INodeID pNodeID, RoadNetworkEdge pObservation, public double getProbabilityForValue(T pValue) {
long pTimestamp) { return 0;
return new ListBasedPredictionContainer<>(pObservation);
} }
@Override @Override
public SiSType<RoadNetworkEdge> getBasicSiSType() { public double isInsidePrediction(T pValue) {
return SiSTypes.ROAD_EDGE; return 0;
} }
@Override
public T getMostProbableValue() {
return null;
}
} }
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.transport;
import de.tudarmstadt.maki.simonstrator.api.Message;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 18.01.2018
*
*/
public interface MessageSendListener {
public void messageSend(Message message);
}
\ No newline at end of file
...@@ -20,14 +20,31 @@ ...@@ -20,14 +20,31 @@
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.information; package de.tudarmstadt.maki.simonstrator.api.component.vehicular.information;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
public enum AvailableInformationAttributes { public enum AvailableInformationAttributes {
POSITION("position"), DATE("date"), VALUE("value"), OWNER("owner"), EDGE("edge"), TTL("ttl"), EXPECTED_DURATION( POSITION("position", Location.class), DATE("date", Long.class), VALUE("value"), OWNER("owner", INodeID.class), EDGE(
"duration"), STANDARD_DEVIATION_DURATION("sd_duration"); "edge", RoadNetworkEdge.class), TTL(
"ttl"), EXPECTED_DURATION(
"duration"), STANDARD_DEVIATION_DURATION("sd_duration"), TYPE("type", SiSType.class);
private final String attributeID; private final String attributeID;
private final Class<? extends Object> clazz;
private AvailableInformationAttributes(String pAttributeID, Class<? extends Object> clazz) {
this.attributeID = pAttributeID;
this.clazz = clazz;
}
private AvailableInformationAttributes(String pAttributeID) { private AvailableInformationAttributes(String pAttributeID) {
this.attributeID = pAttributeID; this(pAttributeID, Object.class);
}
public Class<? extends Object> getExpectedClass() {
return clazz;
} }
/** /**
......
...@@ -62,7 +62,7 @@ public class NotificationBasedVehicularPointInformation implements VehicularPoin ...@@ -62,7 +62,7 @@ public class NotificationBasedVehicularPointInformation implements VehicularPoin
@Override @Override
public <T> T getAttribute(AvailableInformationAttributes pKey) { public <T> T getAttribute(AvailableInformationAttributes pKey) {
return (T) _notification.getAttribute(pKey.getAttributeID(), Object.class).getValue(); return (T) _notification.getAttribute(pKey.getAttributeID(), pKey.getExpectedClass()).getValue();
} }
@Override @Override
...@@ -72,7 +72,7 @@ public class NotificationBasedVehicularPointInformation implements VehicularPoin ...@@ -72,7 +72,7 @@ public class NotificationBasedVehicularPointInformation implements VehicularPoin
@Override @Override
public <T> boolean hasAttribute(AvailableInformationAttributes pKey) { public <T> boolean hasAttribute(AvailableInformationAttributes pKey) {
return false; return _notification.getAttribute(pKey.getAttributeID(), pKey.getExpectedClass()) != null;
} }
@Override @Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment