HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:& q) L4 T$ u: U2 O
5 g/ u. @1 W3 h, X0 x$ S
public Object buildActions () {/ D9 V- W1 B& F1 `
super.buildActions();4 r( R5 Y' A! J; T
. z y% V7 j# f7 T
// Create the list of simulation actions. We put these in% u3 E. h- s2 R$ m
// an action group, because we want these actions to be
1 q% x; ?6 ~8 m) Q t2 S // executed in a specific order, but these steps should
E8 L, T1 E$ a( B // take no (simulated) time. The M(foo) means "The message
% m |% x* S w // called <foo>". You can send a message To a particular1 ]+ g$ q" V, l
// object, or ForEach object in a collection.8 ^6 } T8 _) I2 L" a& ^9 y( i* f
% l( a, A7 g+ j3 U
// Note we update the heatspace in two phases: first run7 k) Y' F$ ]- s* O
// diffusion, then run "updateWorld" to actually enact the
1 N. h0 ^6 ~& w // changes the heatbugs have made. The ordering here is" S9 Z% Q& D4 l+ @5 h
// significant!
6 P' k; m. V. j$ g! t 0 E& @# e: t R) `( f7 h# ? g
// Note also, that with the additional! D' X2 C2 F2 X$ ]1 |7 S
// `randomizeHeatbugUpdateOrder' Boolean flag we can
# B9 k% G3 H. c6 U5 |( g" N0 n // randomize the order in which the bugs actually run
& [% P ^0 d1 Q! x! u& t // their step rule. This has the effect of removing any
( O) L7 {5 \: Y // systematic bias in the iteration throught the heatbug& O( n9 [* E3 o2 o
// list from timestep to timestep4 H- C& G, E% K5 L, ]
}- g8 O8 @. C) S
// By default, all `createActionForEach' modelActions have
& K w# Q' M# l) W. Z: K' ]5 p- ^ // a default order of `Sequential', which means that the% W7 N* ]* r1 g- o
// order of iteration through the `heatbugList' will be
# g4 o7 K) r. h+ n2 c* |" @% Q // identical (assuming the list order is not changed
+ P7 D2 k5 v% ]$ T% E // indirectly by some other process).- |) _2 S) j9 K. E: C- x6 d
) N6 a( B" r ? x) H
modelActions = new ActionGroupImpl (getZone ());! n/ V0 K6 X& S1 G
* `; `/ J- `$ M+ R1 Q$ L
try {7 t! B: O0 ^; w' z
modelActions.createActionTo$message2 T- ^9 h) c4 x& }
(heat, new Selector (heat.getClass (), "stepRule", false));( i0 Y# c/ M; i. C- ], n
} catch (Exception e) {
/ J. D( ^9 @' r, |- | System.err.println ("Exception stepRule: " + e.getMessage ());
& d. i' X1 p6 [; r! O }6 H$ I4 _* W* P$ x; Y, _
- y4 F# G- z/ W J try {
: N6 _6 K2 a J. ^ Heatbug proto = (Heatbug) heatbugList.get (0);
( n5 s5 L/ W9 y! r8 x Selector sel =
K) U. u) m; B new Selector (proto.getClass (), "heatbugStep", false);
3 O; E: l. a' O2 ? actionForEach =& D- ~7 S3 W2 [$ Z
modelActions.createFActionForEachHomogeneous$call! p( { N/ b c; t c& k
(heatbugList,6 M' q+ X: G, E- f w! i
new FCallImpl (this, proto, sel,8 C1 P* x* \! t
new FArgumentsImpl (this, sel)));
2 s4 c7 G3 N' a g# M } catch (Exception e) {
, s6 T8 N: |' r) u3 h" O e.printStackTrace (System.err);
( ?: Q0 e( B( K3 Y }
1 x5 d* F2 u! N
# _# S. e& Z7 ~$ y syncUpdateOrder ();; n0 W+ B. N, l0 O- O
: C& H2 `$ v, R5 h2 R
try {! T& A5 q" f( U4 P* q$ U( g; H
modelActions.createActionTo$message 5 G$ R) l) r! j; d+ G. [
(heat, new Selector (heat.getClass (), "updateLattice", false));7 j; M% O' H& y+ q/ x; s1 ^2 C* ^
} catch (Exception e) {# z0 b: E$ k/ u+ z9 _
System.err.println("Exception updateLattice: " + e.getMessage ());4 z5 e5 N* I' U! |% F# z* p
}& M- @2 D0 @8 V
2 T; m6 h5 Z5 h: c/ P+ p) Q
// Then we create a schedule that executes the
/ F' d" p8 Q( T! D, m( }' E // modelActions. modelActions is an ActionGroup, by itself it( N( W! w" Q) y0 A2 B5 Y1 M
// has no notion of time. In order to have it executed in8 v+ a3 H1 `2 }$ B
// time, we create a Schedule that says to use the; N D- P$ X2 h
// modelActions ActionGroup at particular times. This
" @" k' v7 G2 v/ Y( z$ g' f // schedule has a repeat interval of 1, it will loop every. u# c) p( x2 l3 M! }8 Q
// time step. The action is executed at time 0 relative to
' R3 l; m. I' X/ V6 e( U' a // the beginning of the loop.
4 n2 D& J6 Y6 d5 z% F7 F7 T8 s
: l2 ?: n" J4 w: b // This is a simple schedule, with only one action that is+ y5 J6 n0 E1 V% N/ f
// just repeated every time. See jmousetrap for more
: \0 I1 K% M) w: J+ z, u // complicated schedules.
. M; s& M/ X& \* \
6 b" k8 K2 k" N& ^, m modelSchedule = new ScheduleImpl (getZone (), 1);
, o* O* r! F V, w/ A. u modelSchedule.at$createAction (0, modelActions);
) H9 U T% M& I; i1 J( V9 d + t- A5 T: K& m/ r6 M% |+ C" B4 p
return this;
& v T I, u: Q } |