HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:5 @. i/ Z5 @ x7 T! ]6 H
: z% g* l+ i- b6 \( @7 g7 P' M
public Object buildActions () {
/ r& T$ u U( \/ o) x super.buildActions();
. H" w* F' E, r7 S
+ K+ A7 f( E5 }1 |" l% K // Create the list of simulation actions. We put these in9 W ^/ X6 a1 N2 O! P$ i6 r
// an action group, because we want these actions to be
* Q4 @ T' d# B // executed in a specific order, but these steps should$ e" C" [# ^- u+ M6 g
// take no (simulated) time. The M(foo) means "The message5 H+ \7 ^% A4 T0 s
// called <foo>". You can send a message To a particular4 ^$ G, { m) p3 }7 N
// object, or ForEach object in a collection.
5 I% G7 b9 A4 |( b6 P + o+ h j3 U2 k6 W/ k( l
// Note we update the heatspace in two phases: first run4 q; U# N( c1 |6 S% Z( X8 @
// diffusion, then run "updateWorld" to actually enact the$ _' w$ {/ Q8 {, x, r) g
// changes the heatbugs have made. The ordering here is: I3 \6 I8 L, H$ _8 Y/ b0 V
// significant!; ?$ d+ A* n0 O' @7 `2 q w, f' q& [. Q
5 l% R1 ^6 P3 z8 a- _! Y' d+ f( A2 o4 F // Note also, that with the additional) \$ u! q! t, i9 G# b. S" ~
// `randomizeHeatbugUpdateOrder' Boolean flag we can) f# t5 B ]+ P% R8 y6 {6 C! r: _4 b
// randomize the order in which the bugs actually run
* u: e. ^- ~/ |. z // their step rule. This has the effect of removing any8 ]3 ^2 ?- f0 Y, B
// systematic bias in the iteration throught the heatbug
( U1 c3 ?* [% i% ?) B' [8 s // list from timestep to timestep2 l, d1 V3 T z K6 L9 H
$ S8 e- r6 D/ n7 @2 Z% ^$ y/ T' a // By default, all `createActionForEach' modelActions have1 ]7 |0 q/ E% \- u6 U
// a default order of `Sequential', which means that the
! U, B! ^8 M, W5 S2 v' ~ // order of iteration through the `heatbugList' will be
8 O* M7 f4 m1 a7 m) }: R/ Q! K // identical (assuming the list order is not changed: m( l0 r& m6 c. n% _
// indirectly by some other process).
8 k# x: n- D, k: o t$ S2 x & h% Z+ l. d" H
modelActions = new ActionGroupImpl (getZone ());
1 }" ]" s- @6 A5 ^" x' @" g3 A$ o1 L- H: U" ]; k: c: g. {5 @
try {! L' V, E6 _. ?, \$ p7 R
modelActions.createActionTo$message2 i2 Z3 N; ?$ G% e
(heat, new Selector (heat.getClass (), "stepRule", false));
+ x, I3 S. w: ?, q4 x1 A } catch (Exception e) {
+ b7 K! J8 F4 i, G. q System.err.println ("Exception stepRule: " + e.getMessage ());
* V6 Z1 L6 \* v4 s, T }
, ]4 I3 P2 w2 f9 L. G" w" W7 C p) ~: F ?+ `- a0 V
try {
0 |# t4 F! Q% Q5 H: j Heatbug proto = (Heatbug) heatbugList.get (0);8 F& t, ?. d" L" J& p- f& }
Selector sel = 3 |! h, t& ]; D0 u% r
new Selector (proto.getClass (), "heatbugStep", false);7 U/ G. u, l3 M% n! E# u M
actionForEach =
G! ]7 D' R3 j7 o4 {! c9 f modelActions.createFActionForEachHomogeneous$call3 y7 w) Q/ E; d/ g5 \6 |6 L
(heatbugList,
7 D8 L" Y! u6 U( b! } f new FCallImpl (this, proto, sel,8 p" o. k6 S7 f
new FArgumentsImpl (this, sel)));2 @ G5 x% [3 U" O+ f. {0 S* r- C
} catch (Exception e) {2 \/ {$ U Q# S" x8 Q" t) q5 J3 G
e.printStackTrace (System.err);6 r& E( _$ }: l
}
- d) e) H* D: A: Q' x# Z; A4 |5 j 2 N; s. B; N3 T7 X
syncUpdateOrder ();: w }( l) F: ~' L* Q, g
2 V+ p" N# L" ]% x
try {3 v$ v# g% d$ V x& N
modelActions.createActionTo$message
( E( g- X! l$ d# a (heat, new Selector (heat.getClass (), "updateLattice", false));
i* U% Z2 i8 P- `/ W# `/ c } catch (Exception e) {0 Q8 e; U: z' ~5 s
System.err.println("Exception updateLattice: " + e.getMessage ());) |" I4 n- j3 r* h% |: _7 e/ |
}$ f3 c$ I x3 f- {
( ~* C c! w8 [' ~3 {
// Then we create a schedule that executes the9 n9 s5 j. A1 T2 f
// modelActions. modelActions is an ActionGroup, by itself it% p b/ L- c3 E2 Z
// has no notion of time. In order to have it executed in6 i+ U& s0 u! _
// time, we create a Schedule that says to use the
# A7 V2 Z7 r8 h1 v7 }; q' j // modelActions ActionGroup at particular times. This' o. k+ X3 b7 W
// schedule has a repeat interval of 1, it will loop every
: b6 ]& f6 P; d9 X$ N, G% I // time step. The action is executed at time 0 relative to3 x$ s/ @9 K5 f( N5 |3 N M* Z
// the beginning of the loop." \3 I' f$ i4 u2 z2 F' Z2 s
. _4 t/ V) K# u. W3 K // This is a simple schedule, with only one action that is. i8 x% p( I2 ^5 o; u7 e- t
// just repeated every time. See jmousetrap for more
+ [$ J" O. Q8 z% W' G5 x // complicated schedules.2 P M8 f( M6 P) N1 o+ m1 L
/ r9 G7 Q3 v1 h: A+ }7 j0 E
modelSchedule = new ScheduleImpl (getZone (), 1);
% }* ]$ l9 R' l4 i+ s modelSchedule.at$createAction (0, modelActions);
. a! D4 d! X# ?, }) U) C( P
+ K+ ~* }3 w7 m% L7 U4 O# [6 u return this;4 J2 [% E/ c$ u7 @
} |