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
d5f574ca
Commit
d5f574ca
authored
Feb 05, 2019
by
Julian Zobel
Browse files
Added a fixed 30 Seconds pause time between roaming states
parent
cfa7aab1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java
View file @
d5f574ca
...
...
@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
/**
...
...
@@ -40,12 +41,15 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public
class
InAreaRoamingTransitionStrategy
extends
AbstractAttractionBasedTransitionStrategy
implements
EventHandler
{
public
static
enum
roamingTransitionState
{
PAUSE
,
ROAMING
,
TRANSITION
}
protected
Map
<
SimLocationActuator
,
roamingTransitionState
>
roamingStates
=
new
LinkedHashMap
<>();
protected
final
static
int
EVENT_ROAMING_PAUSE_ENDED
=
2
;
@Override
public
void
addComponent
(
SimLocationActuator
comp
)
{
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
TRANSITION
);
...
...
@@ -56,21 +60,24 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
@Override
public
void
reachedAttractionPoint
(
SimLocationActuator
comp
)
{
// start roaming
if
(
roamingStates
.
get
(
comp
)
==
roamingTransitionState
.
PAUSE
)
{
return
;
}
// start roaming if the AP was reached
if
(
roamingStates
.
get
(
comp
)
==
roamingTransitionState
.
TRANSITION
)
{
// schedule the end of the roaming phase, which will make a new transition
Event
.
scheduleWithDelay
(
getPauseTime
(),
this
,
comp
,
EVENT_PAUSE_ENDED
);
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
ROAMING
);
Event
.
scheduleWithDelay
(
getPauseTime
(),
this
,
comp
,
EVENT_PAUSE_ENDED
);
}
// roam around the attraction point
roamAroundAttractionPoint
(
comp
);
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
PAUSE
);
// schedule roaming
Event
.
scheduleWithDelay
(
Time
.
SECOND
*
30
,
this
,
comp
,
EVENT_ROAMING_PAUSE_ENDED
);
}
private
void
roamAroundAttractionPoint
(
SimLocationActuator
comp
)
{
if
(
roamingStates
.
get
(
comp
)
=
=
roamingTransitionState
.
ROAMING
)
{
if
(
roamingStates
.
get
(
comp
)
!
=
roamingTransitionState
.
TRANSITION
)
{
AttractionPoint
currentAttractionPoint
=
this
.
assignments
.
get
(
comp
);
if
(
currentAttractionPoint
==
null
)
{
...
...
@@ -79,6 +86,7 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
if
(
currentAttractionPoint
.
getRadius
()
>
0
)
{
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
ROAMING
);
notifyListenersOfAssignmentUpdate
(
comp
,
currentAttractionPoint
);
}
}
...
...
@@ -86,10 +94,14 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
assert
type
==
EVENT_PAUSE_ENDED
;
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
this
.
addComponent
(
comp
);
if
(
type
==
EVENT_PAUSE_ENDED
)
{
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
this
.
addComponent
(
comp
);
}
else
if
(
type
==
EVENT_ROAMING_PAUSE_ENDED
)
{
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
this
.
roamAroundAttractionPoint
(
comp
);
}
}
...
...
@@ -108,6 +120,6 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
}
AttractionPoint
assignment
=
candidates
.
get
(
rnd
.
nextInt
(
candidates
.
size
()));
return
assignment
;
}
}
}
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