HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
. X/ o- L/ c1 n2 L B$ |+ s; s/ e" T) o% [% _/ ~
public Object buildActions () {$ r% k7 P1 O8 m/ F
super.buildActions();
6 H- H" {7 k/ U: y, l
1 Y' l( C; |' V; M // Create the list of simulation actions. We put these in! X8 y) F8 w1 J; n2 ^/ N
// an action group, because we want these actions to be
( p4 `: d& V$ c // executed in a specific order, but these steps should: |) b- c: t! N& j
// take no (simulated) time. The M(foo) means "The message
, N8 ~2 |- Q) s1 ~4 j // called <foo>". You can send a message To a particular) G' ?( o8 _" @+ X
// object, or ForEach object in a collection." n2 G8 D" S, N' g
8 T' z* K+ h U" h ^6 Q // Note we update the heatspace in two phases: first run
1 O3 u9 d' |! N" n/ i1 p3 K4 u // diffusion, then run "updateWorld" to actually enact the
1 Z0 ]' a. L4 Z& r // changes the heatbugs have made. The ordering here is; }( F+ S9 f$ z* i5 r; k* Z
// significant!9 a) z/ a$ V. W) U. L: u2 w( h
I) l/ x" V; ]& f. u$ v. C1 z) f
// Note also, that with the additional9 q( {8 O5 S* X j! p
// `randomizeHeatbugUpdateOrder' Boolean flag we can, Q( r x- G, q
// randomize the order in which the bugs actually run. `$ a/ G; q2 j+ r0 ~: |
// their step rule. This has the effect of removing any# E8 U& j1 ^: N$ N- a% a; Q
// systematic bias in the iteration throught the heatbug
9 C/ w' U- D+ `6 ^( k7 q+ s // list from timestep to timestep% h' W1 W+ f. ~( P& E5 q7 O. p9 c! s
9 T3 H! o% H6 f& @1 U/ g. Q
// By default, all `createActionForEach' modelActions have
+ x" s; H/ m) i) c% @0 Y) U // a default order of `Sequential', which means that the
! |. J6 a6 [) z* @4 Q- J! Z // order of iteration through the `heatbugList' will be& }- f Z* v9 d8 z' U, M. o
// identical (assuming the list order is not changed4 I) \& ~% N2 }- p1 r/ a" ~
// indirectly by some other process).
% [& }3 K, o) |9 W& [( Q
7 C5 n$ @7 E5 C" d- s# p modelActions = new ActionGroupImpl (getZone ());) ]' a3 z( w$ P! G
5 {$ o! f+ U5 ^$ c9 u( [ try {# k/ j) s& [+ O1 W# ~
modelActions.createActionTo$message6 ~. t& V; G9 x' K. o9 a8 h5 o0 G3 p
(heat, new Selector (heat.getClass (), "stepRule", false));5 g, q. z1 Q/ K& t- N* M) [
} catch (Exception e) {
2 I, f$ s8 |; }$ F System.err.println ("Exception stepRule: " + e.getMessage ());
) e0 m2 A7 Q1 k+ `4 N; v9 G a }$ x+ R7 s2 f8 I! \, i; `: l
' a' p- `) L. b7 L
try {
" @8 }& D( a2 B6 m' _5 t Heatbug proto = (Heatbug) heatbugList.get (0);
% Q+ ~7 G7 u6 Q' v' W Selector sel = 2 S1 p/ |" w' z0 ~9 K8 d
new Selector (proto.getClass (), "heatbugStep", false);7 j5 N4 y. |: E- @) h+ g2 D/ ^) Q
actionForEach =8 ^) p5 c$ G- q: B8 T
modelActions.createFActionForEachHomogeneous$call
0 b8 {! N: a! d (heatbugList,
+ V* [' g$ q4 i4 A1 R) A5 g new FCallImpl (this, proto, sel,9 p3 Q7 a, z& s# _5 a1 |6 r
new FArgumentsImpl (this, sel)));; ?( j* |* \- p+ U( @& X' f/ u
} catch (Exception e) {( i/ _' d% @3 R9 U, R, w: h% [& ?
e.printStackTrace (System.err);
* X! E' Z# u8 o8 f2 ^3 k) C8 u }9 g+ B2 }0 z# H: P
) N# E6 O" ?" n) \
syncUpdateOrder ();
' l% `3 x, d6 W1 Q# Q; W3 j' I1 Z! G9 m. X
try {
' P, C! K3 V* u0 P modelActions.createActionTo$message ' N9 ~, ^6 p' a8 ? b' |9 u
(heat, new Selector (heat.getClass (), "updateLattice", false));& C1 o5 G0 S1 y# B' }" z
} catch (Exception e) {1 Y$ L& E# x7 O# ^& s0 p: P
System.err.println("Exception updateLattice: " + e.getMessage ());
( Q/ c/ W4 Z$ Z4 V }3 o3 r6 Y- Z$ e8 S4 l; W& K1 m, s
. g, `8 v3 S( ?7 q0 W2 ~! H1 |; @
// Then we create a schedule that executes the
8 }: {8 V W. U, C% i1 J- Z // modelActions. modelActions is an ActionGroup, by itself it% t. y! u/ H- c' v
// has no notion of time. In order to have it executed in; w8 w0 T, ]6 } ^3 _9 J6 {
// time, we create a Schedule that says to use the6 N# M, S& u6 e3 a
// modelActions ActionGroup at particular times. This( V) c5 b& e! s5 e
// schedule has a repeat interval of 1, it will loop every& S# Z5 W n$ b% C
// time step. The action is executed at time 0 relative to, ?* l/ X6 O5 k% n8 d1 {$ V+ I
// the beginning of the loop.
7 t" T/ Y: U6 p, G% E s( E* J# ^+ |& k! ]3 Y+ B
// This is a simple schedule, with only one action that is
h. `; e i; I. F+ R // just repeated every time. See jmousetrap for more8 Z1 ^8 m: t# e- j( E6 e& A; }
// complicated schedules.' b {$ d' T1 g' O
8 ^. ~* F2 D/ Y- W5 r H# A modelSchedule = new ScheduleImpl (getZone (), 1);
~& y# D: T' e6 ~- L- { y modelSchedule.at$createAction (0, modelActions);& B+ ~ u9 ^1 `, U7 X2 q7 ^% x
2 }+ \& P r! I/ C$ s return this;
6 w0 Z: P2 x1 _* m* s } |