HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:) f$ x& f' c: I" a0 `4 A1 p
1 i& h7 _. k( U
public Object buildActions () {9 J8 v0 m0 _4 E7 A+ e. u
super.buildActions();# d" w. b( T2 E8 J) q
! r7 ^% q( o) ?7 d) T0 ~& F // Create the list of simulation actions. We put these in' C6 s n# h; z$ E: e5 A2 X- r
// an action group, because we want these actions to be( l J U8 S( y- i- H$ E- G: B
// executed in a specific order, but these steps should
% [" x- w* o% P$ s" W. C // take no (simulated) time. The M(foo) means "The message: C6 W' g% k2 U: f, ]4 ?) Y$ t: T( \
// called <foo>". You can send a message To a particular
4 G# r6 `5 S$ U0 b, O* ^6 f // object, or ForEach object in a collection.) r7 _, V3 }/ C9 ]* ?$ v
1 Z* P: i! _ _) Y( d
// Note we update the heatspace in two phases: first run0 |; o! D4 R0 R+ I; c- A! N
// diffusion, then run "updateWorld" to actually enact the
" Q* _4 Y! T- N* o% S6 O- V* ?0 J // changes the heatbugs have made. The ordering here is
7 a- A- w4 r& P& t // significant!
! m& {# H5 e/ ?5 E ' U- u( T P+ w3 \
// Note also, that with the additional
( f: k6 j2 O% o+ M // `randomizeHeatbugUpdateOrder' Boolean flag we can0 N' F* W% }+ y& ]
// randomize the order in which the bugs actually run
" I2 W9 {$ Z& J4 J4 b2 p // their step rule. This has the effect of removing any
D: Q, \% c! j* C( p2 c // systematic bias in the iteration throught the heatbug
& [+ A' b" t4 I& D+ |4 D( E* d$ d6 E // list from timestep to timestep/ r2 e3 G# Y) Z% Q; B6 \
9 O/ [. c$ b+ o; o2 s+ d
// By default, all `createActionForEach' modelActions have; t* t" G" U- X) @: ~ N& r
// a default order of `Sequential', which means that the/ s- R- \, R' T6 R3 A
// order of iteration through the `heatbugList' will be! R! r& L( }" I, m6 L) w
// identical (assuming the list order is not changed
+ k" B, s4 B1 q0 b; x // indirectly by some other process).
8 ~% V6 y; L1 _+ y9 A# I6 j% ? 4 k9 r. [6 J V; c8 ^9 `2 R
modelActions = new ActionGroupImpl (getZone ());6 Q/ w. \- c' ?% w9 z$ I+ i
( ?3 q$ {8 j2 g. e; B( ?5 O# l try {
2 X4 `; h' P; n3 j6 i0 b0 Y modelActions.createActionTo$message M$ u9 G( T& x" x5 s8 q5 E3 A
(heat, new Selector (heat.getClass (), "stepRule", false));3 Y( t J' @# }, o
} catch (Exception e) {% V$ H' D, m: X9 ?6 C8 e+ A
System.err.println ("Exception stepRule: " + e.getMessage ());" w& G s1 N# `6 U5 P, }
}
1 T0 Z0 s& G1 l$ r& p. q* X. s0 \$ n! @( I
try {% ^, i3 a) D% p0 W/ A
Heatbug proto = (Heatbug) heatbugList.get (0);8 |( ]" o2 h( `6 d7 _1 g2 D7 U
Selector sel =
" B7 `5 e' D9 L/ R! r- a new Selector (proto.getClass (), "heatbugStep", false);
1 J# f1 k/ B3 k2 Y: q actionForEach =
3 N6 T& o4 x: e! A# z0 o modelActions.createFActionForEachHomogeneous$call
" ]2 F* W& J( V& b. m- V (heatbugList,
# q. M- c" ?% J0 L6 Y: m new FCallImpl (this, proto, sel,
1 i/ s2 v; o- {9 o# Q new FArgumentsImpl (this, sel)));$ H5 e) {! d5 [# E# B! a
} catch (Exception e) { T) }6 a1 z. p
e.printStackTrace (System.err);$ I8 T( k% p( Q, ]* d
}
, z( {: h# t/ J. V( ?
3 q9 }$ r. E1 K8 s syncUpdateOrder ();
, a3 R( Z( j. _: p8 Q# I; o* T
, k( ?! j9 _5 D( n0 J+ l try {
/ d# c, `$ @+ [6 D8 X modelActions.createActionTo$message ( F& |" E% G4 ]9 _+ |6 G" z% h- w, i
(heat, new Selector (heat.getClass (), "updateLattice", false));
' O& D3 h8 f$ _! I* z9 F; D } catch (Exception e) {
s* t* A! j$ D. m System.err.println("Exception updateLattice: " + e.getMessage ());4 {: l0 u7 W0 ]9 _
}* K. |* U1 T% r7 ]2 v* y
: p3 W' d* W; B" o& B // Then we create a schedule that executes the
5 k( I; {$ k' j+ u+ J% ~+ W // modelActions. modelActions is an ActionGroup, by itself it" P" M1 a& h0 ] A7 C. g/ n
// has no notion of time. In order to have it executed in; g. k) z* f$ ]6 v) l
// time, we create a Schedule that says to use the w) x/ N4 X) v) y) _1 ?9 ]
// modelActions ActionGroup at particular times. This, ^* a+ D$ J/ i$ R) c+ w
// schedule has a repeat interval of 1, it will loop every4 |6 L% ^8 U* O/ _, n5 K) D. b
// time step. The action is executed at time 0 relative to; r& f4 ?1 Y, n' {
// the beginning of the loop.
( x( o, b7 s$ f7 u5 C. p# D9 ~% }9 H) Q* F6 m
// This is a simple schedule, with only one action that is
- r" P3 w% {3 c* f // just repeated every time. See jmousetrap for more- W$ l2 r0 P- q* K3 l
// complicated schedules.9 p( A& x' C0 M5 H4 p1 n
x6 C0 e/ Z o* f! Z, a- h1 [
modelSchedule = new ScheduleImpl (getZone (), 1);0 b! f0 b2 s5 U% P+ n7 I
modelSchedule.at$createAction (0, modelActions);/ b: Y% k8 {# j) v& B9 X; {# X+ k0 ]
( a! y+ I$ D1 Z2 d$ D; N8 \- _
return this;; Q$ Y. [% w+ z6 _, J
} |