HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
$ W7 d: G. S% C. i9 z: B( l4 L9 z6 `( y8 s) K' A1 n: S9 O
public Object buildActions () {
1 b( N% H7 s0 p+ L! V9 U% z super.buildActions();0 g/ u9 l& U% q
7 I: `- r( w! Y- A" F: j+ R( K% c# d
// Create the list of simulation actions. We put these in5 c# e) y5 ]2 e
// an action group, because we want these actions to be8 s6 p+ t7 j" w* u9 b; n2 D
// executed in a specific order, but these steps should* P0 U* }# B- s
// take no (simulated) time. The M(foo) means "The message
3 M+ Z9 [; s4 c // called <foo>". You can send a message To a particular3 z- f* {+ i) }# ^" f6 C, F
// object, or ForEach object in a collection.: a# Z7 f' w9 S. a
0 h& K7 g7 N2 }7 s7 ?, y1 p& D // Note we update the heatspace in two phases: first run8 i* u' W; K2 |8 U
// diffusion, then run "updateWorld" to actually enact the
+ R3 P; k! d9 ~. }# L // changes the heatbugs have made. The ordering here is2 H, \6 ^( J* j( i( \* B7 |
// significant!
6 y; y4 y* u1 R; w/ ]0 v: l* r% |8 [- Z + [8 l3 i0 i9 ]( Y
// Note also, that with the additional1 G/ u2 Y/ {# ]) }- r- Y$ K
// `randomizeHeatbugUpdateOrder' Boolean flag we can
' P) h0 S# I) U // randomize the order in which the bugs actually run; C+ V4 l* X2 O, ? i
// their step rule. This has the effect of removing any( ]7 {5 ~1 C$ y1 I7 e. l* d+ E
// systematic bias in the iteration throught the heatbug) l( s: t' f+ Z6 {
// list from timestep to timestep3 @7 c$ `3 ]6 `' y# I
/ g5 i* `' Y8 Y$ T // By default, all `createActionForEach' modelActions have
& ]/ b/ O' _9 h // a default order of `Sequential', which means that the
) I& @9 Z2 G" n+ x // order of iteration through the `heatbugList' will be
. G3 A' _/ S- b7 j* k // identical (assuming the list order is not changed. L/ I) K8 E( r/ n/ S
// indirectly by some other process).
2 i) ^6 ^: U1 a: L) s v6 A6 L0 `3 l! b
modelActions = new ActionGroupImpl (getZone ());
5 m! j% u) N8 Z# G; Q5 [0 u6 c- H6 t6 r. r+ j
try {: V) _$ [+ {' z; M& z
modelActions.createActionTo$message
4 g, t- z( V& W/ b (heat, new Selector (heat.getClass (), "stepRule", false));
9 W0 U4 n: H+ d" ^ u } catch (Exception e) {3 ]8 C0 r* B' U& L
System.err.println ("Exception stepRule: " + e.getMessage ());
% F% w6 s/ M, v6 a( |, e }2 @9 s ^' f$ O4 E, \
0 w# V( n2 F: e. ]( H4 N5 g0 s) P
try {
/ t( g( ]- M; X# _3 }( |# v% Z Heatbug proto = (Heatbug) heatbugList.get (0);
' Y, e' A( D. @4 p9 c% h* T Selector sel =
9 W+ i# Q( d9 B new Selector (proto.getClass (), "heatbugStep", false);2 m+ O# Y3 L7 t1 \: U' Q- |0 r& Z/ Z
actionForEach = ]! L4 x2 H+ @; e6 t
modelActions.createFActionForEachHomogeneous$call
% x9 q; g3 o9 Y+ A& Y+ n, y- p' { (heatbugList,
& N& W6 { H& W" p! b/ y4 v! _( U new FCallImpl (this, proto, sel,7 Z1 |- ~; B) }% l% i+ c; ?
new FArgumentsImpl (this, sel)));: |6 C/ a b1 K$ ]. g) h
} catch (Exception e) {
; a4 ~7 Q7 x4 y7 n. w: h e.printStackTrace (System.err);' B( y+ y! f+ N% ~
}
5 F' I: f4 a( R+ M ) ~/ H7 k( D: r4 L5 O* D
syncUpdateOrder ();3 U3 U% e+ V* v
# K" ?# v9 X, ]9 d+ `
try {: y0 K6 ~( k- ?! e* I1 N' z
modelActions.createActionTo$message 0 D9 @; ^4 U& o3 }
(heat, new Selector (heat.getClass (), "updateLattice", false));
; I/ e# I5 b8 L2 A" C0 Z9 s, ^! [ } catch (Exception e) {! R s" w7 C& q" L3 {
System.err.println("Exception updateLattice: " + e.getMessage ());
6 `9 m; m2 v/ h% `6 [ }
0 ?3 }. y- T) ?% t2 H 8 J7 d9 [: |" l
// Then we create a schedule that executes the4 |- M+ q7 M9 v8 E5 t' N
// modelActions. modelActions is an ActionGroup, by itself it
" S' a- b4 m- {, Y# e // has no notion of time. In order to have it executed in" w: `+ U% H3 I
// time, we create a Schedule that says to use the. ^7 L& ?4 u+ u
// modelActions ActionGroup at particular times. This
% C7 j$ T, f8 ? // schedule has a repeat interval of 1, it will loop every$ E% S/ ^5 d# S6 ?3 p
// time step. The action is executed at time 0 relative to. l# F1 n/ n4 F0 J8 L% Z. ?
// the beginning of the loop.
4 g* u Y! x* C7 D! l- `+ s4 z S$ ^6 u' k7 I2 c& ?8 W4 W1 R2 j
// This is a simple schedule, with only one action that is" W9 p5 y8 E/ X) z$ K: y
// just repeated every time. See jmousetrap for more
5 Z, v( ~5 W6 e5 S/ y7 B // complicated schedules.6 d: q7 o9 `9 H+ ~
0 O4 n% T" E4 V j
modelSchedule = new ScheduleImpl (getZone (), 1);
/ p) @6 n$ {# d! `5 V3 }: @ modelSchedule.at$createAction (0, modelActions);
; z# H3 X6 G7 U 8 U; g& j' K7 p* m
return this;
% X9 b6 u% r1 ~9 n- x2 F" Q } |