HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
* X4 ?+ N, W9 k, Q0 T5 O" H3 r- J7 h# i p) j& @% [
public Object buildActions () {
( I" B0 G) D; N super.buildActions();
& x# j! Q, L `) o" E% e: `
% K* d5 y6 d8 o1 Z- P // Create the list of simulation actions. We put these in2 K1 b; ~: Z' a/ H% a; B' j) M
// an action group, because we want these actions to be
0 \- w: [$ F* i( |0 V, t // executed in a specific order, but these steps should
$ b& w# @# l. Z // take no (simulated) time. The M(foo) means "The message
) V, n4 r B! ^+ ]: w1 q4 S // called <foo>". You can send a message To a particular
8 k$ P' E+ l! L& c' B9 r // object, or ForEach object in a collection., f9 V" z3 v' V0 |, G2 N- X
( y# ^7 L9 T7 V6 L1 L" O // Note we update the heatspace in two phases: first run3 N: N& P) p* E6 S
// diffusion, then run "updateWorld" to actually enact the- E+ t4 P9 M+ Z) ? D7 Z0 x
// changes the heatbugs have made. The ordering here is8 U+ X+ b% w$ I( B# i% n& P; p" U
// significant!" c) c) [& G& G, t4 z
9 p4 U" s6 g/ t O% f+ K5 R // Note also, that with the additional
4 P8 W% V1 |! ]3 n // `randomizeHeatbugUpdateOrder' Boolean flag we can( Y& C8 i5 w2 Y% S. r
// randomize the order in which the bugs actually run' ?" y0 C2 W) g
// their step rule. This has the effect of removing any
9 `7 ?9 k/ r4 |) J // systematic bias in the iteration throught the heatbug5 L! t0 B- C% @1 ]
// list from timestep to timestep% ?9 l6 f; M% k+ l+ Z1 v3 j- l
% b' B# p5 U2 Z# w( y // By default, all `createActionForEach' modelActions have
$ u, S7 I# b+ f; d5 D8 e9 N- m // a default order of `Sequential', which means that the% {6 R& z; e* U& e0 l+ i3 r2 W
// order of iteration through the `heatbugList' will be- ]. ~ l* y' N0 @
// identical (assuming the list order is not changed, P- I: M& }4 q- O- {
// indirectly by some other process).1 v% E7 n) _, s/ a* I
7 M* _2 `" _! }) I3 H
modelActions = new ActionGroupImpl (getZone ());
4 a' j" `+ f H% [
/ ?8 f% G% w t& G% R try {' K, V8 P: _+ g ^3 R) R
modelActions.createActionTo$message1 e$ Z- H0 L; ]/ A
(heat, new Selector (heat.getClass (), "stepRule", false));
) ^& N- a: f6 m% E } catch (Exception e) {( X5 M) Z6 B# \8 ` I! s1 O
System.err.println ("Exception stepRule: " + e.getMessage ());
0 N e& Y; X0 _( E) ` }
8 \9 L" E" A1 a4 n7 [& v0 b' G* s2 y, ?% @
try {5 }! l6 @2 J- X
Heatbug proto = (Heatbug) heatbugList.get (0); g: U5 ?2 d( Y+ ?
Selector sel =
" L1 ^+ K+ G" a! W# w, g E3 h new Selector (proto.getClass (), "heatbugStep", false);
. q: r2 t( z% X& a$ C- h% I* |# v+ I actionForEach =
" S- h: |4 f/ u3 q: t modelActions.createFActionForEachHomogeneous$call/ S; l' P3 n2 s. S6 Q- d( U
(heatbugList,
8 G( g; \2 x. e1 n- y new FCallImpl (this, proto, sel,
+ j, W5 o* X! O( ], x new FArgumentsImpl (this, sel)));
4 A/ ]2 e h( g } catch (Exception e) {5 S# X1 {4 T1 K }* [; c' i- o+ I3 p! U, `
e.printStackTrace (System.err);
% q- T# V- q7 F$ l& T" ?3 w }
9 H4 A1 Z9 H% k: a E + w9 z8 p% x. o! w2 @! n) v
syncUpdateOrder ();
$ _ N- U2 O: R
1 C9 G, \1 A. X) G. C try {5 O F/ Q7 w/ T5 U- w' W# A3 d
modelActions.createActionTo$message
% r8 a* _. T8 n5 S q$ b (heat, new Selector (heat.getClass (), "updateLattice", false));
* n$ J9 P4 p9 y" M# c1 P } catch (Exception e) {9 `* Y X7 P% v
System.err.println("Exception updateLattice: " + e.getMessage ());
$ d _- T. N6 B: L( D }
/ a f4 Z( |7 J 1 f- y/ G& A6 C( B J3 a/ m
// Then we create a schedule that executes the0 ^( D) P# Y: H. N2 q
// modelActions. modelActions is an ActionGroup, by itself it
$ \: V% G# U G+ Q; T // has no notion of time. In order to have it executed in* e1 U. j6 @& B5 b4 o! w' s8 c
// time, we create a Schedule that says to use the
4 H/ u, m# O6 G/ _( a5 w0 d // modelActions ActionGroup at particular times. This9 s N1 X4 }0 D+ j
// schedule has a repeat interval of 1, it will loop every& z; W1 l! S, j; T5 s5 m
// time step. The action is executed at time 0 relative to
2 U) x; ^6 R; z! s // the beginning of the loop.
! k) y ~# z$ t( w
* S1 S3 d9 `/ P // This is a simple schedule, with only one action that is
: z2 Q+ ?0 C+ {+ a& J1 r" Q // just repeated every time. See jmousetrap for more2 j6 ]$ @# v o$ V& R& G
// complicated schedules.' m0 b- z: J ]( ~1 J
) o" y# n/ h6 s. B
modelSchedule = new ScheduleImpl (getZone (), 1);
^- l. c7 D3 u2 W5 x. ^9 a modelSchedule.at$createAction (0, modelActions);0 e' y; i& L6 n' {0 m
$ f/ X) d: J$ [ ?' Y. {2 V return this;
* R: J! W4 s8 t# ?3 }# x/ L( Z$ M } |