HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
6 N' X* V. K) N' b3 |1 {8 p+ g- }( I
public Object buildActions () {7 ~# B! u5 L9 a p, f
super.buildActions();2 [7 i& G# |) t* Y
7 q3 C# U& j4 {% K" X
// Create the list of simulation actions. We put these in7 j3 v% y8 p% [: j. v v
// an action group, because we want these actions to be
A0 D! l }. }* a5 r // executed in a specific order, but these steps should* e3 ?% C6 A) t \3 U
// take no (simulated) time. The M(foo) means "The message7 l( {0 i' n: o8 p. H8 } d6 H7 i1 ]
// called <foo>". You can send a message To a particular
9 T6 S s# i7 S+ U# t' A# o W, _7 ? // object, or ForEach object in a collection.* {' s3 O" v5 x
: s- J4 ^' i; M( Q* P1 |* D
// Note we update the heatspace in two phases: first run; U6 |6 v. V" n6 V. N4 P) L8 z
// diffusion, then run "updateWorld" to actually enact the
$ h1 m+ ?+ N+ s; c0 ] // changes the heatbugs have made. The ordering here is% S f3 `) q8 e+ R* |8 S9 N
// significant!6 s# i# t2 s/ y8 a1 O* i
* b6 H; u9 a6 P; e
// Note also, that with the additional
8 K0 f. U1 T. d" }' Z( N: k // `randomizeHeatbugUpdateOrder' Boolean flag we can2 ]$ l2 y$ ?4 D E/ u; w
// randomize the order in which the bugs actually run
+ e4 f6 _9 @2 r; X* F4 M) D // their step rule. This has the effect of removing any
6 L( s4 v2 c* x2 S% Q0 `# g6 q // systematic bias in the iteration throught the heatbug- G" G6 [5 i1 c$ L
// list from timestep to timestep2 h. w( s. a& T
8 c! W/ Z/ _8 Q. @# ^, [! ] // By default, all `createActionForEach' modelActions have
+ ?8 c) I0 |7 h [: Z4 ^ // a default order of `Sequential', which means that the
) T! J6 m! h3 [! f7 I( \) i& } // order of iteration through the `heatbugList' will be
, Z" v2 ?( z% u4 u& ~2 d // identical (assuming the list order is not changed0 W: [4 ]$ T9 T: R3 {& H4 W# t
// indirectly by some other process).* D7 G" G# O* U9 l" ?" _. F% b9 t
4 I! }" q) N, J; l modelActions = new ActionGroupImpl (getZone ());
: n* p, E0 [4 L6 R% g# J, e% f8 }) ?! L$ K( z' o* C
try {
+ B. ]" B" \6 d( l" [ modelActions.createActionTo$message
; N: H ~4 j4 U# l (heat, new Selector (heat.getClass (), "stepRule", false));
9 `# A G4 l0 k [7 ^ } catch (Exception e) {, U/ y7 L2 R- h. F' B$ ]
System.err.println ("Exception stepRule: " + e.getMessage ());
, {5 ~0 v8 s" x }! F1 n# y. r" Z; G6 x
/ h/ c4 n. j5 _$ q" q B% u$ V
try {
: U5 C( ^8 X' h# y7 R& @ Heatbug proto = (Heatbug) heatbugList.get (0);
8 ?+ Q) t/ b6 g% e( v0 P Selector sel = 5 } }! Y0 X2 E5 [1 n8 e
new Selector (proto.getClass (), "heatbugStep", false);2 Y+ i; ]2 p. G! F
actionForEach =
) l9 v v3 w/ B: N0 w t; t modelActions.createFActionForEachHomogeneous$call3 w% y# T( J' I; V2 t& ~) h
(heatbugList,
3 ?; R& [ @8 ] p2 s new FCallImpl (this, proto, sel,) J' e" |2 v* D! p4 a+ d' H7 x
new FArgumentsImpl (this, sel)));: W" s- e: I0 Y- p
} catch (Exception e) {! P: Y5 u. g# T$ o
e.printStackTrace (System.err);# k% `% V- u0 V3 M) K6 M
}0 T# u* M( [) X2 Q
, Y5 _* e' Q& c
syncUpdateOrder ();5 `+ [3 I- i+ U4 \: f
; c% @5 S# R z g9 \
try {
4 ]% A+ ?, v. r9 F! e9 x modelActions.createActionTo$message - m: c |8 q0 B9 y
(heat, new Selector (heat.getClass (), "updateLattice", false));
* W5 {2 S2 D7 a, g# O; Q+ k } catch (Exception e) {
' g* W0 }1 n; q System.err.println("Exception updateLattice: " + e.getMessage ());7 `! J h. m" G: `; \
}2 t/ D" K6 k/ \
7 u- T$ y$ _9 z, ] // Then we create a schedule that executes the g' K/ m# w. f6 B* c
// modelActions. modelActions is an ActionGroup, by itself it
: Y# e E" D& e: R, h& k // has no notion of time. In order to have it executed in7 J8 X: ^) R: h. ~
// time, we create a Schedule that says to use the
( ?: f5 ?1 m% p4 t // modelActions ActionGroup at particular times. This3 H5 E; C( W! d0 f) P- a1 @9 S
// schedule has a repeat interval of 1, it will loop every
# g* c! W8 B( s" U$ x // time step. The action is executed at time 0 relative to- [# Q& P. X0 `- P* V/ e: J
// the beginning of the loop.- D- t' Z$ J9 K C A
, S0 ^& y$ x& ^* H( C+ ]) } // This is a simple schedule, with only one action that is
/ a; \# Y, L0 d" k' ~5 ], t // just repeated every time. See jmousetrap for more
* \, e) c; a! [& {7 \& A# [ // complicated schedules.
4 T/ A) ]6 `& @( Q
# O+ Y* S, \: r modelSchedule = new ScheduleImpl (getZone (), 1);3 T2 [% v% I3 N( C- G7 X* l# ~
modelSchedule.at$createAction (0, modelActions);
4 w' h* H K5 w% A4 D5 b2 A+ T! l9 e9 p # K$ L Q8 Z/ M" L) z |( A9 A* h
return this;
( L! U3 b; P$ v } |