HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
) |$ p C1 H4 I( d/ m5 u$ V# [7 d0 o' n( _8 q
public Object buildActions () {2 R B5 d2 w* P& }- u* |
super.buildActions();
: ?0 m" _$ `6 b7 n; _3 ~
3 O; b9 Y: z; ~9 |9 c( b // Create the list of simulation actions. We put these in
4 b4 F$ O, r, d6 ?4 B6 x A // an action group, because we want these actions to be; E, x Y& B7 U/ _
// executed in a specific order, but these steps should
4 k" j0 {% I8 J/ n# | // take no (simulated) time. The M(foo) means "The message
+ Z1 |# u! h; { // called <foo>". You can send a message To a particular
9 X d7 ^0 X$ \7 O/ J // object, or ForEach object in a collection.* m g* R9 R6 w3 I/ d6 s
- }4 I- \ a/ x // Note we update the heatspace in two phases: first run* R) a% g1 J/ `& b4 S |
// diffusion, then run "updateWorld" to actually enact the# s, s5 K) B4 g8 V$ L8 Z
// changes the heatbugs have made. The ordering here is
7 J0 N& c! X/ \ e' { // significant!
+ ?( n' Y$ \& d( d " n% _" z [) f1 l3 N' D% n9 \- V' g
// Note also, that with the additional* Z6 t& I+ c; W$ j
// `randomizeHeatbugUpdateOrder' Boolean flag we can
9 w# n( @. @" r% P // randomize the order in which the bugs actually run' H( @+ Y x% @! n9 _6 i1 ]" T; E
// their step rule. This has the effect of removing any2 Z q* F9 N. s9 G" z# X
// systematic bias in the iteration throught the heatbug H6 z' ]) ^+ d) T$ H# Q% d4 Z9 Z1 [
// list from timestep to timestep1 J+ K- @3 x3 R6 j, R
" x# R/ W2 ?' O* x. w4 v // By default, all `createActionForEach' modelActions have
& H5 K$ L8 a! S8 y( u# @ // a default order of `Sequential', which means that the
1 S0 W4 J. K" M( l, I2 z* U* g- w/ g // order of iteration through the `heatbugList' will be, a& n1 X* [0 P8 z
// identical (assuming the list order is not changed
; l( q& |. o- ]9 \- `, [- O // indirectly by some other process). h' K! F# r5 v, Z
H& l- {7 Z o) K- v0 e Z
modelActions = new ActionGroupImpl (getZone ());
' T1 Q& Y, Z% Y$ y
3 f/ g7 t2 H5 A# N1 a \) X1 t try {7 f; J' X4 {. M: ^% z, c
modelActions.createActionTo$message
! Y8 X9 A) x6 v: s5 V/ g (heat, new Selector (heat.getClass (), "stepRule", false));3 ]4 |9 x' }( T! T# r" T
} catch (Exception e) {
$ V R9 h0 f* X0 Z$ [5 X System.err.println ("Exception stepRule: " + e.getMessage ());' d- [3 r5 k5 S _1 P
}
4 w; g. l- R' h- G( h1 f+ u, {
9 u5 {2 d" V9 D, K7 ]& u try {
1 z7 g" P7 U' o3 q1 `) P Heatbug proto = (Heatbug) heatbugList.get (0);
7 N3 w# G' D# g7 g! ] Selector sel = , Y/ A* `" N$ {
new Selector (proto.getClass (), "heatbugStep", false);7 _/ [/ d4 Y& b+ y3 T; H3 {
actionForEach =
+ ?( D. d ~2 u modelActions.createFActionForEachHomogeneous$call' b% D8 b r+ p
(heatbugList,
0 [; ~ x- I7 m+ H. v1 N+ t new FCallImpl (this, proto, sel,
% X, E0 d! Y, D new FArgumentsImpl (this, sel)));2 Y4 h/ G; }. F) G
} catch (Exception e) {) S9 [ e( i" M0 q0 ?
e.printStackTrace (System.err);9 T+ C! Z \" Q/ t# L" d E
}
! s# y3 u: V5 x" p- h
% w$ p4 y$ [/ s) o$ k syncUpdateOrder ();
1 t% F: R$ s$ [4 d$ i. B) L" L2 o. v6 ~ q0 G+ q
try {6 C1 V9 P$ d0 q7 V
modelActions.createActionTo$message
. g) i+ w1 S |5 h8 z. u5 A (heat, new Selector (heat.getClass (), "updateLattice", false));
' F4 x5 ]4 d2 @( g } catch (Exception e) {
- L$ N& ~. j$ I& u: i" _9 u# a System.err.println("Exception updateLattice: " + e.getMessage ());
, k7 c" G3 E/ ` } N7 }& M6 h( P6 x, y/ [
. K5 `# ?8 V" z# U9 c
// Then we create a schedule that executes the7 z+ @/ } b5 Q
// modelActions. modelActions is an ActionGroup, by itself it( s" U4 {0 ]0 g4 T
// has no notion of time. In order to have it executed in
$ \% R' J" d, `' q2 p8 t/ a // time, we create a Schedule that says to use the
5 Q+ A6 x- `& J* p; l! @/ H // modelActions ActionGroup at particular times. This$ p) W+ ?2 @. f1 _( h
// schedule has a repeat interval of 1, it will loop every
0 Z" \) E. I4 g8 c( d // time step. The action is executed at time 0 relative to& h) O% W# _9 ~7 |
// the beginning of the loop.
- B/ {3 ^& J9 ^+ W/ f$ w/ f W Q9 s! g. ^- i. b! J6 y
// This is a simple schedule, with only one action that is) c, G9 ]4 I; v
// just repeated every time. See jmousetrap for more, j. Y6 Q) n7 f0 t7 q! K+ x4 W2 g
// complicated schedules.
4 y8 I; D0 S1 o$ ~; H
2 ?: j" z+ g& x modelSchedule = new ScheduleImpl (getZone (), 1);! B, N" A R8 |7 b6 e
modelSchedule.at$createAction (0, modelActions);
9 S9 C6 y( L1 ~ 2 t" ^. k# g4 z
return this;2 U2 ]# e- l; U3 J- _
} |