HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
/ |0 u- }4 \) C3 x
0 k2 k9 q$ M4 B5 `/ F public Object buildActions () {
! h5 E9 i/ Q- y% K6 ?+ e) K$ ] K super.buildActions();" U" Z4 v5 G$ e3 e+ N1 W
+ h* c0 M" [# i Q
// Create the list of simulation actions. We put these in1 Y' x; R* ~" b8 {
// an action group, because we want these actions to be
+ \' T1 D# x+ x6 |1 I& X // executed in a specific order, but these steps should9 O. j! G1 \/ |9 X
// take no (simulated) time. The M(foo) means "The message! o" n. o; u( E$ a, O
// called <foo>". You can send a message To a particular
. Z. V; }8 ~. ~; J z' @$ |/ ?! _ // object, or ForEach object in a collection.
$ i B) [8 f" u: d2 _
- p, e) V# T" j // Note we update the heatspace in two phases: first run- l K w* ~. w D$ y \! c
// diffusion, then run "updateWorld" to actually enact the4 Z/ ~" E3 |7 l% K" y& w
// changes the heatbugs have made. The ordering here is
% d. F3 B" s3 | // significant!# w- q8 d$ E- R; Y# m
! e2 E/ K! y1 S7 h8 [ u$ P
// Note also, that with the additional6 j9 z3 B2 _ s- G
// `randomizeHeatbugUpdateOrder' Boolean flag we can$ j) o' k: t6 P
// randomize the order in which the bugs actually run* i& K7 p: b) Z
// their step rule. This has the effect of removing any( |! ]/ }3 e* ~( G9 k4 V: c
// systematic bias in the iteration throught the heatbug
8 t* i+ e9 p$ J7 ~ // list from timestep to timestep$ d+ y- ~6 T( D7 U+ ]. _
8 B2 `8 M# [6 D6 U) [7 q" w
// By default, all `createActionForEach' modelActions have4 n6 u; G, Y1 k! J8 Q/ C
// a default order of `Sequential', which means that the$ M0 H' f" s g Q: V/ J4 p0 |: |: c
// order of iteration through the `heatbugList' will be* G* [! t5 M! S+ u
// identical (assuming the list order is not changed
5 w5 B2 w/ ]" _" g // indirectly by some other process).5 {: m$ k/ N5 i# C" w" N- t
% N4 @4 ]: N& _ d1 z9 i; i modelActions = new ActionGroupImpl (getZone ());
?) m d+ G% C7 i' h6 e. ?- k2 \/ C( }) v
try {
2 n: z- ]) T$ u modelActions.createActionTo$message
; I5 n5 S5 `4 }8 r (heat, new Selector (heat.getClass (), "stepRule", false));
; ]7 h" W; ?1 f- L8 e5 Y } catch (Exception e) {
+ d2 N- \2 p# |3 |( w, z System.err.println ("Exception stepRule: " + e.getMessage ());/ C4 x4 s, U, J% M. A+ C Y1 l: y- {
}
7 @ X8 x" q% r2 r( a. l0 v/ |1 [! @" r/ i
try {2 o5 Y7 {! R' U% P0 m
Heatbug proto = (Heatbug) heatbugList.get (0);% M' V+ r: |) Y6 U, @% ]
Selector sel = s1 _$ P: y& H/ H1 m+ R# _
new Selector (proto.getClass (), "heatbugStep", false);
# E' E I& l) e" `, y" ` actionForEach =
) d1 f' b( M/ }' z modelActions.createFActionForEachHomogeneous$call
3 ?; L9 \' [" ~( K4 u (heatbugList,1 c8 D8 a4 X: h0 w- ?- u
new FCallImpl (this, proto, sel,/ C( q: \/ C" m& @/ ^/ w7 ]4 s
new FArgumentsImpl (this, sel)));
4 E1 W" ]% |6 t) V. }4 @ } catch (Exception e) {) M4 U+ _5 b; \" z8 Y( H
e.printStackTrace (System.err);
4 s7 S& q% `: t8 L a% d }8 v6 ~: ]2 V0 x, { w; v
) z6 B+ D$ B# V. n! w' F. ^ syncUpdateOrder ();& B; f5 D, [& Y" j; F3 ~
/ c4 t+ w M* ^3 k B C. Q try {
$ |0 e' y! Z+ m modelActions.createActionTo$message
; m2 ~% P! N) I# k2 h (heat, new Selector (heat.getClass (), "updateLattice", false));
4 ? H5 l) A4 N3 q2 U% F. m } catch (Exception e) {7 B1 q6 `! }" }
System.err.println("Exception updateLattice: " + e.getMessage ());
( Q( B" P+ W1 j. W1 p* J }
( l7 p% n5 o* {2 @# i9 y X' k3 M. s2 \# u! @; Z! L
// Then we create a schedule that executes the
2 v- Q! d' o9 `; T' U // modelActions. modelActions is an ActionGroup, by itself it
* h0 G3 z5 D: J // has no notion of time. In order to have it executed in6 D/ ~# ]* e* P, ]2 M) W/ b% r& ^
// time, we create a Schedule that says to use the
, \# G: T- I Y6 {: S9 n: B // modelActions ActionGroup at particular times. This# Z. l/ |5 ^! u/ E4 j
// schedule has a repeat interval of 1, it will loop every! j+ g1 S6 b Z1 ]1 z& b" L. ~6 j
// time step. The action is executed at time 0 relative to' U( t/ u% C) G
// the beginning of the loop.3 T0 g% b- k( B# h- l
0 m+ E- B7 l- b$ q! \9 l
// This is a simple schedule, with only one action that is
& p) S, {0 L9 _! K // just repeated every time. See jmousetrap for more
# q4 Q. c0 v; n* | // complicated schedules.9 d5 \& [/ ~$ A6 ?4 \3 r6 |4 Y0 P
0 a! P8 L6 \) `% r3 l
modelSchedule = new ScheduleImpl (getZone (), 1);
2 Z1 F# q/ u+ s; v modelSchedule.at$createAction (0, modelActions);% m' \, }1 K% _! z: ]; m
% E% q, U! x- T$ e% K) f2 [: e
return this;
+ H, E5 ~$ Y( t) T! L0 m& y8 T: V } |