HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
9 [* p; N# P! A/ J$ t
4 ^# n* C4 Z6 j6 ~ public Object buildActions () {
4 G5 M% H' y1 n. u" i4 | super.buildActions();3 E7 m' }) }3 z5 m1 Q
, ?, E0 q7 t; t I, p; {4 Z // Create the list of simulation actions. We put these in+ o0 `1 @4 t+ |/ Y4 d* ~
// an action group, because we want these actions to be
* I% z+ k0 d% N2 G# Y+ P& ~/ F // executed in a specific order, but these steps should* k+ j9 c9 ?3 |2 w
// take no (simulated) time. The M(foo) means "The message2 j. Q3 q* F7 W% _
// called <foo>". You can send a message To a particular
, w& X1 Y! c- @! \/ s6 m // object, or ForEach object in a collection.
$ R% n3 {# B9 t0 {7 Z
6 K: h$ D9 _% M // Note we update the heatspace in two phases: first run/ v/ K* d; p* r0 _
// diffusion, then run "updateWorld" to actually enact the1 Y* o& M: M s" B5 c
// changes the heatbugs have made. The ordering here is
4 `& u" n" a- ]2 O+ H: U* y // significant!, T' D" G: {; i
* v1 U( v8 e2 \6 G
// Note also, that with the additional% F$ w& X/ i) a, k
// `randomizeHeatbugUpdateOrder' Boolean flag we can' j. X! j3 R/ |5 {
// randomize the order in which the bugs actually run
4 g9 X- G4 Y' I: O$ T // their step rule. This has the effect of removing any( |5 }2 C2 S5 ]
// systematic bias in the iteration throught the heatbug4 U: z0 H5 n5 B
// list from timestep to timestep
6 o% V8 N2 a: F [: ~. J3 l8 Q
* C8 B- r {4 l2 G2 n // By default, all `createActionForEach' modelActions have( P# l8 a1 d# c: V, v+ m
// a default order of `Sequential', which means that the5 `! H! M. s- |; t8 w/ p* C
// order of iteration through the `heatbugList' will be* [7 t( C2 n6 u! h7 n
// identical (assuming the list order is not changed. @0 O( k# V) ~6 m# J4 d
// indirectly by some other process).
3 V( S* h" k* Z M. Q" _0 s; K, W
& u4 a9 \; n! H/ | y/ H modelActions = new ActionGroupImpl (getZone ());3 L1 H0 |! T _" z' r1 ]# I
" }( a6 `1 e( H try {
! X4 o- R" L- u3 a( @- B modelActions.createActionTo$message5 ]7 n/ y! e7 O" t( L" Q6 O
(heat, new Selector (heat.getClass (), "stepRule", false));) L# ?; z: E! Y/ k; g
} catch (Exception e) {
. D1 t* g/ J# u# Z' C. u/ { System.err.println ("Exception stepRule: " + e.getMessage ());
& t1 _6 V4 {" [0 D }7 w7 M3 E. {& a. R# U: a) \$ `7 P
s# Q7 a$ H5 b& \9 m try {2 ?) M# y- {. j( {1 Q0 Y5 h! o2 N
Heatbug proto = (Heatbug) heatbugList.get (0);
! ~4 P* \- t" i, d Selector sel = 2 O3 D3 p0 L! i) _# c* G" ^) j, a
new Selector (proto.getClass (), "heatbugStep", false);1 h) p7 j, {* q% E& ?- r
actionForEach =6 Y- L# m9 u% u
modelActions.createFActionForEachHomogeneous$call
/ B0 ^) F# @( w4 |8 w" F (heatbugList,
# W. Y% D& I9 O! }* t' @ new FCallImpl (this, proto, sel,
$ e. A( P- A k6 j$ n4 H new FArgumentsImpl (this, sel)));
) ^$ }3 ^6 d0 W9 d3 F& C } catch (Exception e) {
8 R! S% l3 o* G) x s; n e.printStackTrace (System.err);& `! Q0 D4 m! w l4 E( b: h6 G
}$ W$ e$ _% p: Y/ G. s
- ]/ l) m' u% R# ~8 i3 ` syncUpdateOrder ();
% }! k1 p6 P# W+ i9 `" v8 p! ~; h% |
try {
( C7 z) T9 J# i6 r5 s% H; x modelActions.createActionTo$message
' F% V0 m% o+ i3 _' e (heat, new Selector (heat.getClass (), "updateLattice", false));
( P' ]+ T8 D; _% o } catch (Exception e) {( o1 c& T; C/ Q4 r+ e
System.err.println("Exception updateLattice: " + e.getMessage ());
* W2 E6 \8 H+ z }
9 Z% f+ z0 ]8 I" X5 [
% F0 L$ s( h; ], n% t3 W // Then we create a schedule that executes the1 [2 f2 C4 B K
// modelActions. modelActions is an ActionGroup, by itself it, h- r( \0 B4 X
// has no notion of time. In order to have it executed in$ c( j3 _. ]+ R
// time, we create a Schedule that says to use the8 R6 R k* |% \% ?6 ~ U
// modelActions ActionGroup at particular times. This
* c* J5 p- S7 l. I/ ~- P // schedule has a repeat interval of 1, it will loop every
4 v5 T3 R! k3 [+ Y/ j g // time step. The action is executed at time 0 relative to
. m* N" G( ?6 a# w( V$ q$ I9 S! a // the beginning of the loop.$ {/ R/ U/ I2 j& r* I
: A3 o( s3 M1 ]: Z
// This is a simple schedule, with only one action that is/ }# V1 F6 C- u
// just repeated every time. See jmousetrap for more6 u( K: a: |9 E1 H; D
// complicated schedules.. ^* i- p, t# j4 E3 |* g s5 ^
$ O2 }3 G1 |2 }* ^
modelSchedule = new ScheduleImpl (getZone (), 1);
6 A0 Z3 [' \/ g% z/ U/ I modelSchedule.at$createAction (0, modelActions);
8 {) F r+ w9 R* F
, L! B7 P( j8 D9 U' x3 \ return this;
: z Q3 Y% V$ }5 Z# T* r } |