HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' F# s" e. P; e ]8 S
' }( z# |1 X% _# e
public Object buildActions () {
j% E* U, F8 Z+ U+ | super.buildActions();8 l' K" q4 z4 R6 c, g$ n
( K. a/ s4 n9 ^$ @' X2 v2 Y
// Create the list of simulation actions. We put these in
, f9 S* a/ u- K8 o // an action group, because we want these actions to be
1 U8 N5 u' j" Y" R" q // executed in a specific order, but these steps should; w2 U, Y( p4 d( a7 `
// take no (simulated) time. The M(foo) means "The message
`6 _9 ?. T$ H! ~9 C) I4 V% S1 s( [( N // called <foo>". You can send a message To a particular
8 U0 V- W$ i2 k, q5 o; x1 t9 X // object, or ForEach object in a collection.
4 F6 u( s" y6 k % \. z; D, v. P9 E. P7 P" B
// Note we update the heatspace in two phases: first run# T& p1 M, [! m& S$ ?! F5 s
// diffusion, then run "updateWorld" to actually enact the3 k. L& j Y. a: X/ o
// changes the heatbugs have made. The ordering here is4 k& U+ b3 z4 \3 y( Y! C3 A
// significant!
' @0 ?8 C5 V- a1 Q4 q 0 D9 _7 m2 a7 v0 v: u2 K1 C+ W
// Note also, that with the additional
: u% B) I o9 F3 N // `randomizeHeatbugUpdateOrder' Boolean flag we can& j Z. o& p8 D4 f2 G y( \% a
// randomize the order in which the bugs actually run
* r2 k9 r. d% }' A# C; q // their step rule. This has the effect of removing any
! N6 _9 x0 J! E) t. H // systematic bias in the iteration throught the heatbug
" m Q/ [6 Y, V, V // list from timestep to timestep
& {" c% {/ [, G0 \; l ' U7 w; p {; K5 ^: M
// By default, all `createActionForEach' modelActions have$ w) R0 d/ v* T- c- w
// a default order of `Sequential', which means that the) _% p( J! b6 t
// order of iteration through the `heatbugList' will be
1 e; J$ f( W# h4 ^9 h // identical (assuming the list order is not changed
2 U' q( ^/ L* r: q1 K; e' T9 I6 l // indirectly by some other process).7 a8 I. Z$ ^+ n. ^& U
?! l3 ?( {" T* O2 B/ _3 ^ modelActions = new ActionGroupImpl (getZone ());8 ]5 _7 I$ u. a, {* y/ T9 I/ g: H
! c) k) ^' G* o& o
try {
( x D8 w5 @7 q) H0 A modelActions.createActionTo$message+ ~/ s% W5 q+ l$ D3 w$ y
(heat, new Selector (heat.getClass (), "stepRule", false));7 U2 J: W5 w" q! e1 X( u
} catch (Exception e) {/ s: r' ?" F& W% B, |6 p
System.err.println ("Exception stepRule: " + e.getMessage ());/ m; Z' Y @# _; A& O' R
}' i/ |: t0 a' [
+ B, y5 M+ R+ F O1 p% |3 k" D( x1 l
try {
0 v' W1 U/ f$ m. ^ Heatbug proto = (Heatbug) heatbugList.get (0);
+ @" S" }2 b. n5 D3 } Selector sel =
2 _2 @# ^, T" j new Selector (proto.getClass (), "heatbugStep", false);
; @1 a- x/ h6 }% `- W) l actionForEach =
\" T1 _, v6 }5 I1 N2 |$ P8 ?% J modelActions.createFActionForEachHomogeneous$call. T" D: e" f9 B3 b( n& G7 X
(heatbugList,
. _+ c7 @) V8 N. F- r( _4 t new FCallImpl (this, proto, sel,
+ F; u) k5 r/ g8 ~5 r4 [! M new FArgumentsImpl (this, sel)));" O0 J" ~- y1 {# }) o* Y& ^
} catch (Exception e) {
( x& N/ Q% d4 q e.printStackTrace (System.err);
7 D, q3 O4 S5 t5 _* h$ ^: ] }9 }8 @& V" v- D5 t* b I, z
. I; H: d+ {& F syncUpdateOrder ();6 }' e3 X1 ]& _: s. L) m5 h
! s: R! Z; _6 i
try {
$ Y3 Z7 {8 m8 k+ B# R M2 q modelActions.createActionTo$message
0 Q6 j- I" P" H7 I* r (heat, new Selector (heat.getClass (), "updateLattice", false));% r! i1 ^/ v6 b! i, Y7 C
} catch (Exception e) {
( o p" r3 E7 P s3 F* \. ~* @ System.err.println("Exception updateLattice: " + e.getMessage ());
0 b' Y! U% n5 Z }
8 _+ I0 @; S4 t+ q" j! F6 ] 4 d# S% V) k: p2 U
// Then we create a schedule that executes the; b( F9 J& l3 M' b1 k9 r
// modelActions. modelActions is an ActionGroup, by itself it7 I$ s. @7 v$ b( C) X5 Q2 @1 ]! L
// has no notion of time. In order to have it executed in4 Y+ Y" }/ q, i6 I+ K
// time, we create a Schedule that says to use the
$ {/ j) ^1 ^# t9 W // modelActions ActionGroup at particular times. This
?4 i2 x" ]% w // schedule has a repeat interval of 1, it will loop every. V& P7 @$ U1 Z9 t3 `
// time step. The action is executed at time 0 relative to$ d) z0 D9 l4 |+ |. t ^; W4 q3 ~
// the beginning of the loop.
" w6 ~3 E- |0 u0 C8 _; N0 U4 | z5 \6 B% ?. j. v
// This is a simple schedule, with only one action that is
! j4 J. @4 {0 s7 v( U- m; t // just repeated every time. See jmousetrap for more
% N( [( B2 L& Z! | // complicated schedules.
. H" ^9 c* t: B* D& K* v 9 \4 S' x; d- A7 W$ j
modelSchedule = new ScheduleImpl (getZone (), 1);2 X6 F/ V7 \% G( f# p9 ^7 b
modelSchedule.at$createAction (0, modelActions);
7 k F. L4 O6 K* r n+ m F; F7 L6 v3 L7 ~
return this;
7 J) N' c- P% @5 o/ U } |