HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
' y9 y+ ~: s, K2 R3 a& s' |8 U2 T6 [- E8 |
public Object buildActions () {
, S0 v) q2 Q0 K7 H super.buildActions();
; S, h. z/ t9 t+ U
. m, U; K& v5 ?7 r0 n$ H. T // Create the list of simulation actions. We put these in
# D2 u) t/ E" O2 r# Y // an action group, because we want these actions to be- D. M& N% a6 t' J
// executed in a specific order, but these steps should
- W$ W, M$ G( E: K: q // take no (simulated) time. The M(foo) means "The message r" Q( }! E' p% h; u* @9 I! A# p
// called <foo>". You can send a message To a particular4 [( }1 ]; j9 k0 _" C
// object, or ForEach object in a collection.' W' W0 Z, o4 U; |
$ ^$ l; l9 @4 Q" l/ v9 v // Note we update the heatspace in two phases: first run- f8 j( V5 w3 S P$ Z/ Q
// diffusion, then run "updateWorld" to actually enact the
4 } V- D- Z6 C' w+ f* l# w // changes the heatbugs have made. The ordering here is' w: ]/ O, G" R
// significant!+ t' P( X* y+ b# K
" [" T- R# \! N, |* @! L8 K
// Note also, that with the additional
/ I: W% D G6 u. }1 { // `randomizeHeatbugUpdateOrder' Boolean flag we can; G& J, r# l' F
// randomize the order in which the bugs actually run
" n8 _' Q! M$ N; V // their step rule. This has the effect of removing any, n# F& t t6 J% j( H) [
// systematic bias in the iteration throught the heatbug( v6 ]6 u s" L( P6 Z U- e! s9 z
// list from timestep to timestep8 Q' P7 A$ \0 b @. g
- V9 J& D* Y$ g4 S5 Q/ p$ B+ ~
// By default, all `createActionForEach' modelActions have
; u; T# j: y3 Q6 k // a default order of `Sequential', which means that the
2 F9 \, `7 N9 _$ ^- g& t- ^4 i) E // order of iteration through the `heatbugList' will be5 a/ K7 b* S9 M9 X
// identical (assuming the list order is not changed9 ^% x) E0 p9 X. J) @' O, Q- ?5 Q
// indirectly by some other process).
& x% T. N: |: z1 M) Q& i 3 Z( R5 `% H, h7 R& a
modelActions = new ActionGroupImpl (getZone ());0 x* ~; i! k, t0 O9 d
3 b0 q/ v: \; J try {" p' m2 \# p) s/ e( ?' L. }
modelActions.createActionTo$message! U/ T7 W# K3 u& g
(heat, new Selector (heat.getClass (), "stepRule", false));: N4 U2 _! G, g# K/ T2 z
} catch (Exception e) {: h7 n* ]" n* g; n' O" b5 k+ n0 j) o8 I
System.err.println ("Exception stepRule: " + e.getMessage ());
6 n3 X C8 }& `. _2 X9 ? }& L+ S3 P/ ?) o( i8 V; R* w
% ~0 r4 Z! {5 [) O) b" a$ ^8 p* { try {7 l1 r+ X2 t9 S8 S+ k
Heatbug proto = (Heatbug) heatbugList.get (0);1 ^7 b7 |; i% O
Selector sel = # a* V5 f3 G9 P9 _$ c" `
new Selector (proto.getClass (), "heatbugStep", false);, G5 ^0 b/ G# \% U, r
actionForEach =8 W: q" b2 A0 |4 w7 H
modelActions.createFActionForEachHomogeneous$call
: F5 v: |& Z8 L (heatbugList,7 G; S1 ~" M$ \" d! _5 k- l4 e
new FCallImpl (this, proto, sel,$ h: |# V" v- s, S2 L* t9 r5 w
new FArgumentsImpl (this, sel)));
3 [/ Y' V# u9 U8 N% X( v% K5 y } catch (Exception e) {
" ?* D# D5 l" A: w/ W e.printStackTrace (System.err);$ d1 p9 B5 r5 [% L& o1 @ N
}$ j5 ~& j2 B% M2 O; [* j% I
0 ~- Z& ]8 @# M8 Y; n3 C syncUpdateOrder ();
% ?0 [3 ~3 O) m4 B0 z
+ E+ m, R4 y" t% @( r7 W: s try {7 w8 ^8 a2 U! B2 l) s' p2 `3 i) T
modelActions.createActionTo$message
, _) L6 u) O# X1 v6 R* ? (heat, new Selector (heat.getClass (), "updateLattice", false));
1 {$ }% ~, E5 o. M( L& x" t! C$ [ } catch (Exception e) {8 ~2 O) u- M$ u: T' N7 `3 l( l
System.err.println("Exception updateLattice: " + e.getMessage ());5 v I, m9 P K, ?5 t$ f
}
3 x% P. S. k2 U( l, h7 P) G ( c. q9 w) w. G7 A- a
// Then we create a schedule that executes the6 Q* z, X$ G3 m0 t5 F# {; b
// modelActions. modelActions is an ActionGroup, by itself it
% U& {& p; A+ x% {5 n- T // has no notion of time. In order to have it executed in' p: O! X6 W- p. m& p+ B
// time, we create a Schedule that says to use the
; l) M) e# Q! Q! L5 V // modelActions ActionGroup at particular times. This9 p0 D2 L$ V2 Z5 H! `
// schedule has a repeat interval of 1, it will loop every
- s+ i) K2 H5 w5 s$ z3 M // time step. The action is executed at time 0 relative to9 ^) u# |, e- k+ \& G* H
// the beginning of the loop.) J7 b* k2 N& A6 o
* `' E# P! p% Z) Q( l; x: X
// This is a simple schedule, with only one action that is3 J! H* C/ u( n5 c! B% L3 u
// just repeated every time. See jmousetrap for more
8 ?# t( [3 v8 ]! | // complicated schedules.* K0 O6 o. _# v1 f% `+ }
4 p* n' g0 l2 F" s: W
modelSchedule = new ScheduleImpl (getZone (), 1);
( [( g& b0 h7 w+ n! X7 Y3 A( Z modelSchedule.at$createAction (0, modelActions);& A: F7 d: R" F* K
2 y' {- b3 {2 @! E5 v9 w
return this;
* X8 T0 n0 \: ? } |