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
7e67d8f9
Commit
7e67d8f9
authored
Feb 20, 2018
by
Tobias Meuser
Browse files
First working version of monitoring
parent
96cb29ed
Changes
7
Show whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/component/sis/prediction/DefaultSiSPredictionManager.java
View file @
7e67d8f9
...
...
@@ -22,11 +22,15 @@
package
de.tudarmstadt.maki.simonstrator.api.component.sis.prediction
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
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.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent
;
...
...
@@ -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.SiSRequest
;
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.PredictionSiSType
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType
;
...
...
@@ -45,20 +48,25 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
* @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
>,
Map
<
INodeID
,
SiSValueContainer
<?
extends
Object
>>>
availableData
=
new
HashMap
<>();
private
Host
host
;
private
SiSComponent
_siSComponent
;
public
DefaultSiSPredictionManager
(
Host
host
)
{
public
DefaultSiSPredictionManager
(
Host
host
,
List
<
Prediction
<?
extends
Object
>>
pPredictions
)
{
this
.
host
=
host
;
Prediction
<?
extends
Object
>
prediction
=
new
NoRoadSegment
Prediction
();
for
(
Prediction
<?
extends
Object
>
prediction
:
p
Prediction
s
)
{
availablePredictions
.
put
(
prediction
.
getBasicSiSType
(),
prediction
);
}
}
@Override
public
void
initialize
()
{
...
...
@@ -72,7 +80,11 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
_siSComponent
.
provide
().
nodeState
(
predictionSysType
,
new
PredictionSiSDataCallback
<>(
predictionSysType
));
}
availableData
.
put
(
entry
.
getKey
(),
new
HashMap
<>());
}
Event
.
scheduleWithDelay
(
Time
.
SECOND
,
this
,
null
,
0
);
}
catch
(
ComponentNotAvailableException
e
)
{
}
}
...
...
@@ -97,6 +109,16 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
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"
)
private
class
PredictionSiSDataCallback
<
T
extends
Object
>
implements
SiSDataCallback
<
PredictionContainer
>
{
...
...
@@ -106,17 +128,22 @@ public class DefaultSiSPredictionManager implements SiSPredictionManager {
_sisType
=
sisType
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
PredictionContainer
<
T
>
getValue
(
INodeID
pNodeID
,
SiSProviderHandle
pProviderHandle
)
throws
InformationNotAvailableException
{
T
observation
=
_siSComponent
.
get
().
localObservationOf
(
pNodeID
,
_sisType
.
getOriginalSiSType
(),
SiSRequest
.
NONE
);
long
timestamp
=
_siSComponent
.
get
()
.
localObservationOfInfo
(
pNodeID
,
_sisType
.
getOriginalSiSType
(),
SiSRequest
.
NONE
)
.
getLastUpdateTimestamp
();
SiSValueContainer
<?
extends
Object
>
siSValueContainer
=
availableData
.
get
(
_sisType
.
getOriginalSiSType
())
.
get
(
pNodeID
);
if
(
siSValueContainer
!=
null
)
{
T
observation
=
(
T
)
siSValueContainer
.
getValue
();
long
timestamp
=
siSValueContainer
.
getTimestamp
();
return
predict
(
pNodeID
,
_sisType
,
observation
,
timestamp
);
}
else
{
throw
new
InformationNotAvailableException
();
}
}
@Override
...
...
@@ -131,4 +158,60 @@ 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
;
}
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/sis/prediction/Prediction.java
View file @
7e67d8f9
...
...
@@ -21,6 +21,7 @@
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.component.sis.type.PredictionContainer
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType
;
...
...
@@ -35,10 +36,31 @@ public interface Prediction<T extends Object> {
/**
* @param pNodeID
* @param pObservation
* @param pTimestamp
* @param p
Observation
Timestamp
* @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
();
}
src/de/tudarmstadt/maki/simonstrator/api/component/sis/prediction/SiSPredictionManager.java
View file @
7e67d8f9
...
...
@@ -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.type.PredictionContainer
;
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)
...
...
@@ -49,4 +50,19 @@ public interface SiSPredictionManager extends HostComponent {
<
T
extends
Object
>
PredictionContainer
<
T
>
predict
(
INodeID
pNodeID
,
PredictionSiSType
<
T
>
pType
,
T
pValue
,
long
pTime
)
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
);
}
src/de/tudarmstadt/maki/simonstrator/api/component/sis/
prediction/impl/NoRoadSegment
Prediction.java
→
src/de/tudarmstadt/maki/simonstrator/api/component/sis/
type/Empty
Prediction
Container
.java
View file @
7e67d8f9
...
...
@@ -19,32 +19,26 @@
*/
package
de.tudarmstadt.maki.simonstrator.api.component.sis.prediction.impl
;
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
;
package
de.tudarmstadt.maki.simonstrator.api.component.sis.type
;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 0
8
.01.2018
* @version 1.0 at 0
3
.01.2018
*
*/
public
class
NoRoadSegmentPrediction
implements
Prediction
<
RoadNetworkEdge
>
{
public
class
EmptyPredictionContainer
<
T
extends
Object
>
implements
PredictionContainer
<
T
>
{
@Override
public
PredictionContainer
<
RoadNetworkEdge
>
predict
(
INodeID
pNodeID
,
RoadNetworkEdge
pObservation
,
long
pTimestamp
)
{
return
new
ListBasedPredictionContainer
<>(
pObservation
);
public
double
getProbabilityForValue
(
T
pValue
)
{
return
0
;
}
@Override
public
SiSType
<
RoadNetworkEdge
>
getBasicSiSType
(
)
{
return
SiSTypes
.
ROAD_EDGE
;
public
double
isInsidePrediction
(
T
pValue
)
{
return
0
;
}
@Override
public
T
getMostProbableValue
()
{
return
null
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/transport/MessageSendListener.java
0 → 100755
View file @
7e67d8f9
/*
* 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
src/de/tudarmstadt/maki/simonstrator/api/component/vehicular/information/AvailableInformationAttributes.java
View file @
7e67d8f9
...
...
@@ -20,14 +20,31 @@
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
{
POSITION
(
"position"
),
DATE
(
"date"
),
VALUE
(
"value"
),
OWNER
(
"owner"
),
EDGE
(
"edge"
),
TTL
(
"ttl"
),
EXPECTED_DURATION
(
"duration"
),
STANDARD_DEVIATION_DURATION
(
"sd_duration"
);
POSITION
(
"position"
,
Location
.
class
),
DATE
(
"date"
,
Long
.
class
),
VALUE
(
"value"
),
OWNER
(
"owner"
,
INodeID
.
class
),
EDGE
(
"edge"
,
RoadNetworkEdge
.
class
),
TTL
(
"ttl"
),
EXPECTED_DURATION
(
"duration"
),
STANDARD_DEVIATION_DURATION
(
"sd_duration"
),
TYPE
(
"type"
,
SiSType
.
class
);
private
final
String
attributeID
;
private
final
Class
<?
extends
Object
>
clazz
;
private
AvailableInformationAttributes
(
String
pAttributeID
)
{
private
AvailableInformationAttributes
(
String
pAttributeID
,
Class
<?
extends
Object
>
clazz
)
{
this
.
attributeID
=
pAttributeID
;
this
.
clazz
=
clazz
;
}
private
AvailableInformationAttributes
(
String
pAttributeID
)
{
this
(
pAttributeID
,
Object
.
class
);
}
public
Class
<?
extends
Object
>
getExpectedClass
()
{
return
clazz
;
}
/**
...
...
src/de/tudarmstadt/maki/simonstrator/api/component/vehicular/information/NotificationBasedVehicularPointInformation.java
View file @
7e67d8f9
...
...
@@ -62,7 +62,7 @@ public class NotificationBasedVehicularPointInformation implements VehicularPoin
@Override
public
<
T
>
T
getAttribute
(
AvailableInformationAttributes
pKey
)
{
return
(
T
)
_notification
.
getAttribute
(
pKey
.
getAttributeID
(),
Object
.
c
lass
).
getValue
();
return
(
T
)
_notification
.
getAttribute
(
pKey
.
getAttributeID
(),
pKey
.
getExpectedC
lass
()
).
getValue
();
}
@Override
...
...
@@ -72,7 +72,7 @@ public class NotificationBasedVehicularPointInformation implements VehicularPoin
@Override
public
<
T
>
boolean
hasAttribute
(
AvailableInformationAttributes
pKey
)
{
return
false
;
return
_notification
.
getAttribute
(
pKey
.
getAttributeID
(),
pKey
.
getExpectedClass
())
!=
null
;
}
@Override
...
...
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