HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:% ?* R- B8 E4 j8 S: Z
1 h1 [! V. u# Q/ o8 l; k( R, o public Object buildActions () {
' N/ M7 f4 y' M d super.buildActions();
7 p; X$ _, u# M ; f2 T# Y* @8 K" k2 z
// Create the list of simulation actions. We put these in
2 t! s J- y# f. S; H5 A8 k // an action group, because we want these actions to be
: f% A' V# o8 h( `. D // executed in a specific order, but these steps should( v2 m5 [% Z* L& q) u0 D5 t. r: q" C
// take no (simulated) time. The M(foo) means "The message
. ^' s; ?8 [$ q // called <foo>". You can send a message To a particular
8 _4 Q! A" T+ `( A // object, or ForEach object in a collection.. X6 k7 y0 Z/ v
- ^/ r( l+ Z6 W) ~6 j8 a
// Note we update the heatspace in two phases: first run
) c3 n( t2 q { // diffusion, then run "updateWorld" to actually enact the
) t% P# i# L) w1 q // changes the heatbugs have made. The ordering here is% Y2 q# I6 t9 O3 K( M- S7 C" T
// significant!8 u& v/ }5 d% R* w/ ?& Y
9 s+ b' A$ M% q1 k( \* d; S% B" \
// Note also, that with the additional
7 T* z; M) y5 ?0 \! c5 h: B // `randomizeHeatbugUpdateOrder' Boolean flag we can% G$ M& y7 w* q. ~, c
// randomize the order in which the bugs actually run9 U" n' F+ @' x! Q
// their step rule. This has the effect of removing any: ^! n# e$ {. C) r6 Z1 v
// systematic bias in the iteration throught the heatbug3 ^6 _3 M4 Y6 b: K
// list from timestep to timestep/ K. w+ s( E. Z& [
k. j! H( b, h% H // By default, all `createActionForEach' modelActions have
; X5 ~) w' O& Y // a default order of `Sequential', which means that the" l* y! k! ~7 z# Z
// order of iteration through the `heatbugList' will be/ D3 B+ M; o3 n8 _
// identical (assuming the list order is not changed) f5 U$ F: V& [# w1 w7 X3 z% T6 ^
// indirectly by some other process).
4 G7 }: E+ h! w( Z ! D" E4 j! i. q2 ^0 L# e
modelActions = new ActionGroupImpl (getZone ());+ j/ @) J- x) [( ]) q8 K) D
$ n, }5 |# ]% {2 T& r# P; O4 A. R try {9 U5 p. E; T, F+ Z4 S
modelActions.createActionTo$message0 q' S9 A7 |' Z4 H$ {
(heat, new Selector (heat.getClass (), "stepRule", false));
& W9 C: v) @) u' d. c5 O; @ } catch (Exception e) {
! @! E) r e/ r; C/ q System.err.println ("Exception stepRule: " + e.getMessage ());6 x8 b0 T X. x7 c% e" h
}
) E+ ^- d3 O# B- t4 z) @
' T1 b! C) e- G5 ]2 n try {9 D' E$ G! W! }3 B/ R
Heatbug proto = (Heatbug) heatbugList.get (0);
$ D1 l. w( A" G* g0 ~ r Selector sel = + s; c, F& \& f
new Selector (proto.getClass (), "heatbugStep", false);
. n# J+ |) m- Y- h9 ]" V2 W [ actionForEach =
) |) y9 y P9 }! ]! U( D modelActions.createFActionForEachHomogeneous$call
* w* u6 ~" v% y. T7 F/ E- X, s& P4 S9 I (heatbugList,+ r, C0 G( D4 j2 T! }0 f
new FCallImpl (this, proto, sel," `/ u" y r% C3 d" a9 C
new FArgumentsImpl (this, sel)));0 @# L# c# R0 Z6 D1 `
} catch (Exception e) {
F2 i U9 M% m e.printStackTrace (System.err);/ s: i/ _, }; L+ S1 f1 q# z1 n6 i
}
8 ~/ n8 E$ S6 Z, F; y5 o" Y
) i4 M$ `8 V' d+ J; d, j6 [ syncUpdateOrder ();
5 P( ~4 q7 m5 t; K z
: ]5 T7 T; B/ v. ] try {& d3 u4 A9 e/ B5 K* b2 t D
modelActions.createActionTo$message & z# j1 V5 b8 E2 l
(heat, new Selector (heat.getClass (), "updateLattice", false));- A/ r+ a3 m9 D# p$ `8 F
} catch (Exception e) {
0 ^( a4 f, O6 v' c7 i. ^ System.err.println("Exception updateLattice: " + e.getMessage ());& V" {, k" ~/ w+ _! `0 t& o
}
$ ] W$ U6 o2 n/ j
* k* T: e$ _& s2 ? // Then we create a schedule that executes the# g. K3 T4 N5 P$ J8 X! M3 _- C
// modelActions. modelActions is an ActionGroup, by itself it2 k; A% D; }5 {. P, B! J
// has no notion of time. In order to have it executed in. N- n4 T3 d( m3 A- U
// time, we create a Schedule that says to use the9 P1 T1 j; h5 ]8 r3 [; X
// modelActions ActionGroup at particular times. This
! o- }6 G6 K, M# g // schedule has a repeat interval of 1, it will loop every
/ y, d$ ^8 O/ W- A8 w // time step. The action is executed at time 0 relative to
7 ?# w2 r' V6 r( K# \! H. E // the beginning of the loop.. B& K2 r# N" G
" V8 ?8 a D$ H M1 C0 N$ u // This is a simple schedule, with only one action that is8 M, }4 K# V' H
// just repeated every time. See jmousetrap for more0 h0 }+ O+ N/ u+ v( \
// complicated schedules.
' i( D% B2 F; B. N- ^ Z% |/ _! s & {) o9 ?* W: T
modelSchedule = new ScheduleImpl (getZone (), 1);
6 }7 }8 `7 z2 m- P7 d. a modelSchedule.at$createAction (0, modelActions);) J: u( v/ s, K; ^( ~
& \* Y1 L2 f4 Q p1 M' C( C
return this;4 b" h5 d- \3 |' p* S! Y4 c5 d2 N
} |