HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
, C6 G: c% i5 o* s8 s1 @( I0 V+ G7 \& z B }3 _
public Object buildActions () {1 @: r K4 W& T2 a s3 t
super.buildActions();: k, o; W7 b% }/ ^$ a7 G
3 Q7 O" v9 D, |1 e. l // Create the list of simulation actions. We put these in% {' ]- U: M+ r( d8 s) g
// an action group, because we want these actions to be, F0 {, \- A; S/ I; c4 v8 H
// executed in a specific order, but these steps should
" w1 T: y9 j! o. a: r) j // take no (simulated) time. The M(foo) means "The message
3 s A+ e; o# s! r) R+ l! ? // called <foo>". You can send a message To a particular
+ h h8 o; i W( ]7 K$ M // object, or ForEach object in a collection.3 b9 {0 H- ?3 h+ g% u& _
' u8 V# ^- M5 U
// Note we update the heatspace in two phases: first run4 q0 J3 ^4 n1 W( ?
// diffusion, then run "updateWorld" to actually enact the+ Y% `4 f: R& k# l! V0 P: g* b
// changes the heatbugs have made. The ordering here is
# |' H4 Y5 M0 Z' r9 S1 |, J V0 L Q8 t0 A // significant! S- p. W/ f" \9 ^; Z3 f" K
F% ]1 w$ u0 I5 l9 U" G // Note also, that with the additional
5 Z* c8 A* c `0 C9 |5 i& | // `randomizeHeatbugUpdateOrder' Boolean flag we can
! _) b" M) N% b! E1 ~* o$ r5 Z! x // randomize the order in which the bugs actually run
; Y3 J" T# x# W; K- y5 i4 j( z% d // their step rule. This has the effect of removing any
& ?( b, L% w1 [, c // systematic bias in the iteration throught the heatbug
# Q5 |, d) V) s7 u" N3 x // list from timestep to timestep- ]/ {: Z% Y; t, Q
4 r2 }5 _4 s1 P. v5 O2 J! ^ // By default, all `createActionForEach' modelActions have
" m r4 }, F" G' t // a default order of `Sequential', which means that the0 H% c, L" Z4 B b
// order of iteration through the `heatbugList' will be
( \+ m0 V5 r' o1 E" c1 P: q: h // identical (assuming the list order is not changed
: S6 x8 X+ O1 ]( e& S* a J // indirectly by some other process).
- X! p1 d$ V6 v* S
9 ~' V z4 b6 F$ d, }. R3 s0 |. v modelActions = new ActionGroupImpl (getZone ());: w# z: D! b3 U. X R2 T
$ {% L1 U% N z% v
try {. H+ R8 v/ ^& h9 s* [8 K |$ J
modelActions.createActionTo$message S! ?9 L$ r1 ]% J4 T4 H" ^
(heat, new Selector (heat.getClass (), "stepRule", false));
0 y+ i% ~5 _; V9 ~9 q% F } catch (Exception e) {5 n- Z7 Y. H9 ? U
System.err.println ("Exception stepRule: " + e.getMessage ());9 Z; i5 g! e9 q v# M% l
}
( p# A6 {2 a' o! l; F4 z: \9 z8 L$ n( Q0 m2 Z, ]- Y
try {
0 Z2 Z" @5 e1 [% p/ U. v$ B% W Heatbug proto = (Heatbug) heatbugList.get (0);
+ b9 e: d4 e/ t9 e+ E$ s Selector sel = 2 ~* @4 r6 H, U! }, a- d& A9 W
new Selector (proto.getClass (), "heatbugStep", false);2 B( j1 [+ Y. n$ J5 N& U
actionForEach =8 R! P" R) j0 _: ^
modelActions.createFActionForEachHomogeneous$call/ I% M" @# K5 h+ C' @. M% D1 o
(heatbugList,+ M$ P* W: s7 C# E
new FCallImpl (this, proto, sel,
9 t! d8 S% V z+ h' X new FArgumentsImpl (this, sel)));
7 Z3 ?. L; B, ^2 n& D( o } catch (Exception e) {
. p+ d+ V5 l$ w7 J0 J" g5 ] e.printStackTrace (System.err);3 v+ Z8 C0 y- P
}8 | ? Y" Q. s! v, `
( Y; e! Z) b% E: U& s$ Z. S syncUpdateOrder ();; n9 R7 M4 _$ e8 d' r) c4 Z9 n
" X) S4 F( u% x try {& V) c/ h& y9 ^& q: N
modelActions.createActionTo$message
; {% M3 N, b5 { (heat, new Selector (heat.getClass (), "updateLattice", false));3 ~/ L4 e- w2 P0 K) E/ D
} catch (Exception e) {
2 a7 [) ~0 h, [ System.err.println("Exception updateLattice: " + e.getMessage ());4 b# ] q0 {1 G5 g
}. m1 }* O9 [1 h0 N7 g, T
. x0 _) G6 J N) \/ Y! { // Then we create a schedule that executes the
0 W: B6 [+ p2 ~; h4 U g# S% Q2 ^ // modelActions. modelActions is an ActionGroup, by itself it
]6 x Z* [2 {0 I# q# ?; l U // has no notion of time. In order to have it executed in
, @9 U, [$ ^. J2 O, R( H( g // time, we create a Schedule that says to use the/ W/ U+ Q6 P; G8 t3 w
// modelActions ActionGroup at particular times. This9 E4 R5 H8 k' m' j# V
// schedule has a repeat interval of 1, it will loop every2 m1 _( O3 k0 ]2 F. C
// time step. The action is executed at time 0 relative to
( c# Z* _% l+ {, I8 k // the beginning of the loop.
( d a- h T6 D2 `% e
; R+ A: g; n! Y1 N3 I5 M // This is a simple schedule, with only one action that is
6 J7 b5 e( d1 x+ _: c4 T // just repeated every time. See jmousetrap for more) K, t2 J( }+ H: u$ }& D$ M) m
// complicated schedules.
- U: K* ^3 j1 H5 r& \3 M( g
/ A3 G: V0 X, k modelSchedule = new ScheduleImpl (getZone (), 1);. d8 K- K( @% F% v
modelSchedule.at$createAction (0, modelActions);
* X+ p8 |8 J6 p$ D, l; O1 e. j
/ U- A9 |. J5 C return this;0 p9 ~. b7 u+ o- a
} |