HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
, V( H0 }6 n1 `
" S; ^# F6 }0 V public Object buildActions () {
! g& u, B, d( w# h2 k6 S2 I super.buildActions();
$ u9 z; M. V: X8 m3 P 8 `; M; C1 A6 F) z# h+ P
// Create the list of simulation actions. We put these in
( F3 K ^ P/ ?9 e // an action group, because we want these actions to be8 O' d' a- u. W1 Q2 L% h( a% Y
// executed in a specific order, but these steps should8 h! e7 F7 @# i( P) P$ x
// take no (simulated) time. The M(foo) means "The message
9 e( c' `: S7 W2 [+ f // called <foo>". You can send a message To a particular- G: s7 n9 O$ K5 v# A
// object, or ForEach object in a collection.
" ~0 w$ P$ E2 W; H4 N
9 |! X3 S* D" U* S/ B // Note we update the heatspace in two phases: first run! ]- g( j: _8 t
// diffusion, then run "updateWorld" to actually enact the) \. A; g' ~ L& _% k! r
// changes the heatbugs have made. The ordering here is. ?1 j, C( A2 y, t8 @4 L& Z
// significant!) g [' v- b9 s, r- F
( `# l+ V% m" Z y$ v( G. z+ k2 P* Y // Note also, that with the additional
3 m$ C* n& B3 X$ H // `randomizeHeatbugUpdateOrder' Boolean flag we can' h! a t- F8 B, \. l
// randomize the order in which the bugs actually run( L( }* |% R* Z9 k& b
// their step rule. This has the effect of removing any4 n2 e1 ^6 D, b4 P, Z
// systematic bias in the iteration throught the heatbug; q' u# d+ C m S0 g; B
// list from timestep to timestep1 x$ U$ ]4 B1 H# u" m$ k
, Q; x* X- E! l8 u
// By default, all `createActionForEach' modelActions have4 J1 ]8 E* q& h" C7 j. y
// a default order of `Sequential', which means that the
* o n2 v- K3 Y9 s4 o, q3 R6 x // order of iteration through the `heatbugList' will be+ c5 q8 n$ q* ?4 `( A. Q' n
// identical (assuming the list order is not changed
* Q2 W; T% I, o; j6 m [ // indirectly by some other process).$ o0 ~ _5 `8 H8 H
! y* i H5 d9 i* [ modelActions = new ActionGroupImpl (getZone ());
1 N0 l: Z$ E# D# G" m$ d9 M
. E7 c& u' K% q _- h try {
+ I* l d* p: P: D1 H* Y modelActions.createActionTo$message. x" C; g8 m$ N
(heat, new Selector (heat.getClass (), "stepRule", false));6 N) w- \) o# H. `7 B6 X2 X
} catch (Exception e) {! H* {" i- ~# q ]: j
System.err.println ("Exception stepRule: " + e.getMessage ());
! J- O6 G- y1 \8 k. ^) u }
% ?1 n: g x' }$ S
3 a; Z/ @; `8 z2 x( y& b try {
2 T$ [9 Y' @+ g; B Heatbug proto = (Heatbug) heatbugList.get (0);
3 T) ^5 o4 V0 i* q6 g7 b6 f& E& _ Selector sel = 4 {! u, Z: b$ O t0 Q$ v2 r" T
new Selector (proto.getClass (), "heatbugStep", false);5 b( ]: l- @. t# u$ g9 K) l
actionForEach =
" y, n8 H4 B3 ?3 K- z+ r+ d modelActions.createFActionForEachHomogeneous$call/ I- P8 y9 U" ~) r
(heatbugList,
$ y& c! v; f" a! Y new FCallImpl (this, proto, sel,) K8 N/ ?6 t" I+ D; p
new FArgumentsImpl (this, sel)));
& |0 F6 j& V N- ?) | } catch (Exception e) {& T3 M& t* Y, H$ L7 j
e.printStackTrace (System.err);
1 y% i) B; e$ h) d }
( g( R- o6 Z# X" X1 B3 I: d3 b( b ) V4 J m- y% P+ b8 } `
syncUpdateOrder ();3 L6 e: K% y) M r( i$ Q
' {7 v6 O, D, { U
try {* p* a- ~/ B7 \0 w8 E6 N2 ~
modelActions.createActionTo$message
3 |8 D4 @+ D1 `9 A+ q( C1 X3 B0 A (heat, new Selector (heat.getClass (), "updateLattice", false));0 t. D7 ] s/ e: h
} catch (Exception e) {, G; Y7 M6 G; {5 u. R( \& U( ]) h
System.err.println("Exception updateLattice: " + e.getMessage ());
3 h9 A! P8 G% W( R0 j5 C }/ O9 W* Y0 V+ Z) Y0 o
) H- C( u9 J5 s9 Q% }% N' |4 C
// Then we create a schedule that executes the; v! u% t0 T2 v) ^) t
// modelActions. modelActions is an ActionGroup, by itself it
: `( J# g% J& K. _ // has no notion of time. In order to have it executed in5 D5 u. L" E+ f' P6 z* }5 P
// time, we create a Schedule that says to use the
# n% t W4 u) k' j // modelActions ActionGroup at particular times. This, y- y% M2 {! c% u1 P
// schedule has a repeat interval of 1, it will loop every
9 M, M# }" S' v$ W4 }# c( E$ x6 c // time step. The action is executed at time 0 relative to# E. H* o2 d$ s! f7 P
// the beginning of the loop.$ f, o e& w: ]& ?3 n5 w8 ~- g
/ _; O& v# j$ O3 Z
// This is a simple schedule, with only one action that is
1 H4 m; _* n# U7 m! D3 k2 D // just repeated every time. See jmousetrap for more
: n& I. F$ q( m9 ~0 z // complicated schedules.
. Q7 ?& f+ y3 E
& X( e" ?# p( }9 V modelSchedule = new ScheduleImpl (getZone (), 1);+ e2 \) G1 i3 |- ?' `. M" C
modelSchedule.at$createAction (0, modelActions);
1 h4 g' A4 o0 @ - c" z5 ~) i! O) k+ H- `/ g
return this;5 Q7 Y# G& R5 B/ b5 h L# a4 w
} |