Commit 03459d2e authored by Julian Zobel's avatar Julian Zobel
Browse files

Added TTL to notification info

parent be8335ae
......@@ -20,14 +20,6 @@
package de.tudarmstadt.maki.simonstrator.api.component.pubsub.analyzer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* An object that can be attached to a notification to enable easier analyzing
* in simulation mode.
......@@ -67,6 +59,13 @@ public interface NotificationInfo {
*/
public long getTimestampOfCreation();
/**
* The time this notification is valid seen from the timestamp of creation.
*
* @return
*/
public long getTimeToLive();
/**
* A sequence number for notifications, this can be used to detect missing
* notifications. Only to be used for analyzing.
......@@ -95,81 +94,5 @@ public interface NotificationInfo {
public boolean hasMarker(Class<?> markerClass, long marker);
public class DefaultNotificationInfo implements NotificationInfo {
private final long payloadSize;
private final long originatorHostId;
private final long timestampOfCreation;
private final Set<Long> hostIdsDeliveredTo;
private final Map<Class<?>, Set<Long>> markers;
private final long sequenceNumber;
private static Map<Long, Long> hostSequenceNumbers = new LinkedHashMap<Long, Long>();
public DefaultNotificationInfo(long payloadSize, long originatorHostId) {
this.payloadSize = payloadSize;
this.originatorHostId = originatorHostId;
this.timestampOfCreation = Time.getCurrentTime();
this.hostIdsDeliveredTo = new HashSet<Long>();
this.markers = new HashMap<Class<?>, Set<Long>>();
if (hostSequenceNumbers.containsKey(originatorHostId)) {
this.sequenceNumber = hostSequenceNumbers.get(originatorHostId);
} else {
this.sequenceNumber = 0;
}
hostSequenceNumbers.put(originatorHostId, this.sequenceNumber + 1);
}
/**
* Marks the notification as being delivered to the given host. Method
* returns false, if the notification is a duplicate.
*
* @param hostId
* @return
*/
public boolean markAsDelivered(long hostId) {
return this.hostIdsDeliveredTo.add(hostId);
}
@Override
public void setMarker(Class<?> markerClass, long marker) {
Set<Long> cMarkers = markers.get(markerClass);
if (cMarkers == null) {
cMarkers = new HashSet<Long>();
markers.put(markerClass, cMarkers);
}
cMarkers.add(marker);
}
@Override
public boolean hasMarker(Class<?> markerClass, long number) {
return this.markers.containsKey(markerClass) && this.markers.get(markerClass).contains(number);
}
@Override
public long getNotificationPayloadSize() {
return payloadSize;
}
@Override
public long getOriginatorHostId() {
return originatorHostId;
}
@Override
public long getTimestampOfCreation() {
return timestampOfCreation;
}
@Override
public long getSequenceNumber() {
return sequenceNumber;
}
}
}
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