HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:2 V1 h, D) I! O( @
# } B6 l( D2 }& y
public Object buildActions () {, a/ r+ }* T% |6 O6 [6 q/ ?. C$ I
super.buildActions();4 V) ]; Y( g* q& J' b
" c' B/ m1 B8 n# s$ P7 _ // Create the list of simulation actions. We put these in* U3 G3 I* K8 g% d3 p( _) \
// an action group, because we want these actions to be
) n# w/ s5 k! C* A2 J // executed in a specific order, but these steps should
7 r2 q$ ?0 @* J/ h9 Y // take no (simulated) time. The M(foo) means "The message1 U2 X( J: P2 i( `* ~6 K5 S
// called <foo>". You can send a message To a particular
3 j5 V2 \2 s' g! S- Y/ t // object, or ForEach object in a collection.% y% h7 d! o/ u( C
* \1 C# s* h2 @0 R F
// Note we update the heatspace in two phases: first run
1 r( ^+ u+ _3 S- ?+ \; q // diffusion, then run "updateWorld" to actually enact the" c8 C3 t) S! ]( L% s, U9 R* C/ I
// changes the heatbugs have made. The ordering here is
# Q' t# \: z( T1 x$ H' k ~ // significant!+ n2 m0 ]( D4 i. T
( _! \7 A" Z" O1 S // Note also, that with the additional
5 Z9 r9 M/ R% c# c // `randomizeHeatbugUpdateOrder' Boolean flag we can
! n8 Y/ M4 V2 @5 i+ x3 o) D6 w2 Y // randomize the order in which the bugs actually run3 k& Y( j3 n7 |+ ]1 G
// their step rule. This has the effect of removing any
4 C7 W% q1 |& f // systematic bias in the iteration throught the heatbug
5 L! r( r* w$ {; _( e // list from timestep to timestep' X2 h$ z1 ~; L* \% Z. B- W# K2 ` _1 y
" v$ y, e+ m% s; u4 C
// By default, all `createActionForEach' modelActions have
* H+ ~$ v* d3 ?$ W5 P2 Y" d // a default order of `Sequential', which means that the0 W9 p7 _ I; P) y& J8 I; i
// order of iteration through the `heatbugList' will be
( _( n. l3 p0 q // identical (assuming the list order is not changed
5 j9 I# R! l" D: ?3 B // indirectly by some other process)., z9 }& ]3 _# P1 f
0 G) s) j1 p5 S& l& D+ j' S1 i; I' \ modelActions = new ActionGroupImpl (getZone ());8 l/ V; {7 p( L7 R) Z( E/ A/ M
, o, y4 U% d( {( `" ^6 J try {; k$ ~( P0 A( y5 `
modelActions.createActionTo$message7 \( w1 m* j* F, v/ D7 {
(heat, new Selector (heat.getClass (), "stepRule", false));2 z- J1 c( b# m) x
} catch (Exception e) {
; @2 z! C9 T( b0 X6 v8 H; u) u System.err.println ("Exception stepRule: " + e.getMessage ());3 ?/ \+ }/ f7 M2 F- u
}
; v+ I8 z5 a1 T' R8 i! `- ?( E! y7 q$ E! [# Q
try {' M8 V' J" |0 {# w& a8 T
Heatbug proto = (Heatbug) heatbugList.get (0);
( x$ x) ~" B; b/ i; e n Selector sel = , [4 N' E. N8 @+ C! R7 k7 \
new Selector (proto.getClass (), "heatbugStep", false);4 ?+ O- }) B( d8 U+ L
actionForEach =
6 j. Y6 B1 _0 ^- s9 Z modelActions.createFActionForEachHomogeneous$call6 ~/ H1 G6 s* [1 n6 P2 }
(heatbugList,
( f3 L% d( P& F& N- N9 S5 n new FCallImpl (this, proto, sel,
! S3 s4 X# @- y5 D' K- n: T new FArgumentsImpl (this, sel)));
\4 H) y- y) E- H0 S# I( Q- P+ `0 U } } catch (Exception e) {
3 k4 d& Y4 z0 ]) Q% f9 Z% q/ h e.printStackTrace (System.err);
& r" X3 _5 ]+ b. m" ^ }
; d# |- p* [, D
$ Y. ?$ m- H7 `% C! H" h: R syncUpdateOrder ();
; S1 f( w" m$ W5 j; M& k, f3 a8 Y! A4 o% M3 f- U: s B) l
try {$ ^/ ]7 U/ [( f" W: ?7 N
modelActions.createActionTo$message 9 ?, F" E8 `, j
(heat, new Selector (heat.getClass (), "updateLattice", false));. a) I( c4 |6 E9 k' q4 _
} catch (Exception e) {
& r, |' L8 m8 |, w( V/ T8 j# S) } System.err.println("Exception updateLattice: " + e.getMessage ());# c8 ?0 n; f+ X. h: G# u @. p( s
}) }, s! B0 o. G5 l( s
% q8 {$ l) _9 R
// Then we create a schedule that executes the
' v0 U; T. u" l7 u l // modelActions. modelActions is an ActionGroup, by itself it* L N! V2 V7 n
// has no notion of time. In order to have it executed in
2 s! o) R: W3 L# I+ ~- | // time, we create a Schedule that says to use the
2 W8 h7 w& r, R6 Z6 z/ Y! t // modelActions ActionGroup at particular times. This! x4 j3 L5 ?) {; z
// schedule has a repeat interval of 1, it will loop every4 C ?9 }! z/ \# x4 Z
// time step. The action is executed at time 0 relative to
/ a; v0 z) `) r // the beginning of the loop.
& ]1 a7 }! \3 m* h$ \- E
' ?$ R4 E8 o. f* ` // This is a simple schedule, with only one action that is8 u# b' F6 q/ a/ R* U$ s) ?! g
// just repeated every time. See jmousetrap for more) I- B: o$ d: o" R. r1 V" L% ^% f
// complicated schedules./ M0 L$ }# q, {0 X0 Z9 i& v
* ]9 o }8 I/ ^8 c C7 q) G
modelSchedule = new ScheduleImpl (getZone (), 1);
( k4 X+ y y/ w* | modelSchedule.at$createAction (0, modelActions);& s) ^0 O0 B; p
" Q3 o0 c8 u( c- t" ~
return this;
! |- {+ X; }. O- W9 u } |