HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
& }. ?: m8 a6 w6 }
% h- I9 X4 p2 W3 A8 Y9 ^3 r public Object buildActions () {
7 K7 ~! v* f3 j2 h3 ~+ [2 a super.buildActions();
6 r3 [% q% W; H; H3 ] 4 k u! t9 F" V' }! A% I& u
// Create the list of simulation actions. We put these in+ I5 p4 z0 `- h% C) I% o
// an action group, because we want these actions to be y# k0 J$ S0 b( I6 N" Y. G# U
// executed in a specific order, but these steps should
2 Q V( t+ Z( ^8 S // take no (simulated) time. The M(foo) means "The message0 T/ o" f1 }, q. v
// called <foo>". You can send a message To a particular. v$ t' c% M' h; Y
// object, or ForEach object in a collection., q& o2 x' ]) K, h r5 M$ X: ^
+ t; U# B" Z: S$ R- j% }
// Note we update the heatspace in two phases: first run. H) s# N' x3 o M- S1 H" C6 N
// diffusion, then run "updateWorld" to actually enact the
; R3 \' e& M, g, c( z // changes the heatbugs have made. The ordering here is
/ p& ?6 L; X. a // significant!% B, K% y7 D& f5 x* E
8 |0 _2 G$ o$ {% F$ P5 y0 a
// Note also, that with the additional/ i8 a4 i2 j7 P% ]& A
// `randomizeHeatbugUpdateOrder' Boolean flag we can' @9 q; W1 {: t6 q" {7 I+ b
// randomize the order in which the bugs actually run+ [& b" E1 F# J' V
// their step rule. This has the effect of removing any+ N& G. C4 y: H( Q/ {
// systematic bias in the iteration throught the heatbug
9 Q I6 C, \9 i! w // list from timestep to timestep7 s9 I) V7 j( ^
% d8 ?- Z. B* n" E& E
// By default, all `createActionForEach' modelActions have5 f' S2 p* d. k G W
// a default order of `Sequential', which means that the
: m6 o- L' ]" a; Z) V0 R# x // order of iteration through the `heatbugList' will be( e2 P9 L/ L8 ?
// identical (assuming the list order is not changed
, x5 Z- u: f' } // indirectly by some other process).
% l# j: j$ w; w; v 7 C/ ]0 G& K9 _# L, |
modelActions = new ActionGroupImpl (getZone ());
9 B: a9 K' r q! B3 R
4 h2 A4 k6 v) u2 W3 ^! A try {( ]' A, }; Y4 R; A! D* p6 t
modelActions.createActionTo$message$ y, m. Y- k E( U* |8 b6 w: Z9 V/ q
(heat, new Selector (heat.getClass (), "stepRule", false));
$ h5 m8 U7 W* h+ S5 \4 o, A } catch (Exception e) {" H: p4 {1 r1 W, I0 p+ r
System.err.println ("Exception stepRule: " + e.getMessage ());# k+ _. w5 V5 F# K# c* R
}* d, ^& `* j" g
, Y) ?# P6 g3 g' H7 b# r4 U) l
try {( y- y4 C* G/ H( V. D
Heatbug proto = (Heatbug) heatbugList.get (0);
9 i; }+ x& ~) l! X, M Selector sel = + D$ m8 C) I8 d& G; B
new Selector (proto.getClass (), "heatbugStep", false);( Q% D: D- V* x7 b
actionForEach =
- d4 t7 c+ T6 L modelActions.createFActionForEachHomogeneous$call
) m& v( s" l* T (heatbugList,
% h1 i+ c3 d$ g s8 }6 J, g new FCallImpl (this, proto, sel,3 t3 `; Q1 n' N! o8 i, S0 W7 v
new FArgumentsImpl (this, sel)));
8 o- Q$ U' L7 L } catch (Exception e) {0 A% I/ s, u/ }" ]' k
e.printStackTrace (System.err);
) E& k* c+ b8 d+ o& e! a" ]3 L }- [. W Y2 y* A s) f
' C1 V% c [5 Y7 j1 G
syncUpdateOrder ();1 b: d% \+ j" }4 H! k2 v) i9 M
* k7 K7 t" Z; y$ R try {
5 e3 K1 b0 N+ `6 k8 y modelActions.createActionTo$message $ i" h5 P$ m2 n$ F
(heat, new Selector (heat.getClass (), "updateLattice", false));) B5 V" k* E( e+ V. D
} catch (Exception e) {; s8 l5 V C- S% j5 P. T g
System.err.println("Exception updateLattice: " + e.getMessage ());2 Q* _. K' ^7 v9 r( n0 i2 l7 z
}1 C1 S( r1 ^7 l) A* Z2 v" B
v# m4 F5 h" {5 l: i9 H/ L8 w
// Then we create a schedule that executes the; c0 o; A& I; }! _
// modelActions. modelActions is an ActionGroup, by itself it
) I" i$ t3 H D, Q( Z! M // has no notion of time. In order to have it executed in
- I) D7 H5 ~* I% }' c: T // time, we create a Schedule that says to use the
1 B7 X& a( D% D8 x; P // modelActions ActionGroup at particular times. This
0 [) X3 _% B" d( } // schedule has a repeat interval of 1, it will loop every( k( |" e' \3 j1 T" I% g# h
// time step. The action is executed at time 0 relative to5 X- F4 x) E% w- Y; T
// the beginning of the loop.
. |8 |9 T; ^- F: r6 J+ q( U1 [4 g! E: n2 m
// This is a simple schedule, with only one action that is
; h8 q1 x& A3 V3 j% U // just repeated every time. See jmousetrap for more
9 y6 c% K4 Q& q) C% o // complicated schedules.0 e8 |3 P! a& T% q& p
& [+ P7 ~- y# P& n. Z2 I# p modelSchedule = new ScheduleImpl (getZone (), 1);% ?+ b: I# C/ u" g
modelSchedule.at$createAction (0, modelActions);
# u2 i. n# A4 d8 Z
+ X+ e/ p( [5 H' b3 ? return this;
/ h2 B' O/ U) |) M; T9 C j } |