HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
$ f* z# z/ \5 `2 q4 v8 }& U" ]% g. U
8 Z$ [; T6 i1 n& j5 }0 H public Object buildActions () {
/ ~! X2 o; Q& c2 m" I super.buildActions();. u: D4 ^7 a( y) I. o0 N
) b }* g1 S, \
// Create the list of simulation actions. We put these in/ @) x/ ?( R' w) m3 q
// an action group, because we want these actions to be8 t0 ?2 T0 _5 N, l1 t
// executed in a specific order, but these steps should# ?8 w& n( v9 H
// take no (simulated) time. The M(foo) means "The message
~8 k: D3 ?3 p, K // called <foo>". You can send a message To a particular4 ~5 s5 ]) Z# E! H/ d, L
// object, or ForEach object in a collection.2 P+ q0 x7 q- V9 ?
* u7 A0 A) \) X: F& W // Note we update the heatspace in two phases: first run: _, Z5 m$ d/ s# M* _: h3 v0 @
// diffusion, then run "updateWorld" to actually enact the
( k, W2 C& }% h$ G! F' K- x // changes the heatbugs have made. The ordering here is/ w2 |) c& u) ~: L& t! O
// significant!
( _1 i2 R3 [/ q8 o6 v7 ?+ H
0 w( e- B0 y$ A7 F* C // Note also, that with the additional
$ U0 E% T! A) D. F // `randomizeHeatbugUpdateOrder' Boolean flag we can! y; i! x7 |4 n
// randomize the order in which the bugs actually run
! N8 k0 E3 @5 y- ^ // their step rule. This has the effect of removing any
6 p* b+ j. |+ }6 g // systematic bias in the iteration throught the heatbug3 m, J: m: h" d6 d1 S
// list from timestep to timestep* `$ C5 ]- ~$ K4 o/ D+ L k0 }
. R ?, v5 ?2 X: T
// By default, all `createActionForEach' modelActions have A8 s$ H+ ?+ U& x
// a default order of `Sequential', which means that the1 J; A# S& a; L% Z; }5 u# H
// order of iteration through the `heatbugList' will be9 s' c) `, {9 g: b
// identical (assuming the list order is not changed
* L1 W" s9 T4 q6 G // indirectly by some other process).9 G" i: V9 q3 |! c8 ?0 |
8 W: ` _& _7 L5 g* J' n modelActions = new ActionGroupImpl (getZone ());
% z' p: S. z1 w" r+ r4 w& |1 M4 k' ]( ~& Y3 x* g) j
try {* g( E. p/ D- _; H" b1 }
modelActions.createActionTo$message f1 [. e" v! T. h' C' T9 f
(heat, new Selector (heat.getClass (), "stepRule", false));
( ~' F/ Q! g& J3 s2 r7 G2 L$ K: Z } catch (Exception e) {# H& t2 q/ u5 y5 q5 W
System.err.println ("Exception stepRule: " + e.getMessage ());6 x. H8 \2 n' z1 Z3 Z; j
}7 S$ A: Z) j/ M
( |! R2 }0 Q# K try {
N2 L# q4 X4 v4 u Heatbug proto = (Heatbug) heatbugList.get (0);
2 i/ @7 `2 }' ?; s( @% ` Selector sel = - l% w* e2 N* G2 E7 V
new Selector (proto.getClass (), "heatbugStep", false);4 _( o$ ^/ U& _! j" s
actionForEach =
; ^- u. u( I+ |8 p9 n% r# b- U modelActions.createFActionForEachHomogeneous$call
% y8 _% |! ]: r( z' d+ s4 r! \ (heatbugList,6 A7 H4 @3 Q o9 c- c
new FCallImpl (this, proto, sel,
, q; I: f0 b$ l! D5 z new FArgumentsImpl (this, sel)));
$ d% u; j. z# l( r9 p9 K' r& S2 A } catch (Exception e) {9 ^$ r- i1 t/ H2 q
e.printStackTrace (System.err);
& z, J5 r" W, U% r5 W }" K3 T1 j& N( E' {; r. c
! C' ~( T t, ?$ W syncUpdateOrder ();
! B2 p7 _: I2 n
+ b' g' O% R' `8 C. `/ f; T try {$ P' y2 n6 N6 g3 j9 W
modelActions.createActionTo$message 1 @/ A7 l# l# f" V7 Q8 g2 X
(heat, new Selector (heat.getClass (), "updateLattice", false));
& D R! O$ m6 X i0 E } catch (Exception e) {
2 Y- {7 K) X ?8 u$ t4 ?- d$ | System.err.println("Exception updateLattice: " + e.getMessage ());5 T3 }/ R4 W! u! n) _' ~- l6 Q7 m: V* O
}* x5 [* U+ G+ J0 v0 K$ `. m
# w+ \& ^; k( D
// Then we create a schedule that executes the
( B/ I F+ [9 i) d // modelActions. modelActions is an ActionGroup, by itself it1 j: D/ d& W) q1 K8 X1 U
// has no notion of time. In order to have it executed in5 G7 Z+ p7 |* v; L
// time, we create a Schedule that says to use the
2 J( v4 e* I% z) ? // modelActions ActionGroup at particular times. This; P0 v$ B( `8 y# u& \- }
// schedule has a repeat interval of 1, it will loop every
- A, h3 a I4 T( V // time step. The action is executed at time 0 relative to
. z9 g' W& b' a- V) d3 K // the beginning of the loop.
1 g$ i {) F! {! u! I
* J$ `2 @+ b6 x8 P // This is a simple schedule, with only one action that is
u* O# x- E A5 ?, ` // just repeated every time. See jmousetrap for more
9 S0 _6 Y; Y4 Q( Y! A // complicated schedules.$ I. m3 C: N% o% S, q# `% x
/ d( G* H5 J8 R% V" u
modelSchedule = new ScheduleImpl (getZone (), 1);
' E) q2 X/ s, N; N modelSchedule.at$createAction (0, modelActions);6 R# @6 O9 ]9 O
8 o! y. G6 f: I0 E
return this;
" [4 P2 d; L y } |