HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
, ]) B( [4 ~( c) m- @
f( h. X: x* w! ]2 { t9 c public Object buildActions () { ] U% r! @& @2 `. w/ s8 j
super.buildActions();
3 G! D, c# q% o+ \! c . S$ V* v: a9 U# P# {+ @) t
// Create the list of simulation actions. We put these in
+ B) b' \$ |' X; W1 V // an action group, because we want these actions to be
& f$ U o/ `! k7 ?. P0 R // executed in a specific order, but these steps should
5 y" R+ C: q5 _ // take no (simulated) time. The M(foo) means "The message9 t( ?! [ s+ |" m
// called <foo>". You can send a message To a particular1 ]2 d9 @5 Q" h+ l# `
// object, or ForEach object in a collection.* g+ n) L9 G/ ^3 m% q3 _
( l3 x! T2 L8 x, o# H2 b. G7 ^& O
// Note we update the heatspace in two phases: first run1 z6 _9 z1 H. |* k+ J+ B6 m* R! ^# p
// diffusion, then run "updateWorld" to actually enact the
, p) O) }6 A% x$ v. k0 B3 K# n+ l // changes the heatbugs have made. The ordering here is
0 h# p. b' z C2 l+ q3 C // significant!
C3 A3 L' T! _ + m9 w/ Z$ ^; ~' {+ ^
// Note also, that with the additional5 t/ ~# a/ X. A, U# h; g0 L
// `randomizeHeatbugUpdateOrder' Boolean flag we can, x9 Y) x* r1 w8 {; s
// randomize the order in which the bugs actually run0 s3 f/ f8 c7 }2 {
// their step rule. This has the effect of removing any+ E8 K- E* M; U) \1 L, T: Y
// systematic bias in the iteration throught the heatbug
' g3 T- J! Z& _% L& t6 g7 r) d, t // list from timestep to timestep
1 T$ \5 p) W$ V! j) P4 Z 9 t% @) Q2 s, _- o6 F
// By default, all `createActionForEach' modelActions have
; f7 v5 z/ l- b: u9 |; _4 Q // a default order of `Sequential', which means that the' e$ Z r9 ~# e; _: C% W
// order of iteration through the `heatbugList' will be* Y% L; ^9 L F* B; j7 R
// identical (assuming the list order is not changed% r8 g/ S0 X6 C0 K. o# d+ ^
// indirectly by some other process).! C8 I! c4 D4 l) k8 n( P
' n- e# J7 M3 _2 |. c4 }4 H modelActions = new ActionGroupImpl (getZone ());7 @2 V3 H z* u, |1 P+ d9 ^( O
' L7 B9 I) _. A4 W. g* f
try {; u7 e6 X' t% F4 V: ~: {
modelActions.createActionTo$message
; @9 X* r& b4 }0 Z8 a0 v; B (heat, new Selector (heat.getClass (), "stepRule", false));
4 E. h; `- h( ]9 G2 H } catch (Exception e) {% o L' \$ b8 |, R6 f+ w* i0 i
System.err.println ("Exception stepRule: " + e.getMessage ());
7 X. Q# H& V7 l. U3 _ }6 z* ?; S3 L! p7 f2 |, Y
* p6 l4 @' U! e* X, T( U8 W try {
" A) ?7 `' Z, k5 w0 L6 M- T* h' k; j Heatbug proto = (Heatbug) heatbugList.get (0);
; G! d) l# u7 A/ F: K Selector sel =
$ W- }1 [9 ~4 Y2 Z% Y' ` new Selector (proto.getClass (), "heatbugStep", false);
+ @5 M# G4 A4 o3 l4 h actionForEach =
: g+ i6 J F7 x3 a3 e# ~ modelActions.createFActionForEachHomogeneous$call
5 Z! Y$ ~( {6 S8 E: Y0 k (heatbugList," Z8 ?2 c9 W( W! B3 f5 f- r& ~: K
new FCallImpl (this, proto, sel,
2 {( v8 k4 E, m' q7 E; K new FArgumentsImpl (this, sel)));! w, `% {% K5 k: j' o/ u/ n& h- C/ h
} catch (Exception e) {0 m6 a& T1 O, B
e.printStackTrace (System.err);
* [3 Z7 C! f) z1 S1 l; J# B- f }- b( K1 A: O& v
6 }* R9 t) ^) i9 j
syncUpdateOrder ();8 y, U: ~) k- V# f, f
# _, e# B0 _ }# w, }0 T6 l try {5 Y/ P; Y) D! F z* W
modelActions.createActionTo$message % W$ l6 K( c v
(heat, new Selector (heat.getClass (), "updateLattice", false));" |; r9 K8 `/ {4 r& D! _
} catch (Exception e) {
5 }; R! y! ]& u/ G) m& L$ W4 K8 l System.err.println("Exception updateLattice: " + e.getMessage ());
* ^2 k) |2 L. S% V7 Z1 @5 s* b7 [ }4 i' ]/ c. {$ Y' t( `3 X& r
2 N, R( q4 O" E
// Then we create a schedule that executes the
3 j3 Z+ C3 o0 J! N" g* W // modelActions. modelActions is an ActionGroup, by itself it
! ~9 H: A8 _8 Q; U4 ]- D // has no notion of time. In order to have it executed in% R3 v: S' {# n9 ?$ F" a# B i
// time, we create a Schedule that says to use the7 L; u4 P% i m! @& }. o' @
// modelActions ActionGroup at particular times. This
) @* D. Q' S) A5 w1 [- z; r0 X // schedule has a repeat interval of 1, it will loop every
9 W0 C- [' |0 f0 ` // time step. The action is executed at time 0 relative to$ F5 M T3 m7 x" [3 x
// the beginning of the loop.4 g& w! Y! D c, F0 L
, r& c9 w6 z% `7 x7 m3 Q* F // This is a simple schedule, with only one action that is
9 ], Y. d2 V" Q, ~& A9 k: } // just repeated every time. See jmousetrap for more
7 c0 E3 g3 j* |, c& o; p Y' | // complicated schedules.8 P. V$ H3 b2 z* M/ _# p; D- e( l
0 w8 W+ P' k( @, Y, R$ z8 T
modelSchedule = new ScheduleImpl (getZone (), 1);( I( W+ F/ T v1 ?1 }
modelSchedule.at$createAction (0, modelActions);
* F% D% u/ Q5 R- n+ F + `; N U% ]# y# O0 a0 `1 b6 K3 K
return this;
0 |- ^4 W5 o6 ^3 N, A9 z } |