HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
. m% Z( ~ Y+ Q% {$ k; I. s4 i4 S. }- b6 D' C/ a$ T, [) J
public Object buildActions () {3 V# K' B0 C" Y
super.buildActions();) ]! |! e+ M7 n z; S; }
" W, [- Z5 a4 D1 k // Create the list of simulation actions. We put these in
3 o' }+ \$ m% a9 T5 J // an action group, because we want these actions to be: d, }- X7 |1 J+ `, F
// executed in a specific order, but these steps should
3 }; P) w J) g+ A; v% p: z7 e // take no (simulated) time. The M(foo) means "The message; f5 s3 S& X" }( K' e; ^9 w
// called <foo>". You can send a message To a particular
) E* e* ~ K+ O2 d // object, or ForEach object in a collection.
5 ]5 ]9 O& ~7 ?+ _4 t1 X6 \ 2 Y# r X2 q& b* d9 H+ @
// Note we update the heatspace in two phases: first run, ^8 M# |: ^3 P4 A+ \
// diffusion, then run "updateWorld" to actually enact the8 G2 A& F9 ?& C7 p* F
// changes the heatbugs have made. The ordering here is( A, k! x# T/ P: o( A
// significant!
% R8 [+ e3 D6 }% Q
8 {- N v0 H2 W7 r: J8 C // Note also, that with the additional
* Y6 {8 i$ z$ s& _" p // `randomizeHeatbugUpdateOrder' Boolean flag we can
: X& x: s/ B% a$ ?9 T# [ // randomize the order in which the bugs actually run. Y* T* D0 N, N$ x2 c' N
// their step rule. This has the effect of removing any
' {1 [. n' r, J$ p2 o/ R8 {6 F // systematic bias in the iteration throught the heatbug+ Y# p3 `5 z+ ^( K( P% b( L' p
// list from timestep to timestep
. T% Y5 U3 [9 T: w0 o `6 l - \) J4 Y' s& @+ P0 ^: J6 Q
// By default, all `createActionForEach' modelActions have% q4 m: l y8 i
// a default order of `Sequential', which means that the8 X6 C$ G& q: Y( X; C/ V* B" e) _
// order of iteration through the `heatbugList' will be
* q* @/ t8 d$ [2 t* w! Z! u // identical (assuming the list order is not changed5 l& d; R% Z. \/ @7 \; }
// indirectly by some other process).
# C7 }% B6 B$ q. o- r4 k7 c ( v( h7 N8 p8 ^# @
modelActions = new ActionGroupImpl (getZone ());) R1 s: n( w+ O, l4 [" a/ r5 R
# `3 J+ ?9 _4 i: ~
try {
% ] ]" N" ~+ z9 [, C! g- z modelActions.createActionTo$message( R6 ~/ f8 l- `7 F
(heat, new Selector (heat.getClass (), "stepRule", false));5 s$ K& q- B; y: D0 E7 K0 P- T' \
} catch (Exception e) {3 B: f& z/ b) h# A
System.err.println ("Exception stepRule: " + e.getMessage ());
( \& O, X, A2 ^/ X' H. W3 e }7 i7 X$ |# J* y2 Z9 V4 X
9 @: r" X! \$ ?5 e4 S7 m- Y0 H
try {
( ^: d* f* K( ?2 ~/ M6 G Heatbug proto = (Heatbug) heatbugList.get (0);4 X0 q D: L, R. f* S* o9 h9 l
Selector sel =
# i4 @+ N2 ]) U$ w& [: M$ _ new Selector (proto.getClass (), "heatbugStep", false);/ @2 b3 X6 l) J4 c2 Z3 ~! L/ w3 A
actionForEach =
, U: p* H9 Q# U! b' T+ I4 }" @: d! ~& j# I modelActions.createFActionForEachHomogeneous$call
$ q/ S( |* T7 r7 A- `% P! _ (heatbugList," j0 R! e: @) E. t6 }- m
new FCallImpl (this, proto, sel,. D8 l5 F/ _3 ?
new FArgumentsImpl (this, sel)));& Q$ O* O; Q; j5 p1 n6 N% g
} catch (Exception e) {) g6 q9 Z" N" T* O' R" F( D
e.printStackTrace (System.err);
" m2 b/ K4 |5 C) @6 d }& U. h2 P% N2 o7 D" I' G/ V* x9 o
7 |9 N* I, z1 P. S/ c# X
syncUpdateOrder ();& D K, C2 x; J; y
( `, S8 C; ~$ u0 c) M( }: d' X
try {' [& x% [& _% J1 u9 r, V2 y; ~. F5 [
modelActions.createActionTo$message 3 `9 c* F4 L3 u2 z( t1 a
(heat, new Selector (heat.getClass (), "updateLattice", false));
w: P; N7 g; Y1 g$ X } catch (Exception e) {
) t* }0 n9 b9 v System.err.println("Exception updateLattice: " + e.getMessage ());/ y$ z1 ^7 W4 f3 X) }3 u. n$ ?
}
/ \2 a2 _6 h) u& i5 S
Z3 D7 }0 V) D1 D+ p3 a2 e4 B // Then we create a schedule that executes the
9 |, c) I8 Q+ W& ]' a: V/ I4 } // modelActions. modelActions is an ActionGroup, by itself it
6 k0 U W: f3 N& B // has no notion of time. In order to have it executed in. T2 M& F) Y; L& o9 E
// time, we create a Schedule that says to use the
4 G9 V4 \5 J& |% |- ]2 w // modelActions ActionGroup at particular times. This7 v+ }6 Y3 o1 I* B
// schedule has a repeat interval of 1, it will loop every) a: \4 c8 o. k R, \ C9 s
// time step. The action is executed at time 0 relative to
' O2 D, G0 \/ P( f Q; }. p // the beginning of the loop.3 U3 H/ X: [! g# E
_* ^* M' t3 e% `1 J4 ~ // This is a simple schedule, with only one action that is
& b8 N0 X! G: Q: c# O, G' G3 Z# Q // just repeated every time. See jmousetrap for more
' O: L: F: X/ X0 E // complicated schedules.
* A5 U9 }" ]2 }, ^( J % Q( j# I. m2 c% j8 _2 z. ~% W
modelSchedule = new ScheduleImpl (getZone (), 1);
& b5 Y) b H% a: V# f r modelSchedule.at$createAction (0, modelActions);
& X5 ]4 V: V. o" J 8 D3 c8 n! z. p
return this;' C) i# F0 U% a2 h, ~6 m; t9 f2 ^
} |