HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
: @/ I9 J, A- E1 X* t5 J2 J) O, l3 \3 a0 `
public Object buildActions () {
4 A5 z" K+ {2 T super.buildActions();' I- B' |0 U* Q' A8 z' W5 a
/ \3 w$ d6 V: k' I& E; t/ l. j- N // Create the list of simulation actions. We put these in
" U- [& x4 ?! m( a- p6 G7 ] // an action group, because we want these actions to be, q- Q+ _* ~8 {& d$ b
// executed in a specific order, but these steps should
' v, J7 Y6 b* q" @: h7 B- G# g // take no (simulated) time. The M(foo) means "The message6 X% R2 N" O) ?2 ~( N* ]4 S Z
// called <foo>". You can send a message To a particular
9 l0 F5 B/ O( f* W# O // object, or ForEach object in a collection.
8 q: \; y( |1 u
; ?& M3 m; k3 y // Note we update the heatspace in two phases: first run
5 x6 A& d6 J$ t // diffusion, then run "updateWorld" to actually enact the
+ d0 N. Z$ ^' j% _5 p // changes the heatbugs have made. The ordering here is
! r" G; j$ U, B, j) { // significant!
m0 M. ^1 P0 e7 u * {7 q% }3 h8 e* U- o! p9 i1 a
// Note also, that with the additional' b v6 m) e3 z' t7 r
// `randomizeHeatbugUpdateOrder' Boolean flag we can' Q+ B }$ A |. U' z, B3 A
// randomize the order in which the bugs actually run% r4 |4 M/ U/ ]9 w2 G
// their step rule. This has the effect of removing any& s- p7 k2 t# j; k* F
// systematic bias in the iteration throught the heatbug
6 p" k' X ^. o" E% X! ] // list from timestep to timestep
v- W( V# c* G" Q1 e+ L- W
6 H e% V, C, [+ L- z // By default, all `createActionForEach' modelActions have
& W1 I' J7 k( X; h // a default order of `Sequential', which means that the: ~ D- d. M* \- i+ o
// order of iteration through the `heatbugList' will be
) c; x4 \' u2 `4 g // identical (assuming the list order is not changed4 y' w1 s- P' u" w9 D
// indirectly by some other process).* b1 w- A6 F( q' m
% X, d1 i2 i" [% C7 n modelActions = new ActionGroupImpl (getZone ());4 s& v( ?1 }3 J& S* d: }* a
2 d' \- d D7 \ try {
) @3 e; |' \: | modelActions.createActionTo$message- B/ M# b: Y% z
(heat, new Selector (heat.getClass (), "stepRule", false));$ P6 @& m. k% O. k* e$ S2 t. h3 X
} catch (Exception e) {
0 y) b* k( m; G8 A, v/ b3 x System.err.println ("Exception stepRule: " + e.getMessage ());
: L! x- N9 Z1 q( A" F1 | }
! L% Y- G# w& o4 N ?$ U& j3 o
* B. y" M; f2 d. q, Y9 g1 C: ] try {
0 Y2 y5 B/ r0 \/ f. ~4 Q Heatbug proto = (Heatbug) heatbugList.get (0);/ [# K A n, t9 G4 c
Selector sel = ) ?* ^6 M# r& O, G% j! U
new Selector (proto.getClass (), "heatbugStep", false);% ]! |& i* ~5 j% `+ t. W6 W+ G2 r
actionForEach =
; a2 H1 u0 X, g! j1 b modelActions.createFActionForEachHomogeneous$call
" F! I* v0 f5 s (heatbugList,! e5 T8 w* k+ R& h* O* e9 p
new FCallImpl (this, proto, sel,
z& P7 z, d: u& B7 F new FArgumentsImpl (this, sel)));
' N* G( b& L$ o ] } catch (Exception e) {! u* u. q! s& B: W% p, e
e.printStackTrace (System.err);
3 B0 i/ L$ L3 O* r. l }
( M' e |$ s; W 3 `- o& a* Y, S
syncUpdateOrder ();
% q% }2 p4 v$ D0 f1 f6 n" ~6 k
I' L" j; ?7 n d try {' q6 G$ Q1 y- [5 g
modelActions.createActionTo$message
/ M) ^( y/ m- S+ X% |& E( l9 W1 i; X (heat, new Selector (heat.getClass (), "updateLattice", false));
6 k& L# q# `" l$ U$ t! O. Q& T } catch (Exception e) { Z, }) n( D+ u0 L/ r: @4 e
System.err.println("Exception updateLattice: " + e.getMessage ());
4 a& P+ T; q2 R& N, Q& S" u1 b }
3 T3 n/ i2 I' G* i8 f/ }* K % l0 q1 l+ r2 ?1 F; D" C8 b9 c
// Then we create a schedule that executes the9 N' W" L8 K: ?0 J
// modelActions. modelActions is an ActionGroup, by itself it) k e6 x+ W3 L/ Q
// has no notion of time. In order to have it executed in$ l1 m% O6 a2 S `3 X
// time, we create a Schedule that says to use the
9 {5 o" {9 C9 q c. o* r+ l; Y t4 c // modelActions ActionGroup at particular times. This
) }7 N, w+ |! O/ g) c8 f // schedule has a repeat interval of 1, it will loop every
{# x2 Y( `2 d# c* m // time step. The action is executed at time 0 relative to
; Y( ]- H; w/ n // the beginning of the loop.
% ]; {6 c$ g! C1 d$ Z1 h1 @: d4 \: w( k. F9 G& R$ q' H- e
// This is a simple schedule, with only one action that is7 S( ^2 F( s' g$ |; e
// just repeated every time. See jmousetrap for more
3 m% T* `. v7 {6 S5 } // complicated schedules.1 [1 @' x# W: z2 T# j) `
( `2 c( W' j, D
modelSchedule = new ScheduleImpl (getZone (), 1);
. O% P$ D+ @* K0 _' }1 m modelSchedule.at$createAction (0, modelActions);
' g9 {( m7 U- M. w' U
& Z) [" @ A( S- T7 F return this;
6 O( g( d9 V6 s7 o } |