HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
2 L. Q4 J5 `. d& H) E5 O7 C6 h2 y% ?- W8 i# @& t
public Object buildActions () {4 c6 ^/ b7 E& c0 {
super.buildActions();
$ K; k) J5 R2 ?& b. l& C% c $ B* w8 J, _! h. V- _& K- b
// Create the list of simulation actions. We put these in
2 E. d9 Z% ]$ j9 o // an action group, because we want these actions to be
( @1 I W1 b& ?7 b |2 N9 n // executed in a specific order, but these steps should& w, |9 |# G d( t) y! _
// take no (simulated) time. The M(foo) means "The message
) h! f* m5 K: M$ {$ H // called <foo>". You can send a message To a particular7 }8 C; E) u! ^ D
// object, or ForEach object in a collection. v% G8 V1 A1 E6 ^% A# J8 l1 Q+ s
; U2 U' U; g3 a6 p // Note we update the heatspace in two phases: first run. t9 J7 j0 z2 ~- }2 ~
// diffusion, then run "updateWorld" to actually enact the
/ i1 ^5 x; b5 ~) c" I // changes the heatbugs have made. The ordering here is- T- q, {5 U c/ I) e
// significant!- g) V; I: P7 @/ U3 N( q+ j! B- Q
- _$ ]! [( E# \ // Note also, that with the additional% _) H5 s, L9 n, {) f+ r
// `randomizeHeatbugUpdateOrder' Boolean flag we can
* C6 g1 x# F- v6 F' o) N3 ^ H // randomize the order in which the bugs actually run
* X( [/ P" Y* `" |& } // their step rule. This has the effect of removing any
" n1 B1 u" }7 J1 `* ^$ c$ n. a. k // systematic bias in the iteration throught the heatbug
. w4 K ^/ \6 z5 z" B# q7 ~$ l // list from timestep to timestep, I9 |& L8 x9 \
. P* e; |8 ]6 E. ^) a3 s# w // By default, all `createActionForEach' modelActions have; A( `1 S- x& g' x. z* s H5 L; {5 V
// a default order of `Sequential', which means that the
3 g* A g; e9 P1 A/ l5 U) v // order of iteration through the `heatbugList' will be: y: ~0 e, M3 J- F1 S" s4 B
// identical (assuming the list order is not changed
" |4 Z. @6 z! E; b& R6 d' A // indirectly by some other process).
6 Q) w; _; P; V5 r z* V$ e% G
$ @; Z, @. M. y modelActions = new ActionGroupImpl (getZone ());
% p1 F& X7 m9 c1 `: N( o, S
# _$ K& o' L8 C4 Y8 D% I1 w: e8 ]8 g. G; Q try {
$ \9 J/ \1 V8 C* H modelActions.createActionTo$message4 C9 {5 A4 C N. d8 Y
(heat, new Selector (heat.getClass (), "stepRule", false));4 v4 S% Y# \* w1 _+ y
} catch (Exception e) {
$ f; H; T! j1 p) ^0 A System.err.println ("Exception stepRule: " + e.getMessage ());3 k. @: ~0 w# H% v5 T
}
% B" ~% @3 d0 o6 @2 ?4 @' C/ i9 K* @1 j( C: `
try {9 L( {5 R! r' P- M0 o: C, D" V1 t
Heatbug proto = (Heatbug) heatbugList.get (0);; g Z- x& q/ I" W# J( B' H
Selector sel =
& z" e% y5 P7 u# } new Selector (proto.getClass (), "heatbugStep", false);2 q4 U9 b. q( K/ b/ \0 a* F" `' D
actionForEach =
4 w4 T X; L" k modelActions.createFActionForEachHomogeneous$call7 m+ x- `; N1 N0 f V- P
(heatbugList,
! n- a0 V. {! B* ]2 P- t3 Y new FCallImpl (this, proto, sel,
1 S6 W" b' L& u0 ^# ?. e' R } new FArgumentsImpl (this, sel)));" w" ]% z; q# Z/ v" a3 W5 I- B
} catch (Exception e) {; o: z1 P! F3 d5 @( J2 s; u
e.printStackTrace (System.err);
+ i9 F9 A) \7 o; A, P, C& D$ v }
# E: X0 r! z6 V0 I8 ~" s. { , W1 M/ Q2 Z, w8 v2 I
syncUpdateOrder ();( O+ J, ^8 q8 ^: h; Z+ w/ T. Z; g
5 k8 k1 o5 x3 `( f# C* r try { \' [8 }+ e9 I6 ]
modelActions.createActionTo$message - V8 P, a. H8 H
(heat, new Selector (heat.getClass (), "updateLattice", false));
) o8 H. U( u, U( G } catch (Exception e) {+ L. Q4 U2 m# Q" P* Q: A0 w* U3 M" M
System.err.println("Exception updateLattice: " + e.getMessage ());& L g* `: Q4 [; G1 l
}- X( `$ u& t" } Z6 [
1 ]8 [3 L8 Q3 h7 i l5 p/ E8 @ // Then we create a schedule that executes the
% X, b, Y" f }6 V // modelActions. modelActions is an ActionGroup, by itself it
4 U/ x- f9 N1 w. r/ v: q // has no notion of time. In order to have it executed in
2 m. a0 V; C/ T // time, we create a Schedule that says to use the
. U; @4 u0 \; h0 C) K, P // modelActions ActionGroup at particular times. This; ]9 a" s$ r2 E. R9 d1 L, v
// schedule has a repeat interval of 1, it will loop every/ A+ C y4 j7 D
// time step. The action is executed at time 0 relative to
- T/ b8 Z1 d9 u* U6 p // the beginning of the loop.
4 B! V. D% B( {. B v; N
/ @5 J @( m/ `6 U // This is a simple schedule, with only one action that is* g$ g' l: a8 A$ W- c4 P4 ~
// just repeated every time. See jmousetrap for more+ D. \. k: Y" p- @# l+ k
// complicated schedules.; i1 Q# J% x4 k9 C% t; k' L2 D
$ T9 d" r$ q; E7 a- j0 n: Y modelSchedule = new ScheduleImpl (getZone (), 1);8 p# |) J1 { K# J% x
modelSchedule.at$createAction (0, modelActions);
7 [* t5 h; v3 d) t; h7 Y
7 o$ S" ] C$ O! { return this;
1 N( E: T9 M+ B$ {- T } |