HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
4 F7 K$ Y8 u' A& y( i- |+ P1 ?7 B# {& O/ V
public Object buildActions () {
9 Y7 Q' o/ S; c1 x% B, [0 v4 u super.buildActions();! w# T0 j: `5 a' O
/ Q' [( w! R) V
// Create the list of simulation actions. We put these in
2 s9 @9 t- F3 f( F U // an action group, because we want these actions to be
. g! w( i2 c: I" t. m- f: y( q // executed in a specific order, but these steps should
& y ^6 C* B5 h9 a! K // take no (simulated) time. The M(foo) means "The message4 t* {3 ~/ A+ ?0 E. @) c7 L
// called <foo>". You can send a message To a particular; i! e& {# m& Y
// object, or ForEach object in a collection.; V2 S3 w$ m2 s- J9 s6 p; {5 P
8 M+ U. p4 G( e6 D) V% K // Note we update the heatspace in two phases: first run! N% r' E T& v4 x0 b2 y
// diffusion, then run "updateWorld" to actually enact the6 l, G3 T/ y; ~6 u7 q/ F" `
// changes the heatbugs have made. The ordering here is
8 B; t( q: ?5 G$ V // significant!3 m- p7 t' m, L% Q
% @; O0 Q. M7 g X // Note also, that with the additional
9 t2 y5 e }$ v // `randomizeHeatbugUpdateOrder' Boolean flag we can e; M- E1 ?6 d g
// randomize the order in which the bugs actually run2 O7 q$ y6 F( A8 t$ |' Z* _
// their step rule. This has the effect of removing any# P# u7 o# F1 n- c0 a; M$ _. j
// systematic bias in the iteration throught the heatbug- m7 L/ @0 ~, ?; G
// list from timestep to timestep! h% @5 P/ [# N8 l: V8 ~
/ j# A: \# L5 x5 y' c0 u4 h
// By default, all `createActionForEach' modelActions have w' R+ G- T: C' I. {
// a default order of `Sequential', which means that the1 |, N8 i+ q4 l: A9 Q
// order of iteration through the `heatbugList' will be
8 \2 d9 [* v; _% k // identical (assuming the list order is not changed: l* F( \ F4 a6 P) B
// indirectly by some other process).$ R7 g3 D2 z8 {
; ]1 ]; s- D" q8 V/ x" t modelActions = new ActionGroupImpl (getZone ());# A* H/ A `& L; s. F) |
* E! e4 o' F9 o3 Y9 L3 X
try {" R' e: m' o, D6 X+ q; j3 K9 I! {
modelActions.createActionTo$message
B$ X, U! o0 S0 @+ S1 m1 u6 p3 { (heat, new Selector (heat.getClass (), "stepRule", false));
7 M# ]! h: ?! {- o7 y G8 a6 M/ @ } catch (Exception e) {
) K$ Y# e( M r" f( u& G4 ~8 D: ~ System.err.println ("Exception stepRule: " + e.getMessage ());
3 X6 q& Y: \3 v) Q2 J( w' V }# a) M" d9 d. I- [# N! F$ G% J
6 e. `# l- l7 w! ~( h0 o3 l try {
9 j9 M7 t* b1 [& x" U+ O! L Heatbug proto = (Heatbug) heatbugList.get (0);
' I' M6 r) G. R) F: M2 s4 M; d Selector sel =
, n- S4 M' K/ L+ s# x# c0 r" ~ new Selector (proto.getClass (), "heatbugStep", false);
' W3 X5 [( V, Q' n3 f- ^ actionForEach =+ t/ \ e2 U/ S* k. _/ p E
modelActions.createFActionForEachHomogeneous$call
+ d7 v5 y9 J# L0 V7 f8 T. z2 Z4 i (heatbugList,/ G, l, x! x. {' w! {8 K4 n2 U
new FCallImpl (this, proto, sel,! K9 s2 Q/ ~$ J: { h1 R1 I6 V" h
new FArgumentsImpl (this, sel)));" p! f7 A6 N, A$ a. x/ C8 q, E
} catch (Exception e) {
6 @$ I9 b7 o2 O8 N3 v e.printStackTrace (System.err);5 B" i; g, B7 w* p- L, a. X
}
! G& Z2 O7 H" T S1 F. v1 y) V
* U1 H( Y" M& v% Y1 }' B$ b# o syncUpdateOrder ();
a ^7 B w5 L3 ] `1 C# ?. Y. Y3 L
try {
" g/ c8 W5 S2 g8 J- ?3 ^2 x modelActions.createActionTo$message
7 W [, M" s- {/ A (heat, new Selector (heat.getClass (), "updateLattice", false));
7 D$ A) q' W( O) N- f } catch (Exception e) {
( E- E' S" {% Y6 J* c System.err.println("Exception updateLattice: " + e.getMessage ());
! j& E+ u. t' Q }
1 U# B9 }1 K2 l& V! K 3 `8 l. t4 e# I+ j% A
// Then we create a schedule that executes the
* F+ s" V7 i+ _; j // modelActions. modelActions is an ActionGroup, by itself it H4 e0 T4 N ?" w5 Y9 z0 Q; E
// has no notion of time. In order to have it executed in
% T+ L* I+ X/ V/ @4 \+ |( b0 N+ s, P& v // time, we create a Schedule that says to use the9 E" E9 ^6 [' ~% k6 T, h
// modelActions ActionGroup at particular times. This
9 P% _3 j5 J v& S; Z; S2 {5 ~ // schedule has a repeat interval of 1, it will loop every
; Q5 G& C2 [! f# ?. ? // time step. The action is executed at time 0 relative to2 A( P; U- w2 }! [
// the beginning of the loop.
# E3 _% I( ]+ a2 {' D9 o1 `# a/ U2 F; u
// This is a simple schedule, with only one action that is+ p D6 ^0 X& l' ~$ {- |
// just repeated every time. See jmousetrap for more7 Z+ c, W: H/ z' ^; F J7 n
// complicated schedules.
( v1 M) L8 _& i! _" j: N6 n. K 2 i/ E) S3 M0 w* r
modelSchedule = new ScheduleImpl (getZone (), 1);# q; p4 A* z# A* k
modelSchedule.at$createAction (0, modelActions);
' P7 k" K7 n) d' O2 Y 4 w" {8 [: o# u0 A! z; E
return this;! B! S. |( x. j$ c
} |