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
PeerfactSim.KOM
Commits
a9baf33b
Commit
a9baf33b
authored
May 07, 2018
by
Björn Richerzhagen
Browse files
Merge remote-tracking branch 'simonstrator/tm/vehicular-services'
parents
705984e5
f476dae3
Changes
62
Show whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/vehicular/caching/replacement/NoCacheReplacementStrategy.java
0 → 100755
View file @
a9baf33b
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.tud.kom.p2psim.impl.vehicular.caching.replacement
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.CacheReplacementStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
public
class
NoCacheReplacementStrategy
implements
CacheReplacementStrategy
{
@Override
public
boolean
replaceInformation
(
PointInformation
pCachedInformation
,
PointInformation
pSensedInformation
)
{
return
false
;
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/replacement/TTLbasedCacheReplacementStrategy.java
0 → 100755
View file @
a9baf33b
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.tud.kom.p2psim.impl.vehicular.caching.replacement
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
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.PointInformation
;
public
class
TTLbasedCacheReplacementStrategy
implements
CacheReplacementStrategy
{
private
Map
<
Object
,
Map
<
Object
,
List
<
Long
>>>
detectionTimeStorage
=
new
HashMap
<>();
@Override
public
boolean
replaceInformation
(
PointInformation
pCachedInformation
,
PointInformation
pSensedInformation
)
{
if
(!
pCachedInformation
.
hasAttribute
(
AvailableInformationAttributes
.
TTL
)
||
!
pSensedInformation
.
hasAttribute
(
AvailableInformationAttributes
.
TTL
))
{
throw
new
AssertionError
(
"Cannot use TTL caching without TTL set!"
);
}
keepDetectionTimes
(
pCachedInformation
);
keepDetectionTimes
(
pSensedInformation
);
if
(
pCachedInformation
.
getValue
().
equals
(
pSensedInformation
.
getValue
()))
{
return
pSensedInformation
.
getDetectionDate
()
>
pCachedInformation
.
getDetectionDate
();
}
else
{
Object
cachedPosition
=
getEdgeOrPosition
(
pCachedInformation
);
Object
sensedPosition
=
getEdgeOrPosition
(
pSensedInformation
);
if
(
cachedPosition
.
equals
(
sensedPosition
))
{
Map
<
Object
,
List
<
Long
>>
detectedStates
=
detectionTimeStorage
.
get
(
cachedPosition
);
long
currentTime
=
Time
.
getCurrentTime
();
long
weightCached
=
0
;
List
<
Long
>
detectionTimes
=
detectedStates
.
get
(
pCachedInformation
.
getValue
());
for
(
int
i
=
0
;
i
<
detectionTimes
.
size
();
i
++)
{
if
(
detectionTimes
.
get
(
i
)
<
currentTime
)
{
detectionTimes
.
remove
(
i
);
}
else
{
weightCached
+=
detectionTimes
.
get
(
i
)
-
currentTime
;
}
}
long
weightSensed
=
0
;
detectionTimes
=
detectedStates
.
get
(
pSensedInformation
.
getValue
());
for
(
int
i
=
0
;
i
<
detectionTimes
.
size
();
i
++)
{
if
(
detectionTimes
.
get
(
i
)
<
currentTime
)
{
detectionTimes
.
remove
(
i
);
}
else
{
weightSensed
+=
detectionTimes
.
get
(
i
)
-
currentTime
;
}
}
return
weightSensed
>
weightCached
;
}
}
return
false
;
}
public
void
keepDetectionTimes
(
PointInformation
information
)
{
Object
key
=
getEdgeOrPosition
(
information
);
if
(!
detectionTimeStorage
.
containsKey
(
key
))
{
detectionTimeStorage
.
put
(
key
,
new
HashMap
<>());
}
Map
<
Object
,
List
<
Long
>>
detectedStates
=
detectionTimeStorage
.
get
(
key
);
Object
value
=
information
.
getValue
();
if
(!
detectedStates
.
containsKey
(
value
))
{
detectedStates
.
put
(
value
,
new
ArrayList
<>());
}
List
<
Long
>
detectionDates
=
detectedStates
.
get
(
value
);
if
(!
detectionDates
.
contains
(
information
.
getDetectionDate
()
+
(
long
)
information
.
getAttribute
(
AvailableInformationAttributes
.
TTL
)))
{
detectionDates
.
add
(
information
.
getDetectionDate
()
+
(
long
)
information
.
getAttribute
(
AvailableInformationAttributes
.
TTL
));
}
}
public
Object
getEdgeOrPosition
(
PointInformation
information
)
{
if
(
information
.
hasAttribute
(
AvailableInformationAttributes
.
EDGE
))
{
return
information
.
getAttribute
(
AvailableInformationAttributes
.
EDGE
);
}
else
{
return
information
.
getLocation
();
}
}
}
Prev
1
2
3
4
Next
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