HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
) j. j: \3 D( x' e* T$ {* W& v9 X* B& v3 q
public Object buildActions () {, ]6 J9 T$ I; W$ b% I
super.buildActions();1 P# m- M: w% j0 a* u3 @! Q
' v; d( ~6 n" z // Create the list of simulation actions. We put these in
! j5 Q' c9 N* i' D( h# v; t // an action group, because we want these actions to be
2 X# M0 ?3 n+ Z G // executed in a specific order, but these steps should8 V* R! Q# O" {" i+ o5 I1 d+ N
// take no (simulated) time. The M(foo) means "The message8 u1 B+ O' x6 o; t0 Z. G
// called <foo>". You can send a message To a particular5 Q0 D. K, n5 F3 b& k9 s
// object, or ForEach object in a collection. c$ h9 Z9 R" {* a
2 T! a, [, X" d& q0 _$ x- ` // Note we update the heatspace in two phases: first run# a) r4 J, T8 y* A0 i. ?
// diffusion, then run "updateWorld" to actually enact the1 R) P \, e t( c9 N# o
// changes the heatbugs have made. The ordering here is
8 S# G2 E1 n% u' T- U! | // significant!( T9 q7 z7 F8 f3 L
: S8 D! C0 l; \
// Note also, that with the additional
/ |5 z. E4 E5 E& U6 u // `randomizeHeatbugUpdateOrder' Boolean flag we can8 S. Z* P* K7 Y5 [; T) k7 W8 x
// randomize the order in which the bugs actually run
. H5 T5 h3 r, v5 u // their step rule. This has the effect of removing any' Y0 n6 f" s6 k l2 h3 r7 I
// systematic bias in the iteration throught the heatbug
5 j. h Y7 l8 x, I) ]) [+ { // list from timestep to timestep) _6 Y5 d+ [2 y' U
E6 @7 e4 q/ _7 {: Q, l, w' d( R. } // By default, all `createActionForEach' modelActions have; w# Q3 o; S* @( ]2 W) b$ Q/ e
// a default order of `Sequential', which means that the4 n& i- ]. O' [
// order of iteration through the `heatbugList' will be, g7 R# w* O* q6 }
// identical (assuming the list order is not changed+ p3 M- B- e5 e. j2 M$ s
// indirectly by some other process).* B8 @# {, u5 U, t$ F2 B
& `1 F% R; I! D1 v
modelActions = new ActionGroupImpl (getZone ());6 Q5 i1 g' k" u% I5 F- h# _
( F/ ]" g+ U" _' w' n/ k
try {0 C# Q$ r5 X) m' O( B+ b
modelActions.createActionTo$message$ r7 H! x0 x& r4 g/ F L! @2 B
(heat, new Selector (heat.getClass (), "stepRule", false));
1 ^# p2 Y6 ^$ ^ H( ?4 T } catch (Exception e) {, |/ U& [* B& O) a
System.err.println ("Exception stepRule: " + e.getMessage ());
' F; ~ |( z; H: L( G% g3 F }5 A+ e- y! l8 J$ l& a
5 v! V5 S& f8 B- {+ d
try {6 I2 \: t1 e, }2 x
Heatbug proto = (Heatbug) heatbugList.get (0);7 L3 d& n5 @, @- q
Selector sel =
) A/ E! x9 Z2 C D' U2 z: \5 s new Selector (proto.getClass (), "heatbugStep", false);
; s, M i/ f, @( p6 p% D actionForEach =
8 i2 l3 Z$ Y. j' u modelActions.createFActionForEachHomogeneous$call
# w+ \- O5 e. v: `3 {0 S7 [; A- W (heatbugList,# r* T9 A5 Y" X0 C) ? u9 v
new FCallImpl (this, proto, sel,7 T: a! K% a# g- x, Z* t
new FArgumentsImpl (this, sel)));
- g4 W; y% ?6 q" ~. Y7 n0 O( ~- w1 \ } catch (Exception e) {
3 X. h6 B! d& s; f; B" i3 `/ ] e.printStackTrace (System.err);' W6 b* s- R' N& ]$ U, H8 g
}) b7 s `$ n" e" _2 A7 G
: {0 m2 W9 C, C. [& ~$ X: B. M
syncUpdateOrder ();
0 Q, e/ V) \/ Q" i: |
+ s( Z3 c3 p2 o# P0 K# k try {/ t* t- k7 E1 L
modelActions.createActionTo$message 5 A0 |. O: A O }6 P
(heat, new Selector (heat.getClass (), "updateLattice", false));7 N4 Z# D I/ _: M$ z4 _( R3 ]( m
} catch (Exception e) {2 K( F( W5 u, U6 \- a1 i( C
System.err.println("Exception updateLattice: " + e.getMessage ());
6 a1 b- p& B, i# i& |3 E* s }
0 |3 \( @( `7 [1 J6 J7 L3 n; x
5 F! {8 v) k9 v+ t! N [' G$ y // Then we create a schedule that executes the2 X' ~, b- n- t' w+ h8 ?
// modelActions. modelActions is an ActionGroup, by itself it5 D# M# n2 U o$ G, q
// has no notion of time. In order to have it executed in
6 C' Q6 ~( A- n- Y, H% p6 i: D; P* b2 y+ t // time, we create a Schedule that says to use the
- J- Q! H% o0 Y- t0 b' x% f' r4 h // modelActions ActionGroup at particular times. This7 ] }# {6 _; d7 U9 q
// schedule has a repeat interval of 1, it will loop every
) a3 @9 Z3 R% C$ M // time step. The action is executed at time 0 relative to
- P. }% U. k8 a; G, E1 @ // the beginning of the loop.
; k! Q! b9 [+ W) I4 Q0 R% d3 s3 q A
// This is a simple schedule, with only one action that is
4 V8 N1 S; {( y6 Y( N; D // just repeated every time. See jmousetrap for more( C) s# S" I: Z2 q# S2 u, Y- b/ ?
// complicated schedules.& \: B/ `2 D: E; |8 c& c
7 F( e: q$ m" J6 D2 R6 @
modelSchedule = new ScheduleImpl (getZone (), 1);
) A, E2 r" D' z8 k& }1 b modelSchedule.at$createAction (0, modelActions);
4 ~0 y! k$ y4 E* R+ D, J3 m0 J L* p ' o K; V1 z' \1 ?+ W. D4 Z
return this;% J' n' h6 W) m* s( H7 D
} |