HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
1 o/ ?+ t& {0 }$ R, S( [3 Y
/ g9 K' y9 |2 J5 O% h Y, P3 R public Object buildActions () {" F+ i4 z1 x& f1 G9 c
super.buildActions();
, z c7 {, B4 ?4 m# ]$ M - D- W9 ?: m7 n
// Create the list of simulation actions. We put these in
- M4 B0 l' {: U! ]; h$ E // an action group, because we want these actions to be
% c! P, e% N( P+ h4 D // executed in a specific order, but these steps should7 j! H/ r$ }8 j$ G& D
// take no (simulated) time. The M(foo) means "The message
- G/ Z3 b' n7 H) K* { // called <foo>". You can send a message To a particular
) t- ^8 X9 s9 B8 b' n3 `4 K // object, or ForEach object in a collection.
8 B4 V" K1 D0 ^ 1 v9 X2 O6 P4 l4 Z
// Note we update the heatspace in two phases: first run
; X8 e j3 z1 Z$ i4 \% b // diffusion, then run "updateWorld" to actually enact the3 S+ z( W( d3 ]2 Z8 v% e
// changes the heatbugs have made. The ordering here is
: Z4 }" _. q, I. G: Z& L // significant!" m; }: M: m! g9 S
- D2 U' G3 f F3 p" W
// Note also, that with the additional P2 ?5 E: s3 U
// `randomizeHeatbugUpdateOrder' Boolean flag we can
& o7 c9 f9 W; `7 T" a) a // randomize the order in which the bugs actually run
5 E$ \8 v$ w# N* H% I // their step rule. This has the effect of removing any# i1 s1 h' n6 n0 b8 s) ]. t
// systematic bias in the iteration throught the heatbug3 W" [( W5 U& D2 I* y, \) V/ r
// list from timestep to timestep
; V. r2 H4 s+ t* i: e) E
1 z& i) y) ]" ^& K2 X3 v // By default, all `createActionForEach' modelActions have- v! S8 e- s4 D( S. O0 r7 B5 t
// a default order of `Sequential', which means that the: f. s( q% B [. k, b
// order of iteration through the `heatbugList' will be! s( ~4 Y+ z. B: A
// identical (assuming the list order is not changed
6 M' k' g, P5 x+ }& Z // indirectly by some other process).
' e) y# ?& q X: y4 b' O) y ( ]) \& k9 I" t4 K+ N6 m4 z
modelActions = new ActionGroupImpl (getZone ());. r. K' ?, D/ P& W- j
+ f8 w) ~- m4 w0 O- ]- o3 r try {! `7 R6 E/ h4 j% F1 l- l
modelActions.createActionTo$message
6 S3 I9 E6 ^9 N4 K# q (heat, new Selector (heat.getClass (), "stepRule", false));
4 @' n0 J* V- r: V" D7 i } catch (Exception e) {9 m, r* w4 x' [ E" b8 O. x. E5 a( A; W
System.err.println ("Exception stepRule: " + e.getMessage ());; T) A# v$ \( L: A
}
0 H) K* f' O% J3 m1 G8 W6 m1 ?6 J
/ R' E* J. y& n; b try {
( j0 m& t6 Q( X6 f$ h- M9 w, D \ Heatbug proto = (Heatbug) heatbugList.get (0);
9 f, V& h( [3 |& s. U5 Z+ j1 o- P- } Selector sel = 3 G: X, w$ d, g a; C Y8 g
new Selector (proto.getClass (), "heatbugStep", false);
5 O: Q0 E% l8 o1 v" Y actionForEach =7 U) O# n3 O, ?- {7 j, J
modelActions.createFActionForEachHomogeneous$call
+ F" ~0 [ ^" L' B4 D (heatbugList,: H" g. w- |% z- o8 {- G, ~
new FCallImpl (this, proto, sel,
) |. w& v% Z7 F% v6 a/ c new FArgumentsImpl (this, sel)));( [9 C; R$ t4 Z4 F9 P d* A
} catch (Exception e) {, m* N$ O/ Z& p7 |9 k* G
e.printStackTrace (System.err);
, C* }$ ~; t' ~* p }2 i2 ^$ y4 M, f& m. Y& [
5 |0 E7 Y1 C% { Z# V: S# j [3 c
syncUpdateOrder ();7 b9 e- \( _) N$ Z# D
P6 f8 N; h2 w$ Q try {
9 P2 g* j ~4 t modelActions.createActionTo$message 8 ^- Q' c/ Q( N! x: ?/ @
(heat, new Selector (heat.getClass (), "updateLattice", false));
+ b1 C8 q" d4 }5 U2 P2 v } catch (Exception e) {+ K: X5 h6 Q5 m) p; G5 ]0 j
System.err.println("Exception updateLattice: " + e.getMessage ());
% Y$ @2 Y8 N# k. w$ ~4 b& B0 B }
5 T% E# A. |( L/ t
8 B( \# N6 z) g* ]; ]2 C7 t% d. A5 q // Then we create a schedule that executes the& d7 o7 v1 i1 Z- O9 |5 q& u& v) E
// modelActions. modelActions is an ActionGroup, by itself it
% d0 S% ~0 d- j1 V // has no notion of time. In order to have it executed in- J2 {: T- O$ r4 {' W' u6 ~4 K
// time, we create a Schedule that says to use the, {% l' o0 f9 ^$ s) L, ?
// modelActions ActionGroup at particular times. This
' Z l. l f# j# Y% ` // schedule has a repeat interval of 1, it will loop every$ ?. [" l0 v8 H
// time step. The action is executed at time 0 relative to
! ]. t. i% z# H8 [3 i) O0 T( | // the beginning of the loop." y1 \/ b: m4 ?/ a) N: q
4 O% ^- u* u: w& T6 \2 Z // This is a simple schedule, with only one action that is
0 }2 ]& v: [- Z$ g1 G( L5 } g // just repeated every time. See jmousetrap for more
) c% x, \! I" F$ r // complicated schedules.: v9 h8 w' _+ m3 o" y. p
8 [8 ~' t' e: [$ K# x1 ~ modelSchedule = new ScheduleImpl (getZone (), 1);; a$ Z% g' h# P0 g+ e
modelSchedule.at$createAction (0, modelActions);
; Y- u4 A+ l5 s$ e( q$ j - |- g& c7 l5 O3 I$ d: [
return this;
+ G3 b1 {- Z% ?% |' Q O$ D } |