HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
' @; o- G- U" j/ m1 x+ B1 {% B9 ^3 A
public Object buildActions () {. s" C* k9 G1 f( |$ ]0 X* \6 \
super.buildActions();
' R% e) \0 H/ J) w
( t8 t6 x/ g! B, f: {& ^) r! r // Create the list of simulation actions. We put these in9 _: a# J7 F8 _
// an action group, because we want these actions to be
& f! v& ?2 P9 L" l: L // executed in a specific order, but these steps should
& i! O/ a! Y3 b% X- Z // take no (simulated) time. The M(foo) means "The message. h5 Z1 D) N) v/ Z- V9 [( y5 {
// called <foo>". You can send a message To a particular
2 Z* b" W8 }2 e, W, S) V // object, or ForEach object in a collection.
4 E+ A5 o6 f) m" |/ v
0 _. A0 f/ G# `1 W$ Y. E // Note we update the heatspace in two phases: first run6 A! |6 o3 {, {$ Q( b7 H
// diffusion, then run "updateWorld" to actually enact the( h# {4 c. W7 Z$ _, v! c
// changes the heatbugs have made. The ordering here is
# ^/ Q. v3 N% C2 o: m- l- k // significant!- f' a8 P! i$ z, a
/ A3 K& t& ^- n% J // Note also, that with the additional/ d. t% ^+ k/ m6 I ~+ X- v
// `randomizeHeatbugUpdateOrder' Boolean flag we can
( d) q+ V0 R9 B. e // randomize the order in which the bugs actually run
/ P" W0 T$ M1 |. Q // their step rule. This has the effect of removing any
6 M9 w9 G( \3 }. L/ c H: H // systematic bias in the iteration throught the heatbug
) ]& _+ }8 c( A // list from timestep to timestep
5 b* ~7 A/ N+ r" k J$ A * q7 u; j0 B. r9 Q
// By default, all `createActionForEach' modelActions have
. [# \7 Z5 R2 X1 f* d$ T // a default order of `Sequential', which means that the8 o0 B5 @& q5 j% H
// order of iteration through the `heatbugList' will be5 \, ^, V# F0 I) |7 \: z+ G
// identical (assuming the list order is not changed
6 F; F+ u: l4 K) V- h% \ // indirectly by some other process).! W s. X+ s9 v, F O/ H% E) }; X
4 A8 f* B/ l2 u1 w" f) o5 m1 g0 f modelActions = new ActionGroupImpl (getZone ());% h- J, F% T! R( I# z
( u* \: C! o4 ?
try {
9 O$ g: s" x% U modelActions.createActionTo$message
, D2 b/ p9 r S' l (heat, new Selector (heat.getClass (), "stepRule", false));) b4 t" G ]" C! ^8 a+ X4 c
} catch (Exception e) {4 F- a3 F |, i7 Q* i2 E6 R
System.err.println ("Exception stepRule: " + e.getMessage ());' {, S! `1 D! D, v3 M: r8 L
}3 E6 A- b! g) B8 t
# c. L) L9 U# b3 X9 i+ {% q try {5 @# b6 t7 A, V( g4 }* T0 G
Heatbug proto = (Heatbug) heatbugList.get (0);& N. X+ L/ Q. x Q( w) q5 B
Selector sel = ) `0 R* `( ]% b/ Y1 d
new Selector (proto.getClass (), "heatbugStep", false);
+ L1 I4 y" Q2 ^/ H$ G% S; w3 G actionForEach =
, M# f, Q8 X+ r5 P. Z' S+ K" I2 s, q modelActions.createFActionForEachHomogeneous$call5 t( v$ ]" E: k9 |+ i! b
(heatbugList,' r/ A* ~& ]8 _; D7 g( b+ W% w. V; i
new FCallImpl (this, proto, sel,
1 V9 b O' n3 C new FArgumentsImpl (this, sel)));2 H/ m" H3 A) h- l' P5 i
} catch (Exception e) {
6 }: l4 I5 {3 s9 M5 {" E, a e.printStackTrace (System.err);
, B: i2 e# U) x* _) J! _# g o7 \ }
& |$ L5 `! ~+ m0 ] O
8 z0 Q5 s5 N+ n5 N syncUpdateOrder ();- J9 c" @4 f1 S8 F9 F1 V
+ R3 W: [3 y1 n
try {" W& m# C/ y) P" ]6 c; N* S7 {$ y
modelActions.createActionTo$message 8 G0 e7 r2 m0 x3 t% u
(heat, new Selector (heat.getClass (), "updateLattice", false));
6 @4 A* d& T1 s. M& U9 o } catch (Exception e) {' A9 g' V- y: I8 P0 A3 T# V" V
System.err.println("Exception updateLattice: " + e.getMessage ());
6 c9 }6 }4 f C X }5 ?4 G$ s7 {& k! r; v- K
4 \1 T8 k# {2 V" w9 D
// Then we create a schedule that executes the- e- u* E1 C, F8 n, Y' F
// modelActions. modelActions is an ActionGroup, by itself it5 O- @% f! g0 F/ Q0 }
// has no notion of time. In order to have it executed in5 A- `; T- F) u, ^/ h# T% Z0 y
// time, we create a Schedule that says to use the1 p# t p, F7 o$ z1 Y' k) X2 p; S
// modelActions ActionGroup at particular times. This ^1 {% {' g6 g
// schedule has a repeat interval of 1, it will loop every* T3 m p! I, T) }* B% j9 M
// time step. The action is executed at time 0 relative to: i9 \" c% r/ r9 s3 E5 b# k& m Y9 Q
// the beginning of the loop.5 Z1 `/ F7 ]& ~
# k9 k( ^3 [: O7 O1 I0 T/ F
// This is a simple schedule, with only one action that is
5 n1 R/ Q- |5 t; ? // just repeated every time. See jmousetrap for more
' {9 B6 s# G- P5 ?- x$ j. S6 m& ^ // complicated schedules.+ N9 D5 P/ N1 @
2 ]* Z" i7 B% W7 v8 ~5 z+ ?2 C
modelSchedule = new ScheduleImpl (getZone (), 1);# N( @# S( f1 h
modelSchedule.at$createAction (0, modelActions);2 S8 @9 V0 v) u7 P7 E& J' v
4 g! k, t$ H3 v* } W Z3 ]% b5 D
return this;! U7 O# |9 ]* s' E
} |