HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
) h. x' J! a; r% b
5 `6 u$ h6 s @) Q! \ public Object buildActions () {5 f! s2 l2 ]2 J( j9 S7 _
super.buildActions();% V7 W7 u8 P* _* U/ R
' ~8 }4 a. E/ Z5 k& A- T/ ]
// Create the list of simulation actions. We put these in
9 X, K% V( q6 \$ E // an action group, because we want these actions to be) K/ M/ _& e" L8 J
// executed in a specific order, but these steps should
- l( d5 J5 C% Z* j3 A: G // take no (simulated) time. The M(foo) means "The message5 M1 `0 q! A" [0 m5 d% { e
// called <foo>". You can send a message To a particular+ `, o* P8 J3 S8 s0 S: T
// object, or ForEach object in a collection.
\+ t- _0 h! X- F : t7 A( k3 V$ b2 I& _
// Note we update the heatspace in two phases: first run8 J' b: S1 f. W [
// diffusion, then run "updateWorld" to actually enact the& i, W3 C) B& u) ? z% }# u8 D# P
// changes the heatbugs have made. The ordering here is
! p% Q# D7 L' l" d8 c: f // significant!
! w$ D, E1 w4 F( ]
9 ^ m: F1 o" K" M // Note also, that with the additional ~6 ]9 a: I9 o$ W
// `randomizeHeatbugUpdateOrder' Boolean flag we can
' S* M- U. u$ ~0 f. }: ^$ p9 }! S // randomize the order in which the bugs actually run: @. K1 G5 B" N5 ~9 c) w% Z
// their step rule. This has the effect of removing any
2 q; C7 Q9 j3 V0 P // systematic bias in the iteration throught the heatbug( y# s- k5 N9 J& x' [+ Z% |0 d) H6 i
// list from timestep to timestep) q) e$ n7 k& A" T# W
( f- c- f! H6 i d+ a2 ^; D1 t# ? // By default, all `createActionForEach' modelActions have
( \0 ]+ n6 P: q1 @& x3 m- ?2 N- h // a default order of `Sequential', which means that the$ f0 Z% ]& Z* X* p' U4 e9 S3 F" I
// order of iteration through the `heatbugList' will be0 Z5 X9 m9 A; O1 C0 K9 @7 S
// identical (assuming the list order is not changed( H; Z& v; e1 K# S. ?& v& u
// indirectly by some other process).
! x4 y- N6 C9 j& | + Z' R( I0 F/ M* h* v
modelActions = new ActionGroupImpl (getZone ());, v$ Q! P% C9 f
6 Y8 c, T V8 _2 ~
try {
+ s, G x: E: x# m modelActions.createActionTo$message C. J) @/ |# B
(heat, new Selector (heat.getClass (), "stepRule", false));& C% J& I: T4 q5 F. X9 B# s
} catch (Exception e) {
; }2 T! i) Y1 M5 | System.err.println ("Exception stepRule: " + e.getMessage ());
) v5 U; Y* S3 m# a: V2 X) h }
/ U+ t9 Q* K: {# ]4 I' W7 Z, }2 }
. X! A- B$ C( p9 k* e2 i' [9 R( r/ r try {1 G: Z# d+ D3 j8 d4 l/ W3 P* w6 B3 s
Heatbug proto = (Heatbug) heatbugList.get (0);4 V6 c' Z; r, b2 ~8 F
Selector sel = 4 `; b' v1 n( k9 z! a
new Selector (proto.getClass (), "heatbugStep", false);
7 ]$ [5 \8 P9 d8 i actionForEach =* e( S& G. S! I, Y
modelActions.createFActionForEachHomogeneous$call y$ L, ]- P7 k
(heatbugList,8 W. }6 b Y+ k, x6 _
new FCallImpl (this, proto, sel,/ G# w- p9 K9 Z( e
new FArgumentsImpl (this, sel)));
# H3 Z2 b8 f: m2 W+ O } catch (Exception e) {( c$ F5 n* F9 C' A& w1 e8 c, \
e.printStackTrace (System.err);
z4 t- }5 O6 u ~- Q }6 \) |8 Y- V0 W9 f4 c
' S. @3 P# u5 \
syncUpdateOrder ();
/ I; G2 U( Q7 |4 W/ d$ g6 `# V' f3 X( u" q2 ?& r/ T& Q) t k% N
try {% j8 Q, M2 g% B$ Y- A
modelActions.createActionTo$message
( `9 V7 Q4 P5 _8 Z, z% p (heat, new Selector (heat.getClass (), "updateLattice", false));* H Z/ `, ^0 d# s
} catch (Exception e) {6 z2 T ^7 h* `( g. W0 R4 O* M
System.err.println("Exception updateLattice: " + e.getMessage ());
1 v$ Q3 y1 B$ B& E0 P }& q. l4 a0 J3 h! _
" ]9 \! e2 V+ @1 X // Then we create a schedule that executes the
" C0 f; A) O; I0 i' W: ^+ Y. @1 I // modelActions. modelActions is an ActionGroup, by itself it
4 a0 |3 {' f( K9 }" B# _/ \% c // has no notion of time. In order to have it executed in
" x$ q- w* r% R: `% H/ e // time, we create a Schedule that says to use the
6 u1 J" ]( i4 o- ~5 C/ h2 ~ // modelActions ActionGroup at particular times. This+ \7 ?- @- V9 S4 h/ H7 [, b
// schedule has a repeat interval of 1, it will loop every
1 u* w# j6 ?9 t9 @9 v7 A // time step. The action is executed at time 0 relative to4 ^3 }+ Q, P- z# Y% x8 ]6 _
// the beginning of the loop.# H, A; C F* Z6 }' p
) j$ u$ D* D( j0 c$ N // This is a simple schedule, with only one action that is0 @4 F( \) Y/ C3 `- U
// just repeated every time. See jmousetrap for more
* m" v; Z- k# i! J) Q // complicated schedules.
8 [, z* O+ Z; k* J: K7 r' K4 G( m ( Y5 k7 W' E) G0 K b
modelSchedule = new ScheduleImpl (getZone (), 1);
& F5 ^' B4 c* M. E' q0 z7 r modelSchedule.at$createAction (0, modelActions);
; N8 E {( P, h( v4 G) Y) A0 a& D ( y+ ~) @4 e$ p! O1 a2 V3 @' C
return this;# |7 W" f7 q3 K+ Y9 F
} |