HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:* }, d+ [0 j# h. J, D0 z4 {
( `( O0 k9 i% @" l0 U' z3 {
public Object buildActions () {
4 Q7 L7 A/ N" I" q super.buildActions();( z) \! p6 V4 J+ V' s
; ~3 b! c; |1 ]
// Create the list of simulation actions. We put these in
0 o+ [& n+ e/ o$ k/ X6 u) E // an action group, because we want these actions to be; l+ _( m' s. O( z
// executed in a specific order, but these steps should; x+ F( K5 n$ E, ]% N
// take no (simulated) time. The M(foo) means "The message
( x7 z9 v. t3 b // called <foo>". You can send a message To a particular& o8 \/ a! f6 F! _% e' W0 d, F
// object, or ForEach object in a collection.+ T( {8 k( a% P( A7 {
" j$ U4 L- C6 |2 S1 N& t! c2 b" V
// Note we update the heatspace in two phases: first run
& o5 {( m! N! K( | // diffusion, then run "updateWorld" to actually enact the
; f- Q, w. S1 `/ M7 ~+ r& G // changes the heatbugs have made. The ordering here is
2 [! ~; g7 `$ r5 b. f* P6 H5 Y2 p // significant!; l0 N! T6 q5 W- A' t, p X
* z& H2 M6 F9 J$ S) I
// Note also, that with the additional
3 l) x! B+ Q8 Q5 a+ w$ X. E // `randomizeHeatbugUpdateOrder' Boolean flag we can
) v3 v6 @4 B, E( ~" N // randomize the order in which the bugs actually run
# S; t& `/ b& F9 y2 W- T // their step rule. This has the effect of removing any3 k6 Y. U5 N' z% P
// systematic bias in the iteration throught the heatbug2 f: Q6 j# I$ ~) T: `/ l
// list from timestep to timestep1 v; L; v6 k1 F; l' ~! `! a
* P: d2 w% J3 w% C& D8 { // By default, all `createActionForEach' modelActions have( b3 D# K0 ^; a5 O" G
// a default order of `Sequential', which means that the
5 M5 n& H4 B8 e$ m // order of iteration through the `heatbugList' will be' W9 j+ r$ S0 j0 {* w, V0 d
// identical (assuming the list order is not changed
7 q. ]- t: ^* _ B6 i // indirectly by some other process).
4 T [; V I7 \( t & q% p! w5 V: x& A) y
modelActions = new ActionGroupImpl (getZone ());
; ]/ i; V4 m7 E9 c9 ]6 \* |) R: ~9 Y* ~! U# e7 j
try {. V1 J* K( ~) e: D! k
modelActions.createActionTo$message
`& v( e; O4 z2 F: @# t (heat, new Selector (heat.getClass (), "stepRule", false));
3 Q% {" A5 s9 Z+ f! Y d } catch (Exception e) {
! A1 M; i/ |6 T9 c System.err.println ("Exception stepRule: " + e.getMessage ());
9 N/ A: W6 j/ l$ G+ e' p }& X4 o s: w9 u" q
w8 [/ `: V5 q" N- K
try {8 u6 h4 ^3 m: ]5 n
Heatbug proto = (Heatbug) heatbugList.get (0);
) G' S+ L0 [# E, u8 l5 q/ b2 r6 H Selector sel = - D8 [- s, [3 d0 w U
new Selector (proto.getClass (), "heatbugStep", false);, M/ O; J8 l- N3 B5 ^/ ]- X
actionForEach =/ t' Y. m* V# X2 I
modelActions.createFActionForEachHomogeneous$call( _9 N) k* r3 q0 D. O, ` ~) i7 Y
(heatbugList,
# M9 Z9 ` d) M6 b9 W new FCallImpl (this, proto, sel,% j6 b; L, @7 Z" M) k+ D" H( W
new FArgumentsImpl (this, sel)));
' G) ]* @% b* q- c) b } catch (Exception e) {; z" v4 t' T% r0 n' X9 {3 r
e.printStackTrace (System.err);
: D5 L5 m, k4 Z! ? }
7 _2 ^. x0 Z5 p: C) M' C9 n
+ v I& I6 ~/ a6 O. J syncUpdateOrder ();* ?9 u1 c& V( p& v
2 e5 z0 o, H/ V$ h8 |1 h5 ^) |
try {6 D" t7 B# Q7 s* Q# }- f# x
modelActions.createActionTo$message . F1 T5 q; h$ X! b- [* f
(heat, new Selector (heat.getClass (), "updateLattice", false));, j; J- i8 U; H( v! e
} catch (Exception e) {
) }/ Q$ C. ]( l2 J) C System.err.println("Exception updateLattice: " + e.getMessage ());( x' U& b+ _# d/ m% m
}3 L) |3 V2 o+ ?# Q* y3 J
; ]; ?- U! n9 y // Then we create a schedule that executes the. J2 P/ L- `8 P2 a9 [* l* ^
// modelActions. modelActions is an ActionGroup, by itself it
5 z* G# p& N$ v1 A |( L1 y( z // has no notion of time. In order to have it executed in0 O. ?0 p' P2 l
// time, we create a Schedule that says to use the
2 N, [) r# x& N& ?9 ]1 B+ M // modelActions ActionGroup at particular times. This0 I% F% M- q* ^/ j! @
// schedule has a repeat interval of 1, it will loop every
/ k! p: c0 y1 k // time step. The action is executed at time 0 relative to
+ _9 K2 R. N1 i4 }0 B$ c // the beginning of the loop.
) b) t5 _1 W7 J H( D. C) _& x8 ^$ P
// This is a simple schedule, with only one action that is- R3 [+ z7 h6 t# b: V2 M
// just repeated every time. See jmousetrap for more
* }9 g! Y6 |0 \7 K' Z' l7 S" m // complicated schedules.' a2 l8 H0 d2 G k U
/ h8 d! d- \( c4 }" ^: _& n
modelSchedule = new ScheduleImpl (getZone (), 1);& ?$ t" q6 O" C6 D/ A8 B
modelSchedule.at$createAction (0, modelActions);
8 ~0 s! f# U* n4 Z- h& \ 0 {( w8 c0 ]) [8 ^7 |8 t
return this;
& N _, C' O2 p+ \* F& r+ R9 q+ n U } |