Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
API
Commits
03459d2e
Commit
03459d2e
authored
Mar 29, 2019
by
Julian Zobel
Browse files
Added TTL to notification info
parent
be8335ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/component/pubsub/analyzer/NotificationInfo.java
View file @
03459d2e
...
...
@@ -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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment