HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:3 D: ^. Q2 Z7 S
2 j- y6 ^7 U: g3 V3 g- d public Object buildActions () {
" c5 ]! C# t9 Z' `' N, m super.buildActions();
. @& c8 M4 c1 L$ k H/ U8 ^ T+ t5 Z: t6 z# \, S
// Create the list of simulation actions. We put these in) x: C5 |7 a( O' x
// an action group, because we want these actions to be
5 ]1 u" u3 r! x# ]. t // executed in a specific order, but these steps should
; A% B: }' c/ J' E' Q& k) D4 S // take no (simulated) time. The M(foo) means "The message
* F! K, W- C" K7 G7 P // called <foo>". You can send a message To a particular% i3 d8 G0 j3 h( d, Z
// object, or ForEach object in a collection.* [& p5 t! i- k$ N+ n$ m
( o4 J. e7 ~6 Z9 N, { G; t
// Note we update the heatspace in two phases: first run6 h7 J3 Q2 V" r4 c, i: ?
// diffusion, then run "updateWorld" to actually enact the' r% y* d2 @* U6 c* f
// changes the heatbugs have made. The ordering here is) h, X0 \, `% m( R) x
// significant!( `( w/ T0 `" h6 d: t- A
$ |9 ?! L9 Y, l // Note also, that with the additional
2 Y* j8 t" s* l6 z3 ? // `randomizeHeatbugUpdateOrder' Boolean flag we can
4 z- l7 [. O3 j4 _ // randomize the order in which the bugs actually run3 [2 D! K+ t: Y2 J( |
// their step rule. This has the effect of removing any) y0 R: ^4 `9 h4 ?! L# j2 m" ?. T
// systematic bias in the iteration throught the heatbug
# q- c6 S5 |; U // list from timestep to timestep" R; d. K% a+ F: _
" r! X+ O6 }- b9 Z // By default, all `createActionForEach' modelActions have& Y" `& l4 |& Y! _* A5 f" j
// a default order of `Sequential', which means that the
' {$ z& I& `6 Z8 y // order of iteration through the `heatbugList' will be4 a/ C" H" W) \
// identical (assuming the list order is not changed
- u l! M% j O7 E" I G7 e // indirectly by some other process).$ F( |9 A; ^4 L
& t9 a5 u4 X5 {/ U6 |; H7 D
modelActions = new ActionGroupImpl (getZone ());
5 [7 t9 _' @$ z( ?! U, B, j* q2 l1 ~6 C5 L- H' F
try {# H# K; K, ]& l. n
modelActions.createActionTo$message0 J8 E, W. g$ | _0 f# l
(heat, new Selector (heat.getClass (), "stepRule", false));" d q# s* @, b) s% O
} catch (Exception e) {& k& T2 y c& p, o/ Z
System.err.println ("Exception stepRule: " + e.getMessage ());$ D% \2 H; P B
}$ j- [ }2 x8 K
, G' R7 O8 m- d2 D4 \8 W& I
try {2 D& C5 v" a3 d& X
Heatbug proto = (Heatbug) heatbugList.get (0);. n* m( K. m9 a# ^4 j' Z
Selector sel = ! C7 w) p/ [' A) T3 w- l
new Selector (proto.getClass (), "heatbugStep", false);
2 T' \2 x! c) y( w' O U _0 j( k actionForEach =- s3 n- W7 G# ]( P/ o; b1 M; |8 ^% Z: ^
modelActions.createFActionForEachHomogeneous$call
: t0 l+ Y# l$ {5 z3 Q4 u (heatbugList,
, P4 K2 `/ T' n. E) S new FCallImpl (this, proto, sel,% D7 z% `+ ?3 w2 A' b
new FArgumentsImpl (this, sel)));
, F; n2 m6 r; G* N: y- N } catch (Exception e) { v" m8 U* h. K' R% M; O: |
e.printStackTrace (System.err);
7 R' g; ^, J! A6 M% y }
; U, I' L8 i7 t5 v
& i1 `, a, E9 l) {- o9 ~& F3 R1 V: Z/ n5 T# A syncUpdateOrder ();
" Z" _& X2 E1 m- J* q8 K' r1 Q# \, k2 F Y9 \3 \1 Q, ~7 e
try {9 Z. q/ T& T5 ? q
modelActions.createActionTo$message
' _, m# A7 h e7 y: [- R3 b (heat, new Selector (heat.getClass (), "updateLattice", false));4 [% I- {% A1 F3 y L
} catch (Exception e) {
- e9 e1 h7 x7 t3 \ M0 { System.err.println("Exception updateLattice: " + e.getMessage ());
0 x; f, \% v, p: T7 z8 ~ }
, k- T" I [" p G7 T1 F# b* k5 F& u& G, |4 c
// Then we create a schedule that executes the4 o' i5 |5 T& e* e9 \
// modelActions. modelActions is an ActionGroup, by itself it( W" z5 P: j1 y' ^5 J. X: F8 t$ `
// has no notion of time. In order to have it executed in
: s- J3 z. H" A1 s // time, we create a Schedule that says to use the7 b/ e7 q S1 {6 y& Z5 P
// modelActions ActionGroup at particular times. This
8 \. ]" ]6 B9 v! _; {& A7 m' { // schedule has a repeat interval of 1, it will loop every
# T" J. q5 o% Q9 A // time step. The action is executed at time 0 relative to
# v! z1 w' w* g( n+ a- J- _" k* i // the beginning of the loop.$ z$ W, R! k, B0 t0 g
. t; B3 J5 `1 h: G6 |6 c$ C // This is a simple schedule, with only one action that is
8 ~. f9 i. ~7 y7 w. ]7 z // just repeated every time. See jmousetrap for more
+ E4 v5 y4 V+ f8 D // complicated schedules.
( g6 {, c6 J/ O4 l# r: U% c+ _
Y( k: ?+ p% H" q/ {) m- s modelSchedule = new ScheduleImpl (getZone (), 1);
7 a1 O3 D, H/ l! b& z1 J modelSchedule.at$createAction (0, modelActions);' i* ~ _: {$ V
/ X2 J( T5 m: b, J
return this;# o. O( K+ K( e- G
} |