HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
8 r, S5 J& J: a8 |2 ~4 A: O, z2 k" F, U/ I
public Object buildActions () {1 \# t L$ t. N9 Q1 Y
super.buildActions();
$ \4 \( }: M0 e3 g" M
5 @/ f- u% |5 U# q6 A% L3 t // Create the list of simulation actions. We put these in
4 ?* @* H0 @3 p7 O) N8 `) y3 h // an action group, because we want these actions to be
: T, J5 ~3 z" T. S$ P9 ]: Z9 V0 {6 H // executed in a specific order, but these steps should
% I' }! S; }: ~) @' Z( l // take no (simulated) time. The M(foo) means "The message
( F2 R, X* r- j1 A( o" Q k* B1 K // called <foo>". You can send a message To a particular
8 ^9 Q6 m. X9 s$ e3 t // object, or ForEach object in a collection.4 T! r2 a* H! M& \* J) a1 r
) }6 O1 ~2 }( ^. v& s2 O
// Note we update the heatspace in two phases: first run
4 d" ?3 U" Y! ]+ A' z& M J4 f // diffusion, then run "updateWorld" to actually enact the! o1 s7 V7 N; h G
// changes the heatbugs have made. The ordering here is- H% ?8 N1 V8 e3 r2 `
// significant!; M3 s ~* @/ n5 D6 |! J
- y4 c% k" U; I/ V1 o# z // Note also, that with the additional1 D# `2 z W' c
// `randomizeHeatbugUpdateOrder' Boolean flag we can! @4 t. s; b: X$ k
// randomize the order in which the bugs actually run3 q+ B* H8 |5 I: ?* y
// their step rule. This has the effect of removing any( Y' B, y* G7 K
// systematic bias in the iteration throught the heatbug
) J/ ?) @0 r/ @: w; a) s" @ // list from timestep to timestep! j( L% E2 [6 J; |8 t8 X
/ c& w Q4 k4 }' D2 i( c
// By default, all `createActionForEach' modelActions have
2 A% v% \ r, N) ` // a default order of `Sequential', which means that the( j2 Z# M8 J3 e X- f# [. X: ^
// order of iteration through the `heatbugList' will be- a6 T, _* D% e ^ {
// identical (assuming the list order is not changed
1 S7 W: R: S) K6 T5 p // indirectly by some other process).
0 S( G+ h8 n9 A( Y 3 r' ?6 e f5 [6 \& J) [! J# u
modelActions = new ActionGroupImpl (getZone ());2 W% F) W' i1 ~" \$ J
% D5 p! w& T; s
try {( x( a# @3 B7 N4 r T/ v* \
modelActions.createActionTo$message+ L' d) ~: M( E+ }* a4 O& _' R
(heat, new Selector (heat.getClass (), "stepRule", false));
( Y/ Q, U' Y" M) w: _7 J1 R } catch (Exception e) {
9 X! w6 i( U" s1 [' B System.err.println ("Exception stepRule: " + e.getMessage ());
* I0 A' k6 [) c# t5 a }; B& F- j( ~: ^8 l6 P. q* O
% @0 H; l Y# j* N1 [4 n! m try {3 U/ o, a8 d5 n
Heatbug proto = (Heatbug) heatbugList.get (0);
+ r. G2 D2 B9 T" @ Selector sel =
: o0 y* ~ P& Z" M$ S8 W2 u new Selector (proto.getClass (), "heatbugStep", false);
, f/ T7 N+ Y) H4 \ actionForEach =7 y" ^/ m& ?5 p5 y
modelActions.createFActionForEachHomogeneous$call3 n/ ~ [$ `7 [3 [! g8 w
(heatbugList,
p, Y/ Z' V0 ]+ g new FCallImpl (this, proto, sel,1 ?0 x/ D8 o5 R! a8 j
new FArgumentsImpl (this, sel)));
' N+ t, ~% n0 k1 M: w } catch (Exception e) {
4 E( [2 I7 c/ ?( x8 F ^ e.printStackTrace (System.err);
6 V0 G( J( j7 a2 Z6 U' [& P }1 A/ \( b4 J+ ~( M9 M$ a. Q
5 U( v8 Z' g( S+ q. F. {$ }) k syncUpdateOrder ();
, Z- n$ ?+ W3 j; f" H R- ^8 l; F6 H' e, H' l+ w: _( x
try {
5 O9 g/ G* B+ H/ D8 n! [; G modelActions.createActionTo$message
' ]7 P6 }9 I4 ] (heat, new Selector (heat.getClass (), "updateLattice", false));7 k4 p6 }+ ~1 S4 {
} catch (Exception e) {
. X8 y4 F) T& n2 L* k System.err.println("Exception updateLattice: " + e.getMessage ());
y" N+ g W- x0 l }
9 g: W# ], [4 O6 B; {/ k! d5 `: t
, O2 D* l! X& J0 x7 m) d' Z // Then we create a schedule that executes the
|- N3 ~, ~2 @# ]6 K$ l // modelActions. modelActions is an ActionGroup, by itself it1 h3 {& @2 @, ?7 A' P0 s" g
// has no notion of time. In order to have it executed in$ p% ? o& T* d0 G$ b
// time, we create a Schedule that says to use the' x+ e) l9 ~5 t+ A
// modelActions ActionGroup at particular times. This z( W- h7 O$ |& I, P' w
// schedule has a repeat interval of 1, it will loop every
; a% a& v2 v5 ]. E/ L6 a& O // time step. The action is executed at time 0 relative to3 ^6 h, g2 d1 P
// the beginning of the loop.; n, H& \' ?3 A9 D" g0 F
4 t( E0 ^' z* i // This is a simple schedule, with only one action that is
9 Q" a7 W$ u- {1 ^ w // just repeated every time. See jmousetrap for more
0 G8 b2 i4 G. J3 m // complicated schedules.2 E4 B$ |" J5 u7 u
6 Y; G# Y3 g9 y modelSchedule = new ScheduleImpl (getZone (), 1);
7 r6 k5 s! t' |+ t. f3 y/ B. }1 T modelSchedule.at$createAction (0, modelActions);, d- y1 X R9 G7 Q3 i
$ Z2 `* z8 X! U; S" ^" a; A
return this;
& |5 k8 |+ N( E5 ^ } |