HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
- T7 r' e2 ~4 P* @6 l( R% f+ }2 b% I0 J) f7 w. r& r
public Object buildActions () {
0 q, f' o/ Y. U0 \ super.buildActions();( \" ]8 }' K6 C7 \2 d+ u
# j8 _- u3 ]+ i& K/ C X // Create the list of simulation actions. We put these in
1 j: Z- }5 R- o3 M: P% _ // an action group, because we want these actions to be
# l6 p# x# W) s; m2 | // executed in a specific order, but these steps should
" Z* g1 x& p2 q9 e // take no (simulated) time. The M(foo) means "The message
* [ u, X; I! \: i9 ~" C- n7 {" k // called <foo>". You can send a message To a particular/ p# l$ m' K+ a2 Z
// object, or ForEach object in a collection. k5 |: `7 p. |& A4 ~6 Z- K
! j9 F3 S; T" L( N% L0 Z
// Note we update the heatspace in two phases: first run- ]& \3 U, [: n* z X C) h8 K3 v
// diffusion, then run "updateWorld" to actually enact the: R1 @2 X: I4 ]7 l' }* m
// changes the heatbugs have made. The ordering here is
0 D4 y% k& m* L g3 C, K6 { // significant!
- R, r. E/ y7 g* k/ f
; T/ b3 D3 a( w2 E- C // Note also, that with the additional. N3 z. z6 l4 T; K9 O
// `randomizeHeatbugUpdateOrder' Boolean flag we can
2 H# W! l2 M* Q! l' g0 e3 \ // randomize the order in which the bugs actually run( K0 C& \/ \$ M% j2 H( x
// their step rule. This has the effect of removing any& h+ i0 [" m8 b5 j Z* P
// systematic bias in the iteration throught the heatbug% Z) g5 r; U2 A1 }
// list from timestep to timestep
+ ~* O5 P8 p4 |0 X: c) g 3 e) Y4 t8 r7 U4 E6 E0 A# T; n
// By default, all `createActionForEach' modelActions have: P- P4 o; P5 q! Q% s! x
// a default order of `Sequential', which means that the! T- Y9 Q9 K7 z
// order of iteration through the `heatbugList' will be, e1 U# w) n! E5 q% \/ H
// identical (assuming the list order is not changed
9 L2 s: P5 H* B9 G+ b // indirectly by some other process).* N! `* {6 x# q6 `: W5 A! p* M, H' J
7 O/ G' K2 @" M$ B3 J1 L modelActions = new ActionGroupImpl (getZone ());
. _& C# L/ `8 @$ B! `4 b- p5 y* Y/ L0 f+ K! P4 ~& H6 A
try {' x/ v$ ~5 D" F9 \% ?% m M
modelActions.createActionTo$message( H9 f6 |1 d1 F: y+ x" y
(heat, new Selector (heat.getClass (), "stepRule", false));" f/ _+ x1 I8 U
} catch (Exception e) { o7 b; d7 G$ i& p+ N! j3 ]
System.err.println ("Exception stepRule: " + e.getMessage ());
2 P) Z# o9 q0 K" G! R X } a1 x. n2 E4 s
! h3 y* `; P7 }$ }2 i
try {
0 T- }: v* e& r) m$ j+ }4 p" T Heatbug proto = (Heatbug) heatbugList.get (0);/ X+ o7 @: [# C# g j3 E1 f
Selector sel = y1 v1 }$ I& X
new Selector (proto.getClass (), "heatbugStep", false);0 q9 H g9 |) H% k
actionForEach =3 P1 I. P, m% a& v
modelActions.createFActionForEachHomogeneous$call ]+ _# }$ y+ O4 K& z% x
(heatbugList,% ~1 |! z' O8 W$ Y$ S5 [4 @
new FCallImpl (this, proto, sel,# r- N, b/ X& B. e; A
new FArgumentsImpl (this, sel)));3 p; _/ G# ^" P6 l
} catch (Exception e) {: s3 a- A6 o7 P
e.printStackTrace (System.err);
9 C9 l5 ~8 k/ |& O" C: Y8 X2 Q }
1 F0 z* n$ |2 Z * t" C# C9 }3 l5 m- R* N. |
syncUpdateOrder ();1 Z1 B5 R3 b2 I, o& l
: i4 U3 k( _& h8 y) T try {6 e# `$ }9 q/ s; h
modelActions.createActionTo$message
f" @ C2 u# j; S) O% T1 B- S (heat, new Selector (heat.getClass (), "updateLattice", false));
$ `( z! ^& Z- _ P/ ~4 j- U } catch (Exception e) { E" J( C+ k+ m4 L* z$ {. A
System.err.println("Exception updateLattice: " + e.getMessage ());
% ]" Z/ c% L: U" I }. ? s1 U/ k6 F* l- H1 L
7 O, T9 Y# r u" p6 E# h F1 ]
// Then we create a schedule that executes the
& n* O3 b1 r0 b8 y f // modelActions. modelActions is an ActionGroup, by itself it
5 j, X) ^, T' u+ H- J K* c9 G // has no notion of time. In order to have it executed in* e* l0 A e* b- J3 O( S3 r
// time, we create a Schedule that says to use the
" j9 Y \7 ~: ?2 Q3 h8 F+ o // modelActions ActionGroup at particular times. This
6 R" d0 e3 L a( D* y$ E0 s // schedule has a repeat interval of 1, it will loop every
% e0 B! v9 n4 l2 Q% o; O% }8 n% ` // time step. The action is executed at time 0 relative to5 |( Y4 A5 W, l. |5 R3 `! t% [
// the beginning of the loop.
0 M. z: |1 X2 J$ b; \, P0 F7 E
; b3 R% r! h9 u% b // This is a simple schedule, with only one action that is- n4 N- B* x9 \ j8 G# |
// just repeated every time. See jmousetrap for more0 r2 n2 s( T, J/ a5 `3 F
// complicated schedules.
0 O7 H4 g2 a- g/ g, u% H" M! ?7 O 1 K5 E0 B& c1 U+ r& f& z n, u
modelSchedule = new ScheduleImpl (getZone (), 1);+ s* y* A+ G+ S/ H
modelSchedule.at$createAction (0, modelActions);
7 [. F! a, X$ @9 w1 y& P" {: ^
2 b/ j. s, l. |8 \4 z# y return this;' O3 e3 u8 p# f- @
} |