HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:1 \2 A- ^3 ^: I# \5 Y' C, _
: f, W; X5 B0 u4 @3 `5 U& w$ V9 W% H( R public Object buildActions () {/ j7 Z* K) d# f( z# V0 W$ o
super.buildActions();& ~6 T9 [# D( t
1 l( `1 }2 J: r" U // Create the list of simulation actions. We put these in
# ~6 }( \) A* w% Z; d* z8 N // an action group, because we want these actions to be, g# ^8 y# \$ E
// executed in a specific order, but these steps should+ Z/ n. f2 O t: \
// take no (simulated) time. The M(foo) means "The message
4 N; X* T( ~6 |6 p# j( Z3 s* S0 W // called <foo>". You can send a message To a particular
; O! y2 }1 t6 ], Y1 \4 U6 k // object, or ForEach object in a collection.' P# Z' @* o% _ U: t- u+ k
; u1 j: B! r& d2 O" K3 L // Note we update the heatspace in two phases: first run! M; K; b& Q& W* p8 v
// diffusion, then run "updateWorld" to actually enact the
] u2 U. R* d9 m4 C! ? // changes the heatbugs have made. The ordering here is. t6 S/ Y& f& N @- @
// significant!
! [8 s: I5 ~) x+ ^! W - G8 b( W& U0 o) x. D
// Note also, that with the additional9 S% m% \# a& C
// `randomizeHeatbugUpdateOrder' Boolean flag we can7 R/ ~7 V# m( Z4 a! u9 H; G
// randomize the order in which the bugs actually run
1 Y: \9 A1 r# L // their step rule. This has the effect of removing any
, J! o3 I" W4 n4 S; T( L // systematic bias in the iteration throught the heatbug9 ^* i9 ^6 g4 B3 i
// list from timestep to timestep9 `+ P6 m# a2 p, }. b
0 ^9 s7 n5 O6 l0 o) _! }+ Q
// By default, all `createActionForEach' modelActions have
; a+ w. S3 i7 a( w // a default order of `Sequential', which means that the2 \: O" S& k8 z$ M. |! F
// order of iteration through the `heatbugList' will be0 \3 [, ^) |- `3 ^
// identical (assuming the list order is not changed& ]! @% e7 G/ O4 z
// indirectly by some other process).5 I& y0 @4 I& {% q" O7 @
, s! J: O" W U! P5 @3 S
modelActions = new ActionGroupImpl (getZone ());
, r; {: W7 Q2 o9 @. A( g! |1 T3 L
try {& p3 r/ k5 T* B3 M* Z, E
modelActions.createActionTo$message7 b0 g. m: v4 Z
(heat, new Selector (heat.getClass (), "stepRule", false));1 \: ^4 {; N/ H% o: L
} catch (Exception e) {7 R# O4 _) f! L
System.err.println ("Exception stepRule: " + e.getMessage ());
3 @' u+ m1 l4 F/ Q' \, q }
! J: @$ e) x" c% I/ }; x% q$ m& u$ t2 g) b+ C5 [" J
try {
( E% [! \! j3 Z1 {- _* S) _9 m Heatbug proto = (Heatbug) heatbugList.get (0);- x j) P/ ?7 D
Selector sel = " Q0 A4 |$ ]3 K4 C: ~( W
new Selector (proto.getClass (), "heatbugStep", false);
: _3 O( x" S4 Y, p actionForEach =
( a/ n9 u- X2 X( H modelActions.createFActionForEachHomogeneous$call! q0 ^( V- y8 a# c+ B$ M0 F5 i
(heatbugList,1 r/ M/ W9 u! g8 q
new FCallImpl (this, proto, sel,1 B- B$ U( {4 M4 S4 l2 F6 B, R, a
new FArgumentsImpl (this, sel)));
( S4 F7 j6 q6 ] } catch (Exception e) {
3 w A) e4 B/ ^2 ]9 C( r/ _ e.printStackTrace (System.err);
- A9 m; E/ r2 N* p3 M$ H o2 ~ }
9 s+ ?* Q* G' k, {9 r
& o% c6 M' s3 u8 ^9 F syncUpdateOrder ();
- ^/ ]% p' T& n9 T. a& R$ n
; a: p" {6 N. P0 m& y, j try {
9 e4 y0 B8 \: `1 @3 w$ j modelActions.createActionTo$message
! b' s w; v: S (heat, new Selector (heat.getClass (), "updateLattice", false));
! k# s, q9 w" y7 N" u } catch (Exception e) {
9 [/ ^$ Z3 i" w9 \ System.err.println("Exception updateLattice: " + e.getMessage ());
. Y( q! R6 A$ d3 m }
8 Y2 y% l0 w0 }1 ^. Z
0 P. G- p( q- V' k7 Z' c // Then we create a schedule that executes the
* B5 k& l# [/ u- ? // modelActions. modelActions is an ActionGroup, by itself it
% B( U1 J! i& j6 i' P // has no notion of time. In order to have it executed in1 {; w8 n- R. }' q' h
// time, we create a Schedule that says to use the8 C+ d" T, o! R1 j# Z
// modelActions ActionGroup at particular times. This# z4 C- d7 L: f, s$ u' }+ d
// schedule has a repeat interval of 1, it will loop every
2 {" R2 B9 }% d6 _7 H0 ` // time step. The action is executed at time 0 relative to3 G: a4 w, n( I( C
// the beginning of the loop.
. e% H( J) U+ L4 b
' b4 u9 x3 _9 h5 k // This is a simple schedule, with only one action that is" d1 U" Z/ ]8 h( p5 p( l
// just repeated every time. See jmousetrap for more
) O4 ^$ z7 T. B: V/ ^- N( s // complicated schedules.2 a6 P7 }& e3 C
8 N% Y+ n2 ]0 b9 D7 G* b- u
modelSchedule = new ScheduleImpl (getZone (), 1);6 J. g' m& E/ w' z, w! O, f! p7 n
modelSchedule.at$createAction (0, modelActions);4 F) `8 W' N2 Y! A
7 W' D% B& I. x: Q% w% _) x2 b5 U
return this;; Z9 w6 g3 N& q8 i( K7 p
} |