HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:/ b& h% ?+ c+ D5 @$ k# z
3 t) Q$ n5 _% ^2 F) }5 X public Object buildActions () {
+ d" c. F1 I: s: B9 t( S5 W7 P super.buildActions();
# m1 |$ n3 u* Z; x5 d9 y ' q+ J3 }2 ], B0 L# z
// Create the list of simulation actions. We put these in* `: z# d0 u- w: N' h' o! P
// an action group, because we want these actions to be2 c4 D8 x9 M5 G2 E. h
// executed in a specific order, but these steps should
. |* j7 H7 N' {4 | [! a // take no (simulated) time. The M(foo) means "The message# F8 Z4 E/ {$ R! A7 p
// called <foo>". You can send a message To a particular5 S6 X# H4 n) R+ V& Z8 o
// object, or ForEach object in a collection.3 p* Z2 j; E4 U- i3 d: B7 x% H
. ~5 t7 O( m: _ m1 N! { // Note we update the heatspace in two phases: first run$ B( |9 ~& j, A
// diffusion, then run "updateWorld" to actually enact the
w: [( u, e) d! ^/ Z- a: g // changes the heatbugs have made. The ordering here is
; ^" r7 Z+ I$ H. L: I1 z! j! Y // significant!) f/ N; e) F5 J3 j) e4 @9 n/ V
. p/ H( ~3 ]- }" f
// Note also, that with the additional
# g6 J3 c3 U( \ I8 `4 x: V // `randomizeHeatbugUpdateOrder' Boolean flag we can$ R9 Y$ K+ A3 T8 O
// randomize the order in which the bugs actually run
7 \' Z6 m. a0 f4 X7 h // their step rule. This has the effect of removing any- `% ]1 ~) }" b5 d O
// systematic bias in the iteration throught the heatbug b3 X- C& z# n
// list from timestep to timestep
6 ?' G( r; S5 S( J1 B$ _# K 0 \5 _0 m! s" y9 x B% R" H; q
// By default, all `createActionForEach' modelActions have
* I" d8 j; W' `0 k( D# w& v* g2 n // a default order of `Sequential', which means that the
5 c, W! [) \7 G5 O* a$ P1 f2 P; d9 T2 s // order of iteration through the `heatbugList' will be
( t D$ [, p% ^5 C, F/ ^2 G" v+ b+ K% s- j // identical (assuming the list order is not changed
9 S Q. v3 V7 o1 X$ E/ r; y // indirectly by some other process).) n% ]0 P: `: _- [! ^
* z$ c3 a+ Z( r/ `5 r, K modelActions = new ActionGroupImpl (getZone ());
/ y5 |* O7 r5 ]5 O! k% O
: b2 Z! O1 ~) U5 r" d try {4 E2 S1 B7 Y! \% ^5 B
modelActions.createActionTo$message
$ p4 S. P1 U" \! u2 X* c (heat, new Selector (heat.getClass (), "stepRule", false));0 Q3 |) Z! X/ J2 v
} catch (Exception e) {
9 }2 g6 U; U& Y: u System.err.println ("Exception stepRule: " + e.getMessage ());
5 ?$ N( V, e) {! H( c0 H }
) \; t8 ~% H, `1 z
# n, b9 D' D8 \+ c4 g/ a ^ try {' E8 Q2 l% x3 r6 @& |/ ]8 i
Heatbug proto = (Heatbug) heatbugList.get (0);4 a" U8 N1 Z+ T) |( j1 ?. W3 y% }
Selector sel = ) @6 ]: V) B; b0 C* |2 ^
new Selector (proto.getClass (), "heatbugStep", false);
% Z& h* h. J o5 M$ ^- U+ m/ b actionForEach =% W2 h$ A8 K4 t# t+ z% m
modelActions.createFActionForEachHomogeneous$call3 k! I* o7 x, l' w+ o, w+ l" r
(heatbugList,# `, `' E( R6 w; Y a
new FCallImpl (this, proto, sel,
9 O/ r- Y$ ^9 K0 e new FArgumentsImpl (this, sel)));$ j$ [" D. G$ w2 d" H6 N
} catch (Exception e) {
3 |5 Q. k- x$ V6 R: B" W; s* a e.printStackTrace (System.err);
" e, C7 K. V3 K6 J# k: t }( y2 p, S% }! g+ C' V
/ X& @/ _. `0 O7 S8 ]/ C8 G, y8 h
syncUpdateOrder ();$ i5 j' S6 d6 l
3 @# H- }8 G! f0 F' e" ]9 [8 C" C' } try {. J8 ~6 i6 Z' |& O g. p
modelActions.createActionTo$message
) S8 B0 Y/ `1 z* \% B* T2 i" J (heat, new Selector (heat.getClass (), "updateLattice", false));
" H. `4 W% @9 }& n8 B } catch (Exception e) {" c' T9 c' g( ?, Q
System.err.println("Exception updateLattice: " + e.getMessage ());
4 H) h; w) j% H2 o" j }
& _/ y& R% k' V3 r$ `
$ e# a) y2 i' }: _+ I) C // Then we create a schedule that executes the* G. G+ I) O& A8 a' H- F
// modelActions. modelActions is an ActionGroup, by itself it3 F+ [( I' y) z
// has no notion of time. In order to have it executed in
3 B) _) D; V- c. k' r // time, we create a Schedule that says to use the
/ e8 H8 i8 s( e, E$ |: s7 o // modelActions ActionGroup at particular times. This( x; g7 @' x! F% S5 C5 D
// schedule has a repeat interval of 1, it will loop every
3 n' y1 R7 F) I! H, z2 i" c" | // time step. The action is executed at time 0 relative to
& @7 J3 w3 w( D4 A& ?( ?- h0 l // the beginning of the loop.
- ^% W2 y, |) w0 m# q
' S$ J% v# p9 L // This is a simple schedule, with only one action that is
0 E9 i- F; S" H/ [6 ~3 O; h! W // just repeated every time. See jmousetrap for more
3 W$ V" `+ H6 {# f( n$ g // complicated schedules.
- X* y( U8 l) ~* `* b ' t* K' Z9 w" ~& `) o+ [* O
modelSchedule = new ScheduleImpl (getZone (), 1);9 ]! z: F/ K& a, ^2 e) o
modelSchedule.at$createAction (0, modelActions);1 G( N2 Q: c8 }& w* l. v/ e# K$ L
+ m/ |: V4 u: D/ W return this;' m, i2 h( e0 U( q& ~( r
} |