HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
3 z. D# n6 N- b# [; A9 F
& X/ c# B& N1 l public Object buildActions () {2 {) D. T4 I4 Y& `5 q* j2 `
super.buildActions();
$ l; ]6 T0 f P 4 H. _3 Z% k; _4 P! s# o
// Create the list of simulation actions. We put these in# h6 ^4 k+ D. Y0 \) f, L
// an action group, because we want these actions to be
5 e6 y1 x2 T& c- |! {8 p // executed in a specific order, but these steps should7 i2 m) m- y* v" f4 b9 k7 x
// take no (simulated) time. The M(foo) means "The message
, K* [( E: m$ ?5 v2 C/ P/ L. | // called <foo>". You can send a message To a particular" K! k5 R* S, z3 E
// object, or ForEach object in a collection.
9 ]6 w5 U5 a1 O- O( q" J
0 h7 U1 g% R: k8 L1 f, A& Q // Note we update the heatspace in two phases: first run, u3 a8 k S; A$ r2 J8 j: n
// diffusion, then run "updateWorld" to actually enact the9 m1 ^$ F) N. P9 y0 h
// changes the heatbugs have made. The ordering here is
, }* g) e; B7 z // significant!
" ?1 ]' t4 j8 Q. h( K ) i3 \! X; p$ w- q4 P
// Note also, that with the additional
% l) e; }/ @$ _5 P/ E! a( D4 b // `randomizeHeatbugUpdateOrder' Boolean flag we can5 _ ^- M$ B' j+ c% W1 N+ r# P
// randomize the order in which the bugs actually run9 \6 g1 A/ S; w
// their step rule. This has the effect of removing any. f1 Q5 C) P; M
// systematic bias in the iteration throught the heatbug
$ {1 O# w. ?* ? // list from timestep to timestep+ P+ F& S- {! O- S0 h
. R/ h3 ]( ?. R F0 V
// By default, all `createActionForEach' modelActions have1 x, N- x& p2 j% { U6 s) u1 d; R) v
// a default order of `Sequential', which means that the
8 Y& z4 T" B. m' x' C4 L* h // order of iteration through the `heatbugList' will be
! W; k) F6 F% o- j G // identical (assuming the list order is not changed* r: M) o8 V( M' D5 m2 A1 `
// indirectly by some other process).
1 V) d* {) z2 T( Q ! j' d/ k7 U% U7 N0 T' w; q
modelActions = new ActionGroupImpl (getZone ());
" c1 [7 @( M" D8 _) h2 ~6 t
) a3 Q3 X$ F) w( y' n try {( |: N- o: r8 L
modelActions.createActionTo$message
' g: @: A$ _9 q1 [* C (heat, new Selector (heat.getClass (), "stepRule", false));# U8 F, g6 b2 G1 Z5 V
} catch (Exception e) {
( ^8 u/ b P" b5 C- \3 G- ~6 c4 X1 e System.err.println ("Exception stepRule: " + e.getMessage ());
1 Q0 N% d H4 K, ]3 k2 Q* ~9 w# {7 g }5 [; X4 X( v! z# s8 n# Y, q( ?
, }/ R/ b7 Q& h4 h" I try {
5 k: u- T0 R3 n7 S& k7 o Heatbug proto = (Heatbug) heatbugList.get (0);
; i0 a! s& K7 s. V- b, m1 B Selector sel = , d1 l8 F6 J+ p8 {
new Selector (proto.getClass (), "heatbugStep", false);6 u5 g, J# y2 [8 X
actionForEach =) }+ m: F& s/ V0 b* J3 M5 s+ m
modelActions.createFActionForEachHomogeneous$call" @2 S+ M; o) }. h
(heatbugList,& |% t* x0 P {( r/ l
new FCallImpl (this, proto, sel,+ U8 c) ?9 J9 V4 f' `2 k
new FArgumentsImpl (this, sel)));
8 }5 O8 h5 F! L( N1 m } catch (Exception e) {
: r! I8 y- O9 ] @1 f* ` e.printStackTrace (System.err); u8 \0 m: `' N3 E/ { @( b
}
u/ r8 B7 C4 t% d# ]
, S, ?% G9 @7 _! Y' b syncUpdateOrder ();$ t$ ~9 w7 V( O& n, G
! _% e% Y% M: d% ` try {
( A: q: R* W. G& [0 [ modelActions.createActionTo$message
& i& P' ~* |( @% N (heat, new Selector (heat.getClass (), "updateLattice", false));6 D7 F# \" f8 h% F+ B
} catch (Exception e) {. u+ p& M. ?% }
System.err.println("Exception updateLattice: " + e.getMessage ());( n" Z6 m+ P% K+ {3 G* D$ ], q
}6 e, `8 K, u4 Y- o. {- h+ W- W7 m$ N
0 g' [ M2 B, y g
// Then we create a schedule that executes the
2 M2 a" N) }: f, Y4 V // modelActions. modelActions is an ActionGroup, by itself it O/ z) v |; M# C* x# r
// has no notion of time. In order to have it executed in
8 A: P1 n7 O2 ` // time, we create a Schedule that says to use the
; S M6 Q5 P, W' L& p+ B6 e6 z2 Z // modelActions ActionGroup at particular times. This; W# {* e8 L. J8 F
// schedule has a repeat interval of 1, it will loop every
4 M, r; ?# q& w9 O // time step. The action is executed at time 0 relative to
9 o0 w6 A% }% C2 A // the beginning of the loop.7 g6 l$ Z% c& b" C
& ]9 z& T8 e& H+ [3 m
// This is a simple schedule, with only one action that is4 L+ j, I" ]2 j- K9 R6 C* M
// just repeated every time. See jmousetrap for more5 r8 j3 u* |3 y4 H# U0 L# a
// complicated schedules., G7 D% i4 \* V/ {; G; |
) h: T3 m: H) b3 M; r
modelSchedule = new ScheduleImpl (getZone (), 1);! b4 }7 z: Q8 i, l# o
modelSchedule.at$createAction (0, modelActions);
8 |- y/ u* w1 K$ f( F f% F7 S. q$ r
' H# C5 [$ h2 B1 ]8 a) i! C/ } return this;9 d j' ]* o7 D+ K3 O8 V m% [+ H
} |