HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:2 D* O2 q; V' D( \! }2 W
5 D6 M* B0 F3 r0 O public Object buildActions () {6 \) V! t9 L( M0 U- B5 N& J
super.buildActions();; X+ t7 Z C; J6 I) c# f
5 w% L! K( H; x // Create the list of simulation actions. We put these in: L4 ^& M* J- |* H
// an action group, because we want these actions to be, {- Q1 `% _) U5 y' V0 z
// executed in a specific order, but these steps should
' L3 X- q3 j# ^( T // take no (simulated) time. The M(foo) means "The message
# c1 _9 p% g. E // called <foo>". You can send a message To a particular, }5 {0 H7 s4 M
// object, or ForEach object in a collection., B8 C9 y0 a% W& [5 ^) W: u/ F
" E+ C" s; E1 U8 U2 i( k4 x% { // Note we update the heatspace in two phases: first run
E! ^' r, N A: D: T // diffusion, then run "updateWorld" to actually enact the
; x/ s. {" T% g9 f+ t: j ^$ l/ _' x // changes the heatbugs have made. The ordering here is
$ ]" _/ r6 y! p // significant!
' I% X; y! c* u3 ]/ }+ K
$ N6 p7 ~, h3 |1 \9 g8 |( y // Note also, that with the additional
' ]0 Z, v/ r6 L // `randomizeHeatbugUpdateOrder' Boolean flag we can( ?: N3 z+ M% X# E8 c( R0 s
// randomize the order in which the bugs actually run
( P+ @1 B$ Y! r$ ~3 v- {$ t6 k // their step rule. This has the effect of removing any# c3 |! R7 ^# e7 u4 l) S
// systematic bias in the iteration throught the heatbug
% R2 h$ e8 w% c$ K2 Q // list from timestep to timestep7 Z3 U; y% H7 K
0 l- P, N& u+ B# K% B% P; G // By default, all `createActionForEach' modelActions have# R. O' M/ ]: i
// a default order of `Sequential', which means that the/ x6 v& E! e) j
// order of iteration through the `heatbugList' will be
" ^3 w) m5 x2 M6 P: T. k2 T( V // identical (assuming the list order is not changed# F* o$ H! j3 a( l: n9 u+ ^( l
// indirectly by some other process).+ D/ V: i5 H0 z( D
$ V* k) n+ u! O) `4 [$ R' ?
modelActions = new ActionGroupImpl (getZone ());
' V# P1 V% | B# ]' @& w
& y1 r1 {" K. W; | try {6 ~4 g j: O1 x# a1 I9 C
modelActions.createActionTo$message0 |7 ?( k4 f3 @8 E5 j; X
(heat, new Selector (heat.getClass (), "stepRule", false));
[) r- w! x! [5 C } catch (Exception e) {0 X8 y0 H! K( ^3 E5 H3 o$ b% j& ~
System.err.println ("Exception stepRule: " + e.getMessage ());" @9 N. b. K) A4 J P$ a
}
; d$ w1 H7 |1 @; U, Z2 i+ W
! _/ x& @- V. E* N4 V$ y/ r try {
; S5 T8 g) Y/ W. p- s7 D4 X+ X Heatbug proto = (Heatbug) heatbugList.get (0);* K7 s: A# c) v
Selector sel =
$ `* Z2 P/ H& T+ \+ F new Selector (proto.getClass (), "heatbugStep", false);
) I7 W: S* M2 C7 M* {. y2 l actionForEach =
0 c4 ~+ \: I. T modelActions.createFActionForEachHomogeneous$call% V4 q% |( m7 i; X5 M/ {8 h0 C
(heatbugList,1 j/ D! h6 O# s& b
new FCallImpl (this, proto, sel,
% ?8 q. ~/ i* {( c# O) ] new FArgumentsImpl (this, sel)));
: |" M$ ^2 @1 |6 N, e4 M1 I! E3 \" S/ E" ~ } catch (Exception e) {% e' `1 |3 T; b, z+ f
e.printStackTrace (System.err);6 G" y1 C, D7 a. [
}
9 @0 P8 ~9 Q: }% ]. `& i
/ v% r4 s1 F8 l8 U( ]0 {3 m syncUpdateOrder ();" ^" J8 V0 V- e0 g8 j& X2 B
! h5 T+ R8 o& [ @3 G
try {
# r4 r2 W7 y& g1 b3 a modelActions.createActionTo$message ; Q/ @2 K/ t6 A7 X
(heat, new Selector (heat.getClass (), "updateLattice", false));& v, T% M L3 O9 {) T4 H
} catch (Exception e) {
8 d$ f$ k0 t' c1 ~2 [, Y System.err.println("Exception updateLattice: " + e.getMessage ()); A- {* s+ W. u* V
}
: W& n c2 U4 `% }% E& h 4 s Y+ s6 c0 C5 n/ ]! w/ L
// Then we create a schedule that executes the! r0 u; w6 T# e: T: N, a
// modelActions. modelActions is an ActionGroup, by itself it5 \1 z/ p) @: g+ J& y9 ^
// has no notion of time. In order to have it executed in. C; V. ~" s$ C; `, w/ B" h
// time, we create a Schedule that says to use the3 Z+ f e. M) I
// modelActions ActionGroup at particular times. This- ]2 b# h! `. N; H* r2 A% ]
// schedule has a repeat interval of 1, it will loop every+ n. A% l+ g: E$ d3 `
// time step. The action is executed at time 0 relative to9 s6 f( R& a% [
// the beginning of the loop.
" J3 Q# m) v' ]( v. P( z2 N7 S! a
// This is a simple schedule, with only one action that is
+ K6 C3 o) G, N8 c // just repeated every time. See jmousetrap for more
; K" X" O$ L, ^ // complicated schedules.' m( f9 B7 K5 {, E/ U6 ^; s
9 I. z- }: W1 H/ d4 m9 s: E/ M
modelSchedule = new ScheduleImpl (getZone (), 1);
. ` m# }* Y: ` modelSchedule.at$createAction (0, modelActions);
5 N; Z k+ F! E+ j9 N& ~ c
7 }" L# n7 H' A return this;- p8 q% t; O( U. h4 W' k
} |