HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
) ]* T. o7 Q- r' o0 O& g' e) W
1 H* h- p7 u8 J* T6 ] public Object buildActions () {
1 D3 d+ x, a' z, k, Y# h super.buildActions();4 H# f7 k* F+ ?! N
, m3 x/ X7 M% U# U- R
// Create the list of simulation actions. We put these in$ H: g9 g ^' K3 u( P/ M
// an action group, because we want these actions to be2 H" N+ e) W( {7 ^' L3 d; a2 z
// executed in a specific order, but these steps should
+ F4 }) p! d) Z9 T2 C5 p // take no (simulated) time. The M(foo) means "The message0 \+ L6 O0 O' `9 E% k
// called <foo>". You can send a message To a particular9 K2 {0 F/ \% ~& l e, N
// object, or ForEach object in a collection.
7 T6 f9 ]4 F" b9 ` / H5 j+ N% o* ~( v0 D
// Note we update the heatspace in two phases: first run
; P' @3 i& m) h7 R' s! v( L // diffusion, then run "updateWorld" to actually enact the t$ X! a( B# o& N/ h9 W$ y5 ?
// changes the heatbugs have made. The ordering here is
% X: Q) J+ j, t7 L, |2 V5 P // significant!
; ], @0 D. X. ?, } ) _) e1 t! J% l. P+ V" O1 W8 c, K+ @
// Note also, that with the additional
0 M8 d! A) T0 _' m8 e+ ? // `randomizeHeatbugUpdateOrder' Boolean flag we can* D9 k) g& Q7 X
// randomize the order in which the bugs actually run. ?4 r# @; o6 N( v0 i4 Y& g
// their step rule. This has the effect of removing any
5 W% L7 z' ]: O) Z5 A // systematic bias in the iteration throught the heatbug+ |" {! Z8 `. s! ?" T# c
// list from timestep to timestep
5 ?. E8 Q% ?* T4 R) k( a# o 2 \1 Q4 f9 u) ?6 a; Z3 H
// By default, all `createActionForEach' modelActions have
2 ^' I/ Y- S* o: j) A7 y# ? // a default order of `Sequential', which means that the
+ t3 k0 A/ q* E // order of iteration through the `heatbugList' will be6 s! r6 Z1 W/ b, T8 m/ J x
// identical (assuming the list order is not changed0 d' N/ U, l7 h) \8 N; o" Z6 e2 r
// indirectly by some other process).9 I {0 k$ V* Q+ F1 k) y3 I
9 P! h& c3 p2 N* z" d W
modelActions = new ActionGroupImpl (getZone ());# I/ H6 {. p# Y ]* D$ B& t6 V8 B
: a) d, X3 [+ {, L9 F* I3 L4 O try {1 T* `" E2 `% ]& N
modelActions.createActionTo$message, m. L! x; G5 M* i0 N. B0 O
(heat, new Selector (heat.getClass (), "stepRule", false));
4 |: s& E# r6 ^% t Y/ q8 B0 l0 H$ v } catch (Exception e) {
. ~& l4 r. e3 z1 u- F9 ~ System.err.println ("Exception stepRule: " + e.getMessage ());
4 |$ D5 K2 L' r }
7 G# R% `4 T" w h/ h$ e# m+ T. e9 K& d
try {' j7 S9 Q4 s6 P/ Y; z, q
Heatbug proto = (Heatbug) heatbugList.get (0); x& `- x M* W4 m
Selector sel = 8 _" j" V5 Y# M3 k
new Selector (proto.getClass (), "heatbugStep", false);
+ t7 `5 S( b# @. i* i) D actionForEach =2 Q" i8 a8 n2 T/ `6 m0 R) h+ }" z2 x
modelActions.createFActionForEachHomogeneous$call
+ \5 ~0 A# L9 f (heatbugList,9 |- v. D* M: t- h' U6 U- p
new FCallImpl (this, proto, sel,) J& t7 v3 q4 a# F: Y6 w* I" ?
new FArgumentsImpl (this, sel)));& j! r6 x+ [7 _% t7 x- `* f0 x* r6 x
} catch (Exception e) {
3 {* V0 u8 A, N/ ? e.printStackTrace (System.err);
! {6 Q7 N, A0 E( A- N }
) |# |2 y: _+ g
) s( g8 ^! j9 }1 @/ K2 @ syncUpdateOrder ();
! K+ {- e" J$ z" q. Y/ ]( b4 @7 }" C! |
try {
. n7 I+ e. E) [+ f! G2 G( \ modelActions.createActionTo$message
# s+ a$ e2 ~" W+ [ (heat, new Selector (heat.getClass (), "updateLattice", false));& v, L, _; z, Z z
} catch (Exception e) {
& ^% @5 D$ F5 o% R* g$ ]5 e" I2 [ System.err.println("Exception updateLattice: " + e.getMessage ());- _) [0 ^8 ^* x
}2 g; ?+ R9 A$ o4 M9 `
/ m8 l; _+ I) T0 X
// Then we create a schedule that executes the3 E5 C5 }; t! Z2 e4 y. b
// modelActions. modelActions is an ActionGroup, by itself it
! q# N5 e, p$ |! a. l: X) l8 X // has no notion of time. In order to have it executed in
. b! ^6 k' F" e' n9 Z9 @ // time, we create a Schedule that says to use the
) ]+ p- D/ Z8 Z7 ^- m. T8 D // modelActions ActionGroup at particular times. This
. Z, I: `5 C: w( @ // schedule has a repeat interval of 1, it will loop every2 |& }" b6 W' [
// time step. The action is executed at time 0 relative to
7 l) @ L, d% G' p8 ~ // the beginning of the loop.
8 t. ^% F5 s) r7 \- b( l, h$ e
6 N0 L8 U0 E! J; V6 r' U, T" S // This is a simple schedule, with only one action that is7 o0 V/ E% n: ]' p2 h9 p
// just repeated every time. See jmousetrap for more
2 a2 F7 N/ m2 @9 w. U6 Z# j% P // complicated schedules.
, P& L8 b1 B! _ : x+ o% _. i* E, r ]! X9 l. i' {& M
modelSchedule = new ScheduleImpl (getZone (), 1);3 w4 x$ Y: P# X6 F: a9 d4 f2 E
modelSchedule.at$createAction (0, modelActions);
' j0 F+ R' P4 P& y& P" ^% u/ z1 E9 w ) O! t4 v* r6 A9 D1 Z, A3 J* Q
return this;
& ^$ v: n: A0 c) ^0 r } |