HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
$ ?8 c: J: _1 c- g5 M5 ]7 J1 d i0 b0 j% ~
public Object buildActions () {
5 r. y+ O6 z( c3 H super.buildActions();- L* E _& Z2 A" }& h5 U1 v
7 _" M* }. j. Z6 a9 u8 l // Create the list of simulation actions. We put these in' r# o0 z$ L6 I% T4 j* K: w, m
// an action group, because we want these actions to be
& s4 V3 G/ L/ y8 f# T. E // executed in a specific order, but these steps should, ^, d8 }& `/ H" v" V8 h% H3 D" P: _0 P
// take no (simulated) time. The M(foo) means "The message- N# _' o- _2 P" ?& g n
// called <foo>". You can send a message To a particular
! f9 S6 q6 |/ l; Z3 g" P5 F/ w // object, or ForEach object in a collection.( h+ v6 M) I# Y% ?3 H
# X) S4 ~/ A5 M& E% S // Note we update the heatspace in two phases: first run" j0 ?; j( E( S) I% v* W2 e; K
// diffusion, then run "updateWorld" to actually enact the" Z) o Y! F. U$ N0 g# Z
// changes the heatbugs have made. The ordering here is: c' E& b# p6 G- c' ]* s
// significant!2 Y( y& e0 c- q. Z: Y
4 \1 v- t* t# [2 q) q m // Note also, that with the additional/ d! j0 o) U' ?
// `randomizeHeatbugUpdateOrder' Boolean flag we can8 r$ X* f% v5 t; Z( h; ~0 m
// randomize the order in which the bugs actually run X" X8 ?3 O2 R7 N/ Y: A, x$ r+ z
// their step rule. This has the effect of removing any+ |5 k" u* {" O
// systematic bias in the iteration throught the heatbug8 a1 Q9 r" h: ?0 k5 @1 [' c0 O
// list from timestep to timestep
* f. P3 E" |* k; y 4 f. z; M. D0 F5 W Y. w
// By default, all `createActionForEach' modelActions have' r6 P2 \% X: x8 j2 y h' ?
// a default order of `Sequential', which means that the9 @( b$ F8 Q( c( |/ r
// order of iteration through the `heatbugList' will be
9 S5 y" Z3 f0 a$ G2 V // identical (assuming the list order is not changed1 t# x1 E1 \1 x
// indirectly by some other process).
s0 G( q/ n6 g: A; z! C- [ 7 ]6 `# s/ ~; c0 p1 I& L4 g
modelActions = new ActionGroupImpl (getZone ());# F1 Y7 o; Y3 a. z- U
# H7 d7 u4 n. C1 v' M" `6 t# f% Y
try {
! N8 J& E8 ]+ o; E( ? modelActions.createActionTo$message
& t2 U, N+ Y) t& { (heat, new Selector (heat.getClass (), "stepRule", false));
2 S+ T& e+ O f } catch (Exception e) {
2 H& [! r# @- X( K5 R! q System.err.println ("Exception stepRule: " + e.getMessage ());+ A- w, G/ B& I
}
/ c& O+ R( ~3 e; k* G F5 s2 A$ n2 A G" S
try {
$ y! X% e. w3 X; `; Z2 T Heatbug proto = (Heatbug) heatbugList.get (0);
4 g J8 T6 i- _! C0 I Selector sel = ' J B$ v7 `+ Z4 W5 M) o
new Selector (proto.getClass (), "heatbugStep", false);) G+ R) i+ [3 s) T$ W( I! A+ V
actionForEach =( F; [9 P7 S# R7 c' ]
modelActions.createFActionForEachHomogeneous$call
C, w m* S2 t4 o V (heatbugList,; D+ p9 `2 M# Q: V$ P* Q( z
new FCallImpl (this, proto, sel,
$ ~# F* e8 r8 F1 Y. o new FArgumentsImpl (this, sel)));
* I# k- c# j K5 R0 l H } catch (Exception e) {. \0 e: z2 e+ i, R
e.printStackTrace (System.err);' R" o1 P( o7 N% r% k# o8 M3 o
}; K, ], v1 i1 L) j2 ^
. h, A) a% f9 C+ {8 }% V* o C syncUpdateOrder ();7 ?& u; w# c1 x- D8 f( f
. Q, \& q# F6 B try {# a* _% [3 b9 N- v6 n- n+ M6 Z
modelActions.createActionTo$message
' R4 I% t* R' K& y (heat, new Selector (heat.getClass (), "updateLattice", false));
4 W. [0 L5 \# V. k* d! Z& z } catch (Exception e) {8 _3 y4 J, [: O6 C& ~# V( g* G7 `9 c
System.err.println("Exception updateLattice: " + e.getMessage ());
# ^" N# f4 s) i! q }, o1 Y0 V% d/ d: V
7 O. |/ ]3 n7 v // Then we create a schedule that executes the
( }3 @7 i' [" w' y7 F# f" G, B1 o8 { // modelActions. modelActions is an ActionGroup, by itself it. w; J9 }, t( T
// has no notion of time. In order to have it executed in
5 k Y& R, i6 ~ // time, we create a Schedule that says to use the
( n9 V5 Z4 ?! f/ V // modelActions ActionGroup at particular times. This& i, `& p7 O$ V5 Q/ [
// schedule has a repeat interval of 1, it will loop every
1 B9 W: k+ h' K // time step. The action is executed at time 0 relative to
+ j0 c: J3 r0 I# Q; s // the beginning of the loop.% O, v" E5 G6 }7 }& C/ j B
1 U! k+ d3 H8 P# G/ r$ a/ R // This is a simple schedule, with only one action that is
. Y; u; Y- }4 H' |: _! i c8 v // just repeated every time. See jmousetrap for more
) o p1 x7 }7 P* }1 S // complicated schedules.
( Y* P) n" h$ @+ j
# @ ^0 Q6 F9 \% A8 K; H+ h! S modelSchedule = new ScheduleImpl (getZone (), 1);2 a4 [& A+ e$ s& G( @
modelSchedule.at$createAction (0, modelActions);: B- b: k3 J: I- F' h" w
! B5 U; @9 y" R7 n1 V- U/ e: q9 d
return this;
% ]; D/ n8 L- V+ k2 x& M9 k } |