HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:! D0 P0 Z* C' y+ l+ [
) {" u5 p% N, ]3 ^* V
public Object buildActions () {6 v0 n, f- B A$ V
super.buildActions();, ^& I0 c# \ @! E
% y4 |, M7 E( \& w
// Create the list of simulation actions. We put these in7 H, V% G$ p& b
// an action group, because we want these actions to be
w T x& K$ x/ H; P // executed in a specific order, but these steps should( Y' T# l$ l- G& u7 d- a: p
// take no (simulated) time. The M(foo) means "The message% i& b# z1 C+ |8 e2 J
// called <foo>". You can send a message To a particular
" v% C9 U3 G/ Z7 i; ? // object, or ForEach object in a collection., o3 N ]; A) [
& h# @$ c' q- U3 J
// Note we update the heatspace in two phases: first run
7 r, l2 w- [; q( l! f+ y9 x // diffusion, then run "updateWorld" to actually enact the
7 A4 V+ G( c7 P$ W3 ` // changes the heatbugs have made. The ordering here is" B5 c" n4 t' t
// significant!1 f2 H0 G c7 |9 V* Y) }
% s3 @4 ?) Q& J6 b% b( i // Note also, that with the additional G, Z2 [9 o' u2 V7 N( @+ R$ t
// `randomizeHeatbugUpdateOrder' Boolean flag we can, y# l3 l0 l% @" A
// randomize the order in which the bugs actually run
4 W0 x. ?- G% N7 p" H9 r // their step rule. This has the effect of removing any
3 H# \0 c9 M( a8 u, [! M // systematic bias in the iteration throught the heatbug' y ?( Z3 j1 i
// list from timestep to timestep& `* `; w5 r, ~) ]
3 Q F) K4 u1 B6 h# \3 k/ ]3 T
// By default, all `createActionForEach' modelActions have
7 f# l, j1 [; `7 { // a default order of `Sequential', which means that the' L$ d& X2 z, S1 |6 T1 p
// order of iteration through the `heatbugList' will be
) p; }' M9 [% E7 c6 a // identical (assuming the list order is not changed
5 x- Z( c! Q/ J X. M! K8 E // indirectly by some other process).
5 a! m A& T" m
' m- G: ^8 M" Y3 I" E8 @+ Y* _, n modelActions = new ActionGroupImpl (getZone ());4 S9 \" @5 Y& o/ E0 E: I
/ x: ~; U \/ U: {
try {4 q2 h; i/ P1 ]8 ]3 K/ t
modelActions.createActionTo$message
% e' p# F S4 D7 S& } (heat, new Selector (heat.getClass (), "stepRule", false));; l$ E2 F. g7 x0 {
} catch (Exception e) {; f t9 r0 d' z% r8 y0 N( W
System.err.println ("Exception stepRule: " + e.getMessage ());
5 t' d' w' n4 v) s }
7 @0 V/ k" z, Q% P/ \# v* k
: M! [3 o; E' Z+ K try {
/ k" \1 I7 O) \0 Q2 G Heatbug proto = (Heatbug) heatbugList.get (0);
) |" B' I- A4 K+ H Selector sel = # h9 Z& m7 y0 _( t* o( c$ P
new Selector (proto.getClass (), "heatbugStep", false);, {& T, f# G( u
actionForEach =
, c3 E3 s& v3 Q$ g2 P3 q# @! ~ modelActions.createFActionForEachHomogeneous$call
, o2 L h6 B/ q& F (heatbugList,
) m& q2 C0 J' a: F: Q4 q new FCallImpl (this, proto, sel,
, |: z1 y8 {2 n* o new FArgumentsImpl (this, sel)));
( s: @1 r" T3 R- d) ` } catch (Exception e) {
* e" K, R' F' D e.printStackTrace (System.err);
9 r+ o t4 g5 [5 k. O7 \ }) [: z, b; H! E @
6 q: ^& ^0 T& ^( u ` I3 S& m2 V8 d/ I1 L
syncUpdateOrder ();
& W0 `* H# F4 T- s2 B1 b; p; x+ D* ~+ r J o, k4 I5 J
try {' x4 b& D! h u
modelActions.createActionTo$message 1 Z( ]) a* k! i# P& y4 m/ S, y
(heat, new Selector (heat.getClass (), "updateLattice", false));7 ^% R$ w/ O% u$ l
} catch (Exception e) {0 A3 H6 Z* B9 E3 E
System.err.println("Exception updateLattice: " + e.getMessage ());
; l. ?% n, Q. E# {& Z7 d; x }( _) h% e4 c9 m9 C6 Q: F9 W4 l k2 L
% N, }- ] [; P. j# I // Then we create a schedule that executes the3 l" G# H8 |. E3 U7 n0 P) u
// modelActions. modelActions is an ActionGroup, by itself it' s/ W0 W, X! k. }6 z& ~
// has no notion of time. In order to have it executed in8 s+ Z9 ?: s8 H2 ~
// time, we create a Schedule that says to use the
7 i* [$ e# V X7 O" t( D // modelActions ActionGroup at particular times. This+ f l' Q+ E6 s
// schedule has a repeat interval of 1, it will loop every2 W& v9 V1 _. _- a8 H7 M
// time step. The action is executed at time 0 relative to8 I, Z2 Q% t" R* k6 x' @2 b
// the beginning of the loop.# t3 R- w& @! @* V
& S, O: b: X2 s8 S
// This is a simple schedule, with only one action that is; n5 O+ J2 I1 z& v0 _, r
// just repeated every time. See jmousetrap for more
. H; | y& q* c, h: s! w l // complicated schedules.8 y r8 C$ ]9 i& z' a
3 F; {- O" r- t* a
modelSchedule = new ScheduleImpl (getZone (), 1);
% ?( W! a5 p( j# S+ F2 o" s: {9 g modelSchedule.at$createAction (0, modelActions);- ^7 d: l; n# J! `
2 Y$ I& ~. g$ I t% u7 A return this;" e' o0 N% w7 j( U
} |