HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
6 \. E5 x# n( \( J
, F& \1 p* E7 f/ v Z7 [' U public Object buildActions () {
+ y* g$ O0 U+ ~: l9 u/ _3 H super.buildActions();
4 r2 G/ a* e! s# I
6 V, A- b$ B% @ g8 X: l // Create the list of simulation actions. We put these in
~+ T: e, L$ s% ~9 s // an action group, because we want these actions to be
# N6 S. ]+ y3 o4 ~: c" c: M7 q // executed in a specific order, but these steps should
& x7 D9 u8 Y9 r4 Y& B // take no (simulated) time. The M(foo) means "The message# Z8 w% b3 {! G$ W1 e
// called <foo>". You can send a message To a particular
' U" J) [$ {& h9 ? // object, or ForEach object in a collection.! S; P; ]+ f* {2 [' T4 C; V, G2 Z
: M H% z/ q- U! c8 q2 _) `6 Z // Note we update the heatspace in two phases: first run1 I: s' y* g Z
// diffusion, then run "updateWorld" to actually enact the- W. B; @- Z9 y* k( h+ {8 f0 e
// changes the heatbugs have made. The ordering here is
0 V( Z1 \6 ^) a7 B4 F. f // significant!5 [& a0 a4 w9 N! q
" v! F; T! |; ^ // Note also, that with the additional+ d( W) Q, H- g _
// `randomizeHeatbugUpdateOrder' Boolean flag we can% X, T0 C9 ^! t9 ]! Y' {
// randomize the order in which the bugs actually run
* X* ^( Z' `7 T, s& C: I // their step rule. This has the effect of removing any" g- @( u+ t; h. C8 d% b7 G& z
// systematic bias in the iteration throught the heatbug- o% W% L$ `5 I: l9 a
// list from timestep to timestep) ?8 e# L1 k& I3 W2 z9 B2 ^
5 s" ]/ u: ?7 {2 `: O* }
// By default, all `createActionForEach' modelActions have
3 ?5 V7 Y5 N9 n) B, V0 ^! d u; L // a default order of `Sequential', which means that the
, o; V! b: f. B& s" y8 X8 L' e // order of iteration through the `heatbugList' will be
9 f$ |$ }3 F7 c U: ^7 m+ Q // identical (assuming the list order is not changed
5 f6 m" ~" w: H1 ^ // indirectly by some other process).
4 A1 ^" k7 B" D# i
9 i& [6 X1 B; I0 ^: u+ ] modelActions = new ActionGroupImpl (getZone ());
! U7 d, F, J' w. U; F7 @
' l) f2 K; [ u# B9 A$ @ try {
' I {. ~6 m% n$ r modelActions.createActionTo$message9 a# R$ I1 P* u0 k- F4 u5 x, C
(heat, new Selector (heat.getClass (), "stepRule", false));/ }6 D/ _7 w% N6 B
} catch (Exception e) {- J0 e2 k" Y* `* X; _) _' n
System.err.println ("Exception stepRule: " + e.getMessage ());: l/ e* k U" r e
}
. V `' P4 c( \- P
. q4 i# b6 H2 y4 t try { t! y1 @" O# J
Heatbug proto = (Heatbug) heatbugList.get (0);
2 R. s$ ]4 [5 I Selector sel = % P9 Z$ G4 z' @# Y" V8 S( H
new Selector (proto.getClass (), "heatbugStep", false);3 X7 `; U3 a6 f3 T7 a8 V9 ]& i
actionForEach =- l9 F( d, r5 I" ~, m# T
modelActions.createFActionForEachHomogeneous$call5 a0 K6 J+ y4 b' Z
(heatbugList,, {$ @& c% y( t5 _
new FCallImpl (this, proto, sel,
$ E- H: _: M: Q5 }. W2 L! | new FArgumentsImpl (this, sel)));
! o2 i( N& ]& A0 | } catch (Exception e) {( K) _- X+ s" x4 r# \
e.printStackTrace (System.err);5 c4 T8 `: h: a3 S" m9 w
}
/ \# F# X G6 E2 l. }! |7 x : L% U) r7 Y6 [# v% Q6 K
syncUpdateOrder ();
# b( O2 H! K4 M, x
6 p" @7 ?* {! S" ^3 h* s0 ? try {
) z# l B' c) h1 E7 ?/ H8 u: }/ s modelActions.createActionTo$message Z6 ]+ l4 o3 s. \" A: k6 g
(heat, new Selector (heat.getClass (), "updateLattice", false));7 \* z3 j1 B' _' v* W* h. V' D
} catch (Exception e) {( _* P0 J/ [+ t7 e6 I+ I" Z7 e
System.err.println("Exception updateLattice: " + e.getMessage ());! \+ \8 x2 s& I; Z
}1 b& c j( w# x w f
3 C5 J0 Q$ E# h' }, V* {
// Then we create a schedule that executes the& [5 }6 ]3 l0 M
// modelActions. modelActions is an ActionGroup, by itself it
# F6 V, Z. S7 C+ J$ @ // has no notion of time. In order to have it executed in5 G. t& }- p" `( @, E; F3 O
// time, we create a Schedule that says to use the; }- M0 M8 l1 v
// modelActions ActionGroup at particular times. This
) [" v. }( j! W+ \ // schedule has a repeat interval of 1, it will loop every4 |( V {3 P+ m$ n: \, ~
// time step. The action is executed at time 0 relative to
# y$ Z8 q5 H% g // the beginning of the loop.9 L4 {7 I" h; K
! x7 y' _ L' w // This is a simple schedule, with only one action that is
8 t+ B+ P# ~! L // just repeated every time. See jmousetrap for more
! H( B1 O. `, S // complicated schedules.
+ F0 f! H1 h" y& t7 e. d 1 ^2 ^7 x0 x8 y9 x2 z! ?
modelSchedule = new ScheduleImpl (getZone (), 1);8 d6 J+ Y6 y6 B$ b1 W
modelSchedule.at$createAction (0, modelActions);
) y' K5 |" X3 w w9 l 5 [ [! {1 W/ v' O$ ?: r0 [
return this;: y1 q, l( t1 ^1 _6 B% g
} |