HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:* \+ A6 f8 u) ? P
/ V$ ~5 R: p9 U4 E; Z public Object buildActions () {9 K8 ` K4 n* L. ]7 a
super.buildActions();
2 u! T, I0 Y8 c0 Q ; _. _+ h7 I, [3 s
// Create the list of simulation actions. We put these in+ U/ e! f" [- @$ B+ \. F. o
// an action group, because we want these actions to be
6 K! ~( @ } ^, O% A( h // executed in a specific order, but these steps should
7 B6 {* }" z3 G // take no (simulated) time. The M(foo) means "The message. E9 U/ K4 w- m. B. Y5 v! x
// called <foo>". You can send a message To a particular
" ]1 m% x7 q. t8 S5 u9 l9 ~ // object, or ForEach object in a collection.) _' T) Y) [+ A+ _5 Q* I1 T
; w- F9 R$ N+ ?. i' J // Note we update the heatspace in two phases: first run
: N% |( D# Y3 B' D0 e1 n // diffusion, then run "updateWorld" to actually enact the2 G1 r5 [- o; a9 h* G$ x: q. a! T! d4 H1 G
// changes the heatbugs have made. The ordering here is
' l( ~. S, y6 Z- E) W // significant!9 b# Z3 j3 Z" Y6 ]. f
9 T$ X3 f& Z9 B0 [ // Note also, that with the additional
0 O9 W2 ~7 X& l# P1 M // `randomizeHeatbugUpdateOrder' Boolean flag we can4 r# y" j/ d, W/ v/ R
// randomize the order in which the bugs actually run
' z( c ^. t& Y( T4 N' B( ] // their step rule. This has the effect of removing any k0 {* J" S/ B# O* d- T
// systematic bias in the iteration throught the heatbug# O/ b1 m, S) Y! F
// list from timestep to timestep
a7 ?8 q+ \8 `! X- P: ^8 K C! h 7 @5 q" |2 x, u- l9 d
// By default, all `createActionForEach' modelActions have
" O$ I/ m' F7 C6 ] // a default order of `Sequential', which means that the7 K; O. @" ^) ?3 f
// order of iteration through the `heatbugList' will be& Q; u, a! Z# t! J$ s
// identical (assuming the list order is not changed! i) h6 s* n5 J& z* y' |: `+ q
// indirectly by some other process).! o Y) J- u& V0 p# _1 F# |
9 U5 _$ ?: d( k% T" J modelActions = new ActionGroupImpl (getZone ());
1 z1 E/ \6 [+ w0 L0 w6 l- W1 v9 p& [( j- e, Z5 A; W5 b% Q
try {: Q p7 \# S; A0 B* [. s/ _, m
modelActions.createActionTo$message4 ?( P7 T% N+ T2 O
(heat, new Selector (heat.getClass (), "stepRule", false));
* @& _9 z" X, I! t+ l$ R; g7 P+ f+ A } catch (Exception e) {
# T6 B4 v$ c& L$ p3 w/ S System.err.println ("Exception stepRule: " + e.getMessage ());
0 g3 \5 o2 u, k: X }
( h7 k2 e! o" G( u+ ?) p6 L7 p- b2 N: i$ }& o
try {) v; P$ b+ \ [% `1 h4 q
Heatbug proto = (Heatbug) heatbugList.get (0);/ G6 Z, K' \, y; w8 @
Selector sel = + j! O" }4 p- Q% H) y
new Selector (proto.getClass (), "heatbugStep", false);. F4 q; n2 X7 I3 \( V# F
actionForEach =
) E- W; f% ?$ \* O/ K' a0 d. C modelActions.createFActionForEachHomogeneous$call
% ?; b7 n# T: k8 E (heatbugList,
9 t* v2 K# ?3 A/ _0 ~1 m7 m new FCallImpl (this, proto, sel, k4 N" m9 d5 x* v; w4 U& M7 A" v
new FArgumentsImpl (this, sel)));3 P! d: I2 W' K* g
} catch (Exception e) {
4 Z3 ]2 }. U/ }4 V* q1 O' a, P! y/ g( R e.printStackTrace (System.err);! L2 y$ o' M- C6 h* c" X# q N& L U
}
" W- G* T! f) B- b- x $ D4 N0 \' D1 a! g! _$ ?' T9 ?
syncUpdateOrder ();7 x6 v8 q% [6 Y) O
% [2 @4 a$ M1 H2 X# Q7 A8 i try {
& u0 b Y+ M3 A& T8 X* i1 {. w+ X modelActions.createActionTo$message / v( A$ h& X$ z/ q3 g6 [ x- n
(heat, new Selector (heat.getClass (), "updateLattice", false));
1 B2 i: ]7 I7 J: {" q( d } catch (Exception e) {
$ f8 C% w2 i- S x/ B' }# h System.err.println("Exception updateLattice: " + e.getMessage ());: i, F" t! s3 m2 x
}$ q1 R: I4 `0 D: s% K1 O, ]5 C6 \
2 b- E& z j) o/ z4 C // Then we create a schedule that executes the
# Q0 L& P* N' G# d( G# P // modelActions. modelActions is an ActionGroup, by itself it H$ {1 A$ c! j, T
// has no notion of time. In order to have it executed in7 l* i6 `1 ~+ Y2 l8 J r" y3 E
// time, we create a Schedule that says to use the6 X! n( e! m5 Z) i$ h6 O1 w% ~) j
// modelActions ActionGroup at particular times. This& G8 ]( [, }( C" t' [+ x
// schedule has a repeat interval of 1, it will loop every( w3 J/ }$ ]1 e! e% F& }) V s
// time step. The action is executed at time 0 relative to4 s. O, `% w g7 N- H
// the beginning of the loop.' @+ u1 t3 c7 G- P. L9 d( O
9 ^& m) m. W* h& G$ k T
// This is a simple schedule, with only one action that is" j% M2 c# l5 x! S& j j% Y+ R8 d
// just repeated every time. See jmousetrap for more
+ o3 d: H* h: A' X* |* C6 P6 p4 k // complicated schedules.# b/ Z8 D; o1 N7 j& N: Y! O
. Q* u; y' r) U# n, y k
modelSchedule = new ScheduleImpl (getZone (), 1);7 O. p8 T: q7 {1 Z9 |! }2 }2 q/ Z
modelSchedule.at$createAction (0, modelActions);- o0 \/ U' C, t, c( X
1 N) W8 Z3 ]& x. p! a/ d return this;
, r; w5 R v2 |' x2 x } |