HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
1 k3 R" u' Q y: O e! v/ b2 H) S! p, N E
public Object buildActions () {/ ^7 R. l7 S% J2 w: k
super.buildActions();
. a; `: e5 t1 O3 P/ K
7 M) }5 d, ~7 b! P/ i; G" f4 ~ // Create the list of simulation actions. We put these in1 E# e6 z, n9 P) X# g: z( g% @# n/ G
// an action group, because we want these actions to be) x- }1 t2 g, F9 x% G" a5 j. o c: Z; y
// executed in a specific order, but these steps should
8 H6 |3 q c9 F* f, J: b // take no (simulated) time. The M(foo) means "The message
+ n. l' J2 D& ]3 E // called <foo>". You can send a message To a particular
& } z- v2 p; {, X // object, or ForEach object in a collection.
3 n( w# n8 j+ Y* `+ ~' \' z 1 q7 b& e1 o* y4 ]5 ?3 b6 n* D3 c
// Note we update the heatspace in two phases: first run& v" k4 y) ]% }6 Q1 H7 S
// diffusion, then run "updateWorld" to actually enact the
% N i4 ]- V. \1 U2 y6 t! q' N // changes the heatbugs have made. The ordering here is5 D" f# i6 h- Z3 {9 H$ u9 y3 U9 `
// significant!" S* l3 h' Y$ {7 Z3 s
7 z" i7 A9 q9 U% ^0 v' ?, w3 C // Note also, that with the additional. f9 S7 l0 p8 F! m5 |% q6 a/ o U
// `randomizeHeatbugUpdateOrder' Boolean flag we can! c8 _( O% |" _* T4 c5 i" ?& X7 `, z1 d
// randomize the order in which the bugs actually run
9 Z- a& Y: ] w7 n* @ // their step rule. This has the effect of removing any
& v0 x1 ?6 K0 N8 t1 J // systematic bias in the iteration throught the heatbug; a7 A$ G: m' I3 [* I+ q9 o" z1 W
// list from timestep to timestep+ P7 I/ C: K+ j& @0 t
: e5 T* Z2 C: ~- O" p
// By default, all `createActionForEach' modelActions have( @" p/ p, O: R9 F. m
// a default order of `Sequential', which means that the* v4 A% l2 T( @. J3 o) { v- E" b
// order of iteration through the `heatbugList' will be' \2 C" a2 t1 ^8 H
// identical (assuming the list order is not changed/ K6 j8 R9 v9 p% I& H7 |, S4 n
// indirectly by some other process).3 T! `& Q7 ^$ g9 }( v H- v; K
8 q0 G7 C: ]- R: @* q
modelActions = new ActionGroupImpl (getZone ());
( Z+ B7 J4 ^* |6 x5 b
& {# x5 A. s: V9 Z' j1 m try {, o0 Q* E* E2 G5 ]0 c
modelActions.createActionTo$message" l I4 u7 J5 [6 a8 A0 a1 c
(heat, new Selector (heat.getClass (), "stepRule", false));3 l: E, R* H, A C8 [% y% d
} catch (Exception e) {
: n+ q8 L% |- C, d; G% S- o System.err.println ("Exception stepRule: " + e.getMessage ());, U( t* ^9 ^1 N
}
+ ?% Q9 |' M4 N& R( x' c0 R! @- C% u5 E8 `
try {
# U9 z( \, [7 ~2 p5 ? Heatbug proto = (Heatbug) heatbugList.get (0);
6 q7 j" a0 p4 |" a2 Z* x Selector sel = & g: k9 F* w8 D' Y
new Selector (proto.getClass (), "heatbugStep", false);* B& ]* t- X8 {% R. ]
actionForEach =
3 \/ G8 [! j' B! y3 l2 Z modelActions.createFActionForEachHomogeneous$call) W8 c/ c7 N h9 w! C- K: m
(heatbugList,( O# v1 R) _- N! e- ^1 x0 w6 C; k
new FCallImpl (this, proto, sel,
' g- d4 ?7 M' C2 E new FArgumentsImpl (this, sel)));4 Z% J: Y6 F$ B M
} catch (Exception e) {+ x2 h/ h& e8 Z: O3 L/ v N
e.printStackTrace (System.err);
0 k4 f, F1 p! D# H$ u+ G$ _ }# d3 ?! u: i7 M, f! ?3 M
+ E7 Z: b& P" } syncUpdateOrder ();1 e5 R# B! n4 \4 }( @ W
. c Z( `/ u; z8 C) _% a) \& W
try {( q; Q; N& C6 @! u
modelActions.createActionTo$message
8 z7 q; C! @: l/ k$ O) v z3 \ (heat, new Selector (heat.getClass (), "updateLattice", false));/ w" }: s& o7 T, l5 z
} catch (Exception e) {
) e" j8 }6 f, l% r. Z& W System.err.println("Exception updateLattice: " + e.getMessage ());
' B- T9 H9 T& E d! ` }
$ P1 u. p( L6 F8 u" I( T: L) L
% v! A) i) r1 Z // Then we create a schedule that executes the
) q( z8 S% b# z+ ]% w: r // modelActions. modelActions is an ActionGroup, by itself it1 W' ]( v" z; w m
// has no notion of time. In order to have it executed in
8 m) `; w) I% z: f // time, we create a Schedule that says to use the
" E) m. O5 s; H3 `' A: Q) a // modelActions ActionGroup at particular times. This$ q8 n0 ]; H0 S7 r* Y# }
// schedule has a repeat interval of 1, it will loop every; K. j* N6 W2 ?# i. V! d) c
// time step. The action is executed at time 0 relative to, x) b/ n# Y& \7 k0 G+ g- [' j
// the beginning of the loop." e$ i0 h# y; Z
8 g+ k1 [2 x0 C: v9 ~
// This is a simple schedule, with only one action that is, Z7 f& ]+ N* |( {
// just repeated every time. See jmousetrap for more
) A( T8 [# f9 ~* m // complicated schedules." S& x# m! K6 N5 w" d Y
. {/ e/ e" b- p
modelSchedule = new ScheduleImpl (getZone (), 1);4 ^' I# D5 q1 B
modelSchedule.at$createAction (0, modelActions);1 `1 ~/ A8 g- \3 s4 D' ~ j
& B X' W k4 r: j$ {* G
return this;4 t: k( W" H/ d: M P
} |