HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
% M( i- f$ }$ a1 w
. Y, X3 r6 H+ }0 h+ w public Object buildActions () {
5 X: z7 l& E( c super.buildActions();
2 P! ]3 o, N0 V8 U
9 ?' C* T8 Z$ [9 r1 a/ E // Create the list of simulation actions. We put these in
; ^0 R6 W6 N8 w# d6 C# B- B' b // an action group, because we want these actions to be4 w! N; C' f4 l. a) _; X1 \/ b, A
// executed in a specific order, but these steps should
% r" Y% G, ~" }1 T* M; j. K // take no (simulated) time. The M(foo) means "The message
2 u% k& p/ s& r3 S) p. {# B // called <foo>". You can send a message To a particular
/ j' [; C8 A) D6 _ // object, or ForEach object in a collection.0 Z* N: L7 W* t2 J% q; Z5 F- v
0 s; J2 \4 Z7 Y: L+ o // Note we update the heatspace in two phases: first run, s1 r' w( n5 H/ v, B* u+ V
// diffusion, then run "updateWorld" to actually enact the
( a D& b/ d% r' N( K7 x // changes the heatbugs have made. The ordering here is
6 K- s6 i, o! x2 p // significant!
# s; N4 d) X2 a6 I + f8 e( a7 D; M# h$ F
// Note also, that with the additional
8 w: ]0 l0 G3 e5 t- S3 C# C% g // `randomizeHeatbugUpdateOrder' Boolean flag we can1 h) x$ T. q. Z s3 e
// randomize the order in which the bugs actually run4 K9 W6 X) C+ x
// their step rule. This has the effect of removing any. X; o. M$ }2 k& V d. O# d
// systematic bias in the iteration throught the heatbug
0 z) l2 Q& o' u+ D // list from timestep to timestep" S9 t! p% [. I; b& P0 Y; ^; n
8 j, d7 \- w3 V3 I% g' C4 @ // By default, all `createActionForEach' modelActions have
- n1 }; ?$ b) k; l4 D/ ^ // a default order of `Sequential', which means that the
; }, d" V' ?2 Y, M. k // order of iteration through the `heatbugList' will be1 m; O, N; l. ~) n7 {
// identical (assuming the list order is not changed$ g1 s) Q; b/ ^. l! Q
// indirectly by some other process).% Z, n0 x; `& R
& w. b- ]. b% j6 U0 }1 l0 K7 M
modelActions = new ActionGroupImpl (getZone ());
% _# Q, {# a* T+ \: K2 _
) f0 S8 J: h. ]$ ] try {
: }$ Y) o) ?2 U: \ modelActions.createActionTo$message
, J1 A4 `& Q. S (heat, new Selector (heat.getClass (), "stepRule", false));" n! X. w3 v8 ~, ]& W
} catch (Exception e) {
4 i$ J! f3 q( m; Y System.err.println ("Exception stepRule: " + e.getMessage ());
. U) P& k& w' r# s0 Y5 o }& W, f* v+ h' g q) q, ]) L \- ]
@4 m. I" c& z* h! B
try {0 [$ e! z9 W, w2 ~# \! \1 Q: F
Heatbug proto = (Heatbug) heatbugList.get (0);
1 L& H8 c, d+ }. H Selector sel = # p& r0 F6 [: Z8 N& Q
new Selector (proto.getClass (), "heatbugStep", false);- l: K/ k8 {* T$ e% E- I
actionForEach =
4 ?6 p2 f& @) G' k! r: c5 J" K( d modelActions.createFActionForEachHomogeneous$call: P1 C5 h. q2 V' g* W; H/ x& ^3 e
(heatbugList,. z8 R8 h# [0 x& K
new FCallImpl (this, proto, sel,& J7 p/ V8 N3 b
new FArgumentsImpl (this, sel)));8 A: l, Y5 `( U0 k* g: S: N
} catch (Exception e) {
6 s2 a5 M5 K/ ^1 G, ^6 C& D e.printStackTrace (System.err);5 s% A+ S! I. C/ m% K) f* V
}
' a/ G( F6 l/ {; ^ 5 i7 Q, K) Q f) @
syncUpdateOrder ();$ l8 a1 m% ]5 f W
1 j7 v8 _# X3 w4 Z2 N try {) z8 K- B* _& D/ k0 H
modelActions.createActionTo$message
" R: P4 [# |8 f) v (heat, new Selector (heat.getClass (), "updateLattice", false));
" \+ r& F6 h6 Z } catch (Exception e) {
" d8 w7 h! u1 G5 v8 y' b2 u4 a4 @ System.err.println("Exception updateLattice: " + e.getMessage ());: c9 c* Z) `2 E7 c w# |# u
}, w# m0 Y' w( s$ W, s6 B- w! b' j
1 U6 f u9 U% \ // Then we create a schedule that executes the3 ?% {& N8 r1 X2 _% f4 p- B
// modelActions. modelActions is an ActionGroup, by itself it3 D. y A a+ z6 x
// has no notion of time. In order to have it executed in8 k- Y2 O: G- M
// time, we create a Schedule that says to use the7 T0 ~+ Y( Z; U- e! a% m( `
// modelActions ActionGroup at particular times. This
5 e( h# M! q2 O // schedule has a repeat interval of 1, it will loop every
/ o% G9 H$ A1 L( c$ B // time step. The action is executed at time 0 relative to
. \3 y: [6 k4 @0 [, l // the beginning of the loop.
( t* y" Z0 P& l) ^4 p! K' ^$ H
# {" I# m# R, ~, W // This is a simple schedule, with only one action that is
1 F8 X+ b4 q |. ]* N' _ // just repeated every time. See jmousetrap for more
+ W) {. d( l' E9 z9 m // complicated schedules.
+ u7 r% Y' ?% b; V/ t' g5 A$ ] , _" G. K# U2 O! J
modelSchedule = new ScheduleImpl (getZone (), 1);+ r6 k% }5 A$ x
modelSchedule.at$createAction (0, modelActions);7 V5 o! H f- b: x
( {* g: x8 t i( Y( k! Z6 ~ return this;
- [9 w! W( |4 _* w# \/ z0 r } |