HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
2 T0 c/ a9 v3 P) c- ~' s; l. v7 c6 n1 x- L% i; U
public Object buildActions () {5 N! _; w' Z/ j ] P/ m/ @
super.buildActions();
+ i) X/ ^* n' D: g1 B" m @* V7 c& p
) X, |/ M* v1 M3 E3 e // Create the list of simulation actions. We put these in
, T" h' B; P' e8 P0 e // an action group, because we want these actions to be. l' m+ r: ^9 ^6 s
// executed in a specific order, but these steps should0 }+ t% m4 I5 F3 Q
// take no (simulated) time. The M(foo) means "The message8 K4 X' j* h9 y4 r5 H1 \8 f
// called <foo>". You can send a message To a particular8 ?% x$ l. T( k% b
// object, or ForEach object in a collection.6 ^7 `' Y% }0 y: E; C3 g! r
% h6 f# v' J8 F U2 X9 W
// Note we update the heatspace in two phases: first run6 K+ ~/ U, E2 j: R7 ]$ A
// diffusion, then run "updateWorld" to actually enact the
& V$ @ n) c# p0 K // changes the heatbugs have made. The ordering here is" J5 ?5 v# q7 D% `
// significant!5 D, Q6 k9 f; \- I
4 c/ |* x( y/ a$ I2 g* u6 u/ e6 b5 P
// Note also, that with the additional& `4 `2 [: F- ?; m% N0 B- D. E% a& h' I
// `randomizeHeatbugUpdateOrder' Boolean flag we can
# o8 |! N5 g6 H; m6 I // randomize the order in which the bugs actually run R& q) P) R& F" u$ E; D C( d
// their step rule. This has the effect of removing any W' \4 y5 T w: w4 ]
// systematic bias in the iteration throught the heatbug
: Y2 r2 U5 k: n+ { // list from timestep to timestep
/ Z. F& h- L1 `( w* \0 W) H
5 n) i K4 V4 A // By default, all `createActionForEach' modelActions have6 S& T3 t p# p& D# g4 j- m7 e
// a default order of `Sequential', which means that the
1 E8 I7 S/ J( {) Q // order of iteration through the `heatbugList' will be! s! a" q3 `6 u' @8 K- G! ?
// identical (assuming the list order is not changed
. k! ^$ R8 k ?, x* H! ? // indirectly by some other process)., ~7 c3 Z* A2 P
# c% s; w! I0 t) o+ L modelActions = new ActionGroupImpl (getZone ());
6 G9 B% Z- S' d* w2 e% g% h3 ? F- M7 p' G( x0 ?2 P% Z; H
try {" @/ K( E/ G# c5 w/ U0 y. J
modelActions.createActionTo$message
4 {( z9 w" q, A; Q (heat, new Selector (heat.getClass (), "stepRule", false)); Q$ \7 z7 x; j r. ?7 `
} catch (Exception e) {. g6 m* O9 I2 u$ @" z0 E% y7 O
System.err.println ("Exception stepRule: " + e.getMessage ());5 N2 Q: Y+ r; g3 q3 V7 q7 `
}8 j: {5 |9 y1 }4 H' u6 I6 V ?
8 d. D6 Y9 c: B2 ^. Z, `2 Q try {
: A* s: y( d$ r5 v* ]4 D' g2 { Heatbug proto = (Heatbug) heatbugList.get (0);
8 Q- s& s- s) }) D5 O- x Selector sel =
9 @5 {2 A- u) ?* X# \ new Selector (proto.getClass (), "heatbugStep", false);, A4 M7 k7 B( e% t
actionForEach =
! g. `3 ]) o1 V/ d modelActions.createFActionForEachHomogeneous$call; R+ l# x" z+ H, |- R/ p* A
(heatbugList,5 V0 F7 C0 L" X) C, W
new FCallImpl (this, proto, sel,
% x. o; j/ K0 B, B, |- g new FArgumentsImpl (this, sel)));
7 }3 r5 h4 z, X( s7 @ } catch (Exception e) {% N) M. a4 _% z3 }0 U
e.printStackTrace (System.err);
& I9 M) z8 @) c3 {6 @' y }
( s- D, H( E/ q/ P& [) `" ?
8 B8 r8 K2 ^, p( S syncUpdateOrder ();6 L/ f# ~5 H7 m) A
+ b3 S9 r2 [ [- F# }5 a
try {
" j0 \3 b8 S5 d1 Y modelActions.createActionTo$message 5 C0 I; q4 F) a. S0 s0 u
(heat, new Selector (heat.getClass (), "updateLattice", false));
2 @. r- O$ s! c. z5 [2 s } catch (Exception e) {
; L/ y0 @) R8 Q H# V9 f System.err.println("Exception updateLattice: " + e.getMessage ());7 Q; z- `. M! G" G4 w; {
}
6 R3 a6 Z4 V" t
) X, J# w, h/ f9 V _. w6 S2 \& w // Then we create a schedule that executes the
6 x+ v: n9 b0 p& G7 X& d // modelActions. modelActions is an ActionGroup, by itself it
5 k: z* N. @' y4 f6 H. k% i0 z // has no notion of time. In order to have it executed in
f: `& j B& ]6 m ]5 g, j4 @ // time, we create a Schedule that says to use the2 F0 ~% V' T2 B! h' [
// modelActions ActionGroup at particular times. This+ n% W5 `4 j, I2 a
// schedule has a repeat interval of 1, it will loop every6 I# R: P3 r* \" x& M
// time step. The action is executed at time 0 relative to* s0 w3 ~2 N6 {+ {2 _0 t# R% K
// the beginning of the loop." A! o0 s- ]7 m5 p. S
- f* s, j9 n- M, H) R# s( Q
// This is a simple schedule, with only one action that is6 Y+ c" U6 w5 C( H, q" E w7 O
// just repeated every time. See jmousetrap for more7 O; k. X9 s# U6 y
// complicated schedules.! B1 S+ C+ X8 ~
6 ^/ d: E* u7 R' O modelSchedule = new ScheduleImpl (getZone (), 1);
6 `" G L! K2 E! c& J modelSchedule.at$createAction (0, modelActions);
w, g1 h- k" C) f; n/ Y% q4 m 1 f* g% a' ^) |0 ~' F/ A6 A
return this;
0 Z- C6 M7 r. u7 U } |