HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:% Q& a8 c' t& t$ o: D! I5 f2 b
4 ^4 _/ A. ]6 { public Object buildActions () {7 t; P$ Y V" _; A1 c
super.buildActions();; M1 ^- B$ V. r1 r5 D( O
7 y, N4 d- j4 O! {6 C // Create the list of simulation actions. We put these in
# m6 |$ e3 j) q: ^* Q+ C8 B+ n // an action group, because we want these actions to be
' Z' | K) P9 x: w _+ p // executed in a specific order, but these steps should5 p* t0 X; ?7 r0 E- h- I
// take no (simulated) time. The M(foo) means "The message
u% j2 F1 T7 @- | // called <foo>". You can send a message To a particular/ i! y, ]1 }4 d
// object, or ForEach object in a collection.3 p4 }2 o5 S; ]2 x) \7 e, ^& G
5 O: n' v, Z' w5 d6 e9 g+ \; R
// Note we update the heatspace in two phases: first run
4 j3 ~1 C% x# y- _ // diffusion, then run "updateWorld" to actually enact the# w$ C$ u( w! P2 @9 q
// changes the heatbugs have made. The ordering here is. l( j' u6 ]1 N3 v/ ~' L
// significant!; T% T7 R6 M: \6 `. F4 z
" R$ ?0 z+ S9 }6 f+ z
// Note also, that with the additional2 f$ T P! _3 w' b$ K: j; a% v
// `randomizeHeatbugUpdateOrder' Boolean flag we can& y: o! k, Z* G
// randomize the order in which the bugs actually run
2 k* Y7 |. i' R5 d5 x& I // their step rule. This has the effect of removing any! {9 T7 p1 N" u4 m+ h! f
// systematic bias in the iteration throught the heatbug
- M# y, Z; n8 I- b8 J; V8 e5 }( W // list from timestep to timestep
9 C5 V% ^- m: k* C ; J. J8 Q+ b# o3 K% ~) H9 Y/ `
// By default, all `createActionForEach' modelActions have
- r, V* U5 i3 k% |% G9 {& c' w // a default order of `Sequential', which means that the9 h/ {; l9 Z* D2 g/ m
// order of iteration through the `heatbugList' will be
, W a! a4 b3 w7 W* N // identical (assuming the list order is not changed
! q& t; O/ Q4 g // indirectly by some other process).
' N- x# F2 E4 j8 N/ @- _, r* R3 n : I# [. q" ~# {, V& p; Y7 U
modelActions = new ActionGroupImpl (getZone ());
0 x* i5 F$ e" D1 Q2 Q) A8 o& h& _! s4 p
try {& H/ `+ i/ X& w% j6 _0 B
modelActions.createActionTo$message( v" r4 j; d! h; ~9 M6 ?" X
(heat, new Selector (heat.getClass (), "stepRule", false));
4 ^ `& h D( q2 j8 L } catch (Exception e) {
4 ]# Q: \7 V- i9 o. W System.err.println ("Exception stepRule: " + e.getMessage ());
9 N& n8 V+ e% X! H; f" s& v }
& b, H4 L% Y0 F; t r
8 ^* c$ o& [* U- V) w8 E try {+ M4 V$ s" j1 q1 G& ` f4 |
Heatbug proto = (Heatbug) heatbugList.get (0);
O# q. C) |1 j Selector sel =
; d- K8 Z$ e; s) o6 Z' \6 @ new Selector (proto.getClass (), "heatbugStep", false);
" d# t5 Z( ]3 ]: I actionForEach =
: `5 r' G5 P! D8 Z8 _( _ modelActions.createFActionForEachHomogeneous$call
F7 ^$ I( c" N% y- E (heatbugList,
% p7 v: O, E2 s- l( _8 e3 N new FCallImpl (this, proto, sel,
6 T1 ~) x. ~0 l' I! [" D" R+ v new FArgumentsImpl (this, sel)));
+ p2 D+ p8 q8 q0 o- n2 _ _ } catch (Exception e) {
) u$ q* k7 w6 @3 D$ h5 c e.printStackTrace (System.err);$ Q7 `$ n) E4 H
}& S" _1 p. S/ G# }
1 e4 N$ G7 z6 z% _ syncUpdateOrder ();
) y8 V% V' q" [4 \! H5 B4 q# { w, _% y, u; Q
try {
5 [ o6 J5 I+ D& X* i- i6 M modelActions.createActionTo$message
7 u& G8 b5 v4 W% N/ y T Q/ P5 f (heat, new Selector (heat.getClass (), "updateLattice", false));
/ ^, J# T$ L% a- c- b- B } catch (Exception e) {# y) u' m+ u" ]% e
System.err.println("Exception updateLattice: " + e.getMessage ());: q6 B% X4 s0 p6 J1 I2 ?" B
}+ u+ [# U# E* k7 @& R. X* j
# s l: T& E3 J' j3 u2 J3 E // Then we create a schedule that executes the
! h7 G b8 K- A& S: X // modelActions. modelActions is an ActionGroup, by itself it
! ]) ~1 Q0 @. O7 y# k- v // has no notion of time. In order to have it executed in
7 v- H, \8 F4 z& v! R( S // time, we create a Schedule that says to use the
( s' h5 ?2 _& ~1 q // modelActions ActionGroup at particular times. This
2 R6 p1 L4 p7 ~' ~4 ` // schedule has a repeat interval of 1, it will loop every
9 }9 j: s+ j& S/ | // time step. The action is executed at time 0 relative to) m. ?, L7 U$ O Z6 v6 ]
// the beginning of the loop.
1 O: H6 U; D* T I
' I1 f y% P& M, l // This is a simple schedule, with only one action that is4 m3 f3 o- S0 j
// just repeated every time. See jmousetrap for more- R# A' y' R1 ~
// complicated schedules.8 Y ~- Y$ z& a* ^2 D
9 m* W6 Z4 [7 v" r5 _4 r I
modelSchedule = new ScheduleImpl (getZone (), 1);5 d3 s" W+ }8 |; Z
modelSchedule.at$createAction (0, modelActions);# m2 x' d2 y* q0 ` \
9 X& L3 ]9 {- {4 O |4 o return this;
, `* X) a; M/ j2 v6 z } |