HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
7 E7 ~' u. M! P# k! }( b/ C3 ?4 v# g1 o+ C
public Object buildActions () {( r* L+ [! x/ ~" {" I3 P; r* C
super.buildActions();
) }! U( l4 s" M# V + V& P# S0 A/ {( l2 t
// Create the list of simulation actions. We put these in6 v8 C, a2 [! ]/ t2 S
// an action group, because we want these actions to be. g8 a1 q' s$ B8 I# M
// executed in a specific order, but these steps should
6 }/ C& f4 e; k6 Z // take no (simulated) time. The M(foo) means "The message- p) u$ I4 {1 q; a
// called <foo>". You can send a message To a particular( _5 B' u/ o8 k V
// object, or ForEach object in a collection.
+ F; A- S8 `; [5 s* [: o # S9 [' U6 r4 q2 c. z
// Note we update the heatspace in two phases: first run& p* J5 p7 j! O! T( k4 Z9 T
// diffusion, then run "updateWorld" to actually enact the
. |6 Y8 D6 b- B6 k6 @( z! p9 | // changes the heatbugs have made. The ordering here is% l6 z% n _* ~# O+ E
// significant!
6 W# T: P5 d# ?$ ~. @7 H0 a
; B, l. G, V% a# Y // Note also, that with the additional# I0 H7 }+ ^2 L0 g4 B
// `randomizeHeatbugUpdateOrder' Boolean flag we can
* r) X! [! W" x/ v: B1 x // randomize the order in which the bugs actually run0 Q( Z! k( g& o& j
// their step rule. This has the effect of removing any9 a+ }+ [4 I7 k
// systematic bias in the iteration throught the heatbug+ ?7 @% M0 e0 M+ i& b' }& p6 X
// list from timestep to timestep
4 J8 v! K$ l \ ~" _# \
d1 _3 _6 g. L) @+ W: F/ U // By default, all `createActionForEach' modelActions have
, @- l& R( s+ v1 |% Y8 g // a default order of `Sequential', which means that the4 {. n9 S0 {4 k
// order of iteration through the `heatbugList' will be
7 d X2 v% N6 r2 D" U5 k; ]) j# A // identical (assuming the list order is not changed8 Z5 y4 @1 @- ?, o( q: s+ f
// indirectly by some other process).
/ e! v" A$ b3 p6 `' v- R' ~5 O" {
2 T/ ~ t. O/ G modelActions = new ActionGroupImpl (getZone ());8 `0 l. G8 K! U+ ?5 U0 B
, Q+ ^2 t9 `& y& n) a0 p3 b' n E try {1 Z* F! W7 g: z; H/ S' v
modelActions.createActionTo$message
9 i& F) W/ q, o( ?* T' h9 f+ i (heat, new Selector (heat.getClass (), "stepRule", false));
& t" w# ^) b. B1 c: N9 i } catch (Exception e) {
7 P# T" h5 X4 o! F System.err.println ("Exception stepRule: " + e.getMessage ());4 N' G2 I J0 }5 ]( c/ x( }" m- n% n
}, x9 c' f& S0 o9 g
) J0 z5 _4 L5 i. f) S4 y try {
: S- @# {$ |4 f" T' O Heatbug proto = (Heatbug) heatbugList.get (0);6 l, r: y) q. K: O0 w/ Z# `
Selector sel = ; R' l- V \" R
new Selector (proto.getClass (), "heatbugStep", false);
0 L! D- B5 B [. A actionForEach =
) ^- v: o+ n+ l modelActions.createFActionForEachHomogeneous$call$ b+ b; r& C: D
(heatbugList,
8 J( |9 n% _9 Y6 _8 K; _8 @' K+ N1 X new FCallImpl (this, proto, sel,5 ]$ U' V# T8 x! ]0 y: @% N
new FArgumentsImpl (this, sel)));( D' S+ X: |1 M' i- S
} catch (Exception e) {
+ m9 R4 Y, u8 s% T e.printStackTrace (System.err);' C) `, V( N$ o( W$ P$ q
} ~! M! w0 H) j
4 U6 ]2 M$ `) {( }* P# T
syncUpdateOrder ();
% w5 O2 k# U/ M5 O3 K
$ c+ E% l6 j$ d" n' ] try {
8 T8 f5 `4 z) y" \* t modelActions.createActionTo$message ' d! r5 n9 }( q
(heat, new Selector (heat.getClass (), "updateLattice", false));
4 P2 V5 Q" k$ i' w8 O: V! M } catch (Exception e) {
/ w/ l7 ~" W1 F System.err.println("Exception updateLattice: " + e.getMessage ());
: D* h+ s; U& ]. q* t }9 u) M1 y+ m, q4 s. r
) L( I# ?. g! x* }# W // Then we create a schedule that executes the7 ?4 `5 E! Q% D( ?
// modelActions. modelActions is an ActionGroup, by itself it0 b* n* ~' `) I/ J" x* t# V2 a
// has no notion of time. In order to have it executed in v- C! e# D% q8 H* U9 ~5 `
// time, we create a Schedule that says to use the5 U$ k& C' T) K6 L. S) X9 m! e7 {
// modelActions ActionGroup at particular times. This
8 A* B) k5 [: L* ] // schedule has a repeat interval of 1, it will loop every7 l3 j) @7 d7 t- m+ z, l
// time step. The action is executed at time 0 relative to
7 [: w/ b h, `* e // the beginning of the loop." p l" j6 G. S/ B4 U* |
3 V0 u! { i) ?" q! T6 J9 N- x( Z
// This is a simple schedule, with only one action that is
3 A. a* P+ f& U. f // just repeated every time. See jmousetrap for more
% s+ I# k3 i( k! S' {( ` // complicated schedules.
5 {2 H# }, [7 E0 l1 z2 @. Z: a
1 i8 s6 G4 k( M% x( W% ]- [! c8 P' ? modelSchedule = new ScheduleImpl (getZone (), 1);
3 Z3 s6 L' o0 _9 b; c9 Y" [1 u modelSchedule.at$createAction (0, modelActions);' Y6 Z$ ]3 \" ~7 A1 y. [, X
/ \! s O ?. J1 ~' k" N
return this;
5 J( U- {4 b* n! V; e f7 C } |