HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:8 u. |, l3 ?: w- [& P0 \
5 C0 h2 j2 V+ C, E& H: c
public Object buildActions () {
W: e' [. C* i# Q super.buildActions();
6 i9 K, y; A1 k$ k! o' c4 w9 L
) b8 W5 U1 I; g4 X# [& J // Create the list of simulation actions. We put these in8 U; Q' _9 t- @
// an action group, because we want these actions to be
/ {) r/ X" A: g) m% R' c' j // executed in a specific order, but these steps should" G3 m$ I* W6 |" K! v1 i
// take no (simulated) time. The M(foo) means "The message
5 C' G! {) _. [, \ S // called <foo>". You can send a message To a particular
4 b- V$ v$ @9 }- q1 L // object, or ForEach object in a collection.
2 }- t# D; F+ ~' a5 s+ Q
6 L6 L( ?$ |9 K5 u4 e: E // Note we update the heatspace in two phases: first run. W5 P# i# s, P* u; B; w
// diffusion, then run "updateWorld" to actually enact the6 d3 `3 A2 E5 w$ C( Q" a
// changes the heatbugs have made. The ordering here is+ J5 a7 Q( }* I* `) R
// significant!+ u) Z. Y0 k3 s, V$ ?
; ?( i/ {2 p" s- X // Note also, that with the additional
3 v0 q) }! S. [' H: ` // `randomizeHeatbugUpdateOrder' Boolean flag we can+ N9 \9 M3 I( `: e) i" Y0 T
// randomize the order in which the bugs actually run
- I3 T# y+ e5 w# y& e& e& J+ g% F // their step rule. This has the effect of removing any/ Z$ E: w/ n5 n0 b# x
// systematic bias in the iteration throught the heatbug _: w" g. K! u% Z7 ]
// list from timestep to timestep
# P# I, m0 R" A$ ] , o8 Z3 h6 M7 O6 N4 v1 z
// By default, all `createActionForEach' modelActions have
. h1 Y F! B3 Y8 ^, r( P6 o T8 u: D // a default order of `Sequential', which means that the& D: R$ z; p' P0 W( H5 X! a
// order of iteration through the `heatbugList' will be
8 T7 H+ l! M' B) P* @: R7 L // identical (assuming the list order is not changed
0 C: K$ V% q5 s5 S // indirectly by some other process).
2 {* ?: R; t6 l3 i. Z+ m1 b* ~ , _7 G" d1 u! G/ @$ W
modelActions = new ActionGroupImpl (getZone ());% C- Q5 I, ~& o& T+ r* Y) J
" w3 L9 w1 q- o
try {9 [. X: S4 H$ x$ I
modelActions.createActionTo$message0 G& Z" U n2 h4 Q! f
(heat, new Selector (heat.getClass (), "stepRule", false));8 {, @) _0 s; W( `. s# m
} catch (Exception e) {* s) ?( Y( ]. `
System.err.println ("Exception stepRule: " + e.getMessage ());( W* u& @+ R, b5 V) r6 J0 s! c
}
# `. e8 M' [( U6 ^ s: {# K4 J0 J! E5 w
try {& }+ j3 H" T3 ^( {0 \0 ]2 e
Heatbug proto = (Heatbug) heatbugList.get (0);
/ n7 q$ \7 ?: }. m Selector sel =
" }6 q9 _, e/ w. e( G new Selector (proto.getClass (), "heatbugStep", false);
p2 e% J0 A2 V actionForEach =5 r* S' N6 V# P' t/ @
modelActions.createFActionForEachHomogeneous$call
0 P$ u1 V& g4 `8 l (heatbugList,$ S. @+ |; s- G* a' l* x( g. h: o
new FCallImpl (this, proto, sel," j+ }: a( G7 o
new FArgumentsImpl (this, sel)));' a q0 [ @! f/ n( C9 z* |
} catch (Exception e) {
, @, ]( N2 v1 l4 O @ e.printStackTrace (System.err);* b" A: ?7 n/ Y* K* a
}4 ^9 ^3 z) m) f- `( b: k+ ?
/ W5 v' Y5 D5 t5 }6 u2 [
syncUpdateOrder ();
8 M/ z' \" N" j2 y q8 T
% K" x: C8 r# g1 B try {
: j p" F4 ]2 n0 D5 J modelActions.createActionTo$message % f! k4 I" b' F; Z4 \
(heat, new Selector (heat.getClass (), "updateLattice", false));
+ [) S+ O# C6 N } catch (Exception e) {( [' B3 @. I- j9 ^' ^* c# f
System.err.println("Exception updateLattice: " + e.getMessage ());
/ s( l6 d0 E7 x, G6 T }+ t6 L) q+ u$ q" u
; f( I1 h' b1 u+ [# E$ v5 b
// Then we create a schedule that executes the
$ h( r% O3 L5 p% x/ h, G/ v, e // modelActions. modelActions is an ActionGroup, by itself it
) J6 R$ s2 j. Q- i // has no notion of time. In order to have it executed in
: u3 e5 Y4 d$ V( m' R0 X' d- O; {1 S // time, we create a Schedule that says to use the
+ ?& m- q. w; Z/ L // modelActions ActionGroup at particular times. This) l0 U5 N( ~' P/ Q; V% ~. k
// schedule has a repeat interval of 1, it will loop every. A; a, X; l9 s) y1 R H: p M" S! E
// time step. The action is executed at time 0 relative to
- B4 m/ o% P' u& }( D1 C0 \( P7 ^ // the beginning of the loop.
- A {: B4 h" \: z: [" C" F$ v) j, }* y$ g. F# Z
// This is a simple schedule, with only one action that is# d( }; k5 l6 B) k }6 t& ~
// just repeated every time. See jmousetrap for more1 O6 T8 M1 d2 F5 U
// complicated schedules.
. W- B+ V4 x. }' s , o" T4 a3 l/ W9 y- z1 l* b; z4 C" K
modelSchedule = new ScheduleImpl (getZone (), 1);0 ]2 }6 V2 f- {* ^+ S6 S
modelSchedule.at$createAction (0, modelActions);
# S% L5 ]- d8 G$ }$ ]2 }# P) d
7 E, `9 W! z; ]3 v0 W& J2 T return this;! y' y$ K0 M9 t6 u& z
} |