HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
" i$ b6 X( h3 |* M8 r' A( ?
6 J [7 `5 A& m public Object buildActions () {
! V$ w$ A, n) n! G) ~ super.buildActions();5 Y: B# c. h9 W( r
% K- U6 _0 `7 u2 ? // Create the list of simulation actions. We put these in8 B8 E: m# M' s9 m% L1 ^% z
// an action group, because we want these actions to be6 a$ B5 Q0 F$ |" g# s2 p
// executed in a specific order, but these steps should$ z8 g; k7 n2 C$ ~
// take no (simulated) time. The M(foo) means "The message
0 S4 R- g! p' v% J9 i // called <foo>". You can send a message To a particular A) z; O3 @, r) k: B/ H
// object, or ForEach object in a collection.0 z1 ?8 |% B# g) g3 d
D- H% R7 y1 m8 H // Note we update the heatspace in two phases: first run4 n. H% G% F$ M. Z
// diffusion, then run "updateWorld" to actually enact the/ ~. W7 v3 k( V j
// changes the heatbugs have made. The ordering here is
; R* P( T6 w+ @3 r+ B3 x! r // significant!
) L2 |4 P% Z8 Z0 T- B" R, G % ^1 D( Y* x. ^$ d7 y- o2 f
// Note also, that with the additional" ` x" F' ~6 X* e* K" A
// `randomizeHeatbugUpdateOrder' Boolean flag we can. q* \8 D+ v# e2 A. K- A S* Q# b
// randomize the order in which the bugs actually run
8 J9 a! Y9 p/ [) y: ` h // their step rule. This has the effect of removing any1 T3 z3 E* X7 ~2 h" t% V
// systematic bias in the iteration throught the heatbug4 Z( o" `# ~( ~
// list from timestep to timestep
: O' e# C$ l/ T: A 1 h5 b9 u' s2 ^4 l# U, _2 a+ y
// By default, all `createActionForEach' modelActions have! V" g- s U0 G' a! j R
// a default order of `Sequential', which means that the
: I. D' j( L5 j3 y& e2 w6 a3 k // order of iteration through the `heatbugList' will be
6 p$ T, \& |; B' z& t; u // identical (assuming the list order is not changed9 ?4 i {. ?- e) ] R ?6 w
// indirectly by some other process).. U$ `% k# m$ o( a
. E- d' D2 h2 ~' C8 B
modelActions = new ActionGroupImpl (getZone ());/ _4 _" A/ r* u$ f/ p1 z
$ r0 S9 b" A4 v+ q3 S/ L$ N# I try {
4 c1 \7 D* M; q% K modelActions.createActionTo$message4 L% ?6 B( H6 w L5 e
(heat, new Selector (heat.getClass (), "stepRule", false));
. S# `3 D0 U5 z/ j! p } catch (Exception e) {6 p4 M( B: A, j6 _) C
System.err.println ("Exception stepRule: " + e.getMessage ());# x0 {, C4 d) W
}
) v. Y' o+ b# o) g" S& N3 U" @1 d/ S3 l% L6 @+ C/ ~
try {2 | Q& j1 a4 F3 [ ~$ v
Heatbug proto = (Heatbug) heatbugList.get (0);" a! z/ r% p0 d# ?; W1 q4 K5 |6 k
Selector sel =
* Y- T- O# g" M& U new Selector (proto.getClass (), "heatbugStep", false);
% k; D1 J. |# i& W9 j4 v" D* @ actionForEach =. @0 K5 f( C& P" N% J) D
modelActions.createFActionForEachHomogeneous$call5 O0 j0 A' z P! K6 z
(heatbugList,
- s* d7 S/ W+ Z+ Y/ @1 D- K9 o6 [ new FCallImpl (this, proto, sel,9 m, t+ G. l/ b! s# D$ T/ M
new FArgumentsImpl (this, sel)));' x$ @- ?4 Z. i# \* _5 R$ I
} catch (Exception e) {
4 Z1 Q& X. F( v) P e.printStackTrace (System.err);
/ u/ M3 F0 @7 j! } }& n& p1 h9 E5 t7 |( x: G! p
1 d2 `/ ~$ @4 w1 ]# D; A8 O) P syncUpdateOrder ();
( f7 ?' ^' L) k) L5 S* T" | ~8 V. G" L, _
try {
* g& ~/ e6 i* }9 k modelActions.createActionTo$message
' G4 w9 t w) j# a- i! J6 y (heat, new Selector (heat.getClass (), "updateLattice", false));
" y% t4 X C" r, o } catch (Exception e) {
- T+ U+ ^ y: z2 Q( O& \# |$ s System.err.println("Exception updateLattice: " + e.getMessage ());8 ~7 B! \! G( v
}+ ?! d9 N! j& a( m1 v4 D, B
" Y: Z: v( b# H1 x9 r ?
// Then we create a schedule that executes the
. _( T& @! z9 _: ^: k8 v // modelActions. modelActions is an ActionGroup, by itself it
( X- O$ _) L% j; X9 R5 c% }4 J // has no notion of time. In order to have it executed in
- x& m ? |, v- }; m // time, we create a Schedule that says to use the8 I! G+ c; l: N+ U
// modelActions ActionGroup at particular times. This; Q3 n- ] d0 c$ L
// schedule has a repeat interval of 1, it will loop every% l! t% J) ~( [0 S" `' d
// time step. The action is executed at time 0 relative to- x5 E ~8 `9 d/ F2 G, u
// the beginning of the loop.7 c; q" J- |& i7 z0 N
# ] A/ H2 _, L2 s
// This is a simple schedule, with only one action that is( f, T: K z4 U
// just repeated every time. See jmousetrap for more
* {& V/ |- \- q // complicated schedules.
$ Z% l1 l: s: N! C) i7 O ' T) j( @* k# R4 ] \6 D5 r+ k% W
modelSchedule = new ScheduleImpl (getZone (), 1);: A+ V" _- e$ ]- m
modelSchedule.at$createAction (0, modelActions);
3 x* `0 ^% b- q ( J* w( g- Y& w" ?
return this;
- j5 c! v* G7 p$ b* k2 c! Q$ a3 E3 u } |