HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下: O1 m6 K" T, g: J' A! O6 N
" K, Y& L8 s. u; K1 |5 k% y
public Object buildActions () {% P9 s% U" r' g# V( l+ p
super.buildActions();: o, Q* A# V2 w4 z$ t
( q9 `, y5 ]8 M6 ?$ P5 t) q
// Create the list of simulation actions. We put these in
$ ~, x2 V! g# b& F) L( X // an action group, because we want these actions to be& m0 p: J# r) n* _4 z. C
// executed in a specific order, but these steps should
4 o5 B! O/ N" r& s% m' O // take no (simulated) time. The M(foo) means "The message- D" g n3 R* e: j. x/ _
// called <foo>". You can send a message To a particular( @! E6 C: D2 j' `
// object, or ForEach object in a collection.
* M+ y% O, N% \) X$ q* R
! b9 y$ h: ]+ `1 @, { // Note we update the heatspace in two phases: first run; E6 m9 z/ I4 v
// diffusion, then run "updateWorld" to actually enact the
+ {! q* D }4 k5 ` // changes the heatbugs have made. The ordering here is# P- g$ Q7 e3 w5 k7 v- v
// significant!
0 ?3 j$ N9 Y1 U1 ]; O8 @9 _# e$ e) v
, g i& {( |- l; e0 J // Note also, that with the additional0 J$ }, o8 n$ X5 i2 S1 e
// `randomizeHeatbugUpdateOrder' Boolean flag we can# x2 d+ N b: B4 b! F8 x- Q
// randomize the order in which the bugs actually run
+ i) u$ c: r7 a) m1 N+ D% X& C // their step rule. This has the effect of removing any
* L# P& ]; T8 V& Y' k // systematic bias in the iteration throught the heatbug
8 P/ B! g! Z% e: _% t2 M1 v0 [$ G& U. ~ // list from timestep to timestep9 a( X x. @: I) P/ N5 d/ c, b
* ^) X% Y' I6 s) Q. R" i/ ^+ ^ // By default, all `createActionForEach' modelActions have( S+ z5 \9 R/ e1 W# |( \- o
// a default order of `Sequential', which means that the
. ]7 k& O( |) n& K G) X; p // order of iteration through the `heatbugList' will be
- H* }$ F+ ?$ }! W# O) p" \ // identical (assuming the list order is not changed
( H& I7 l; b, H# M! L // indirectly by some other process).! N5 G; [/ j2 d5 H7 m$ v! C
& R1 r$ p5 d% y9 c* p+ Q( a
modelActions = new ActionGroupImpl (getZone ());: c* n) u" Q; m- {# W
$ u _0 t. h4 X8 K
try {
9 M5 x( g: z) S9 C3 Y3 i- Y: x% ` modelActions.createActionTo$message# P* X# E A- b5 g
(heat, new Selector (heat.getClass (), "stepRule", false));" B3 H. H7 i( F1 a p6 M
} catch (Exception e) {4 B& w4 N0 e& t. @; s- U
System.err.println ("Exception stepRule: " + e.getMessage ()); u0 a: @1 p8 |3 x1 ?# O) ?0 A( _& p; h* Q
}+ ]* J/ w3 q7 s4 n* B- j
3 ]: C7 ~8 j j; r& H0 L try {
2 C/ Q5 g; I) G3 D: ?8 B Heatbug proto = (Heatbug) heatbugList.get (0);
" X% j. x8 c* u5 M Selector sel = P Q& R) h9 O0 S& c$ s& N9 E
new Selector (proto.getClass (), "heatbugStep", false); s$ M$ D/ Y3 t8 V D
actionForEach =3 ^0 B* B2 H* m# G5 c+ c' d# q
modelActions.createFActionForEachHomogeneous$call
( Y6 W, D; k5 i! X- J& Q; h% @ (heatbugList,
% X, w! v% q& y9 J ^ new FCallImpl (this, proto, sel,
1 o1 P* O0 B6 h. k3 p new FArgumentsImpl (this, sel)));$ {* g. x, e3 ?! T$ s4 m
} catch (Exception e) {
0 x6 x* O: t6 z: B" \, a e.printStackTrace (System.err);$ D' }8 l6 ]" K7 A
}# [+ Y/ n- `# q: j, o9 `; c
- B/ d. F% d9 V; F' i6 B. E% @+ g syncUpdateOrder ();
1 ~% v- U' j# P s3 ?, z! T) B& P& n0 U5 C/ C( O
try {0 F! N1 t- M% W4 @6 z5 O5 J0 K
modelActions.createActionTo$message
+ \; @' |0 L$ V9 m% J+ Y. ]( n) F (heat, new Selector (heat.getClass (), "updateLattice", false));2 d% U' R. F+ M
} catch (Exception e) {8 N5 ?* o- |6 [+ ]) Y
System.err.println("Exception updateLattice: " + e.getMessage ());- x# }# K* G: B# r. y# P! b: E
}! I) c5 B5 f4 h1 ~+ E' ] @2 e
& ^! p' l" h$ C& F# ]# P) F // Then we create a schedule that executes the( m, j- `! S' p6 o3 x( v: i: T" Q
// modelActions. modelActions is an ActionGroup, by itself it
9 o* {/ g) R4 q // has no notion of time. In order to have it executed in
4 }5 R0 ?* B! {3 s3 U5 S9 d8 A" `" o // time, we create a Schedule that says to use the0 O" G3 s2 N# |% ~9 o
// modelActions ActionGroup at particular times. This- h. L. f# E; n$ d. @
// schedule has a repeat interval of 1, it will loop every
# ?7 u. w0 [: o" Z/ ~- Y6 e# ` p // time step. The action is executed at time 0 relative to/ i3 v! Q! h2 L; D* k
// the beginning of the loop.0 M3 P- I0 x: y
6 l3 j/ Z% X5 c& F! U A8 L, a
// This is a simple schedule, with only one action that is$ C5 }/ ?! [* W2 A8 B- d% X
// just repeated every time. See jmousetrap for more
6 x9 y, v- M. i9 ~! [5 M // complicated schedules.
1 I; v, u: [ Y8 G& E" B6 g8 q
% k3 _! F+ I }& R- Z. Q modelSchedule = new ScheduleImpl (getZone (), 1);9 R9 f7 L. Q7 ?4 z% `" d- U
modelSchedule.at$createAction (0, modelActions);; k; S$ ?; m& w0 C% n y1 Z* N# B& Y
$ v: e1 [7 E( j5 j1 e return this;, j" y& e# `: h: `' V3 X
} |