HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:. ^9 d# p! F/ p) y; s
% S" P: [& K) h) ]. l# [- M4 ] public Object buildActions () {
' ]$ _8 @; U8 a6 y! S super.buildActions();
0 I9 H2 q' }9 [7 y$ g4 B' T
6 z+ l1 H, P2 ]+ y+ l# M // Create the list of simulation actions. We put these in5 z1 w. O2 X- M$ p- b1 Y8 P
// an action group, because we want these actions to be/ F T% m3 `# \1 g4 I; G
// executed in a specific order, but these steps should/ w/ s( N8 t6 m2 T/ y/ j
// take no (simulated) time. The M(foo) means "The message; n( }3 m; e# q. e
// called <foo>". You can send a message To a particular$ G8 M3 s4 @2 i6 F( H4 s; u" F
// object, or ForEach object in a collection.5 v$ Y6 e2 c$ ^0 Q4 V5 d
# V6 ]! g; I9 p) ^; }- ]/ | // Note we update the heatspace in two phases: first run
; _ ^% X+ X, {' i // diffusion, then run "updateWorld" to actually enact the+ q {3 M+ |1 p' S
// changes the heatbugs have made. The ordering here is
0 A) S& X: d+ e // significant!9 j/ Z, t( a! z" \. [
% y7 w3 [0 d) @& r7 Y& @
// Note also, that with the additional" E' G9 Y% k' q$ n
// `randomizeHeatbugUpdateOrder' Boolean flag we can1 y. O0 o, N K, [/ d
// randomize the order in which the bugs actually run
! N4 J1 r: `) B // their step rule. This has the effect of removing any( Q: K* @4 V7 E6 S8 R: [( l7 V! S
// systematic bias in the iteration throught the heatbug- A: {; |2 ~. C* G& ?; U
// list from timestep to timestep
& {: y4 J9 J) B' v$ `" [' N
) M( K m' L- U% S1 | // By default, all `createActionForEach' modelActions have4 |2 \$ e g# i3 h8 k1 D5 Q ~. }& D
// a default order of `Sequential', which means that the* i1 L( x7 M/ A8 h4 Y
// order of iteration through the `heatbugList' will be# P1 I# n1 @. Z6 b) h
// identical (assuming the list order is not changed7 z( E; q8 J3 ~: B. M( u
// indirectly by some other process).
' Y& F; [3 m8 N X6 _" M
" I" b& b `9 L0 Z! ` modelActions = new ActionGroupImpl (getZone ());( M [' |* [. F8 o% Y
. E" {$ h, |, m P& P8 Q try {( t5 F: k: Z/ G1 G9 H! U
modelActions.createActionTo$message
) I3 N9 {8 M: i (heat, new Selector (heat.getClass (), "stepRule", false));
/ m1 X! N4 X; u1 z+ J7 O7 ?' ^3 s } catch (Exception e) {- E( P- T- r' A
System.err.println ("Exception stepRule: " + e.getMessage ());8 k+ P" f4 }1 U& P9 t- o
}3 p3 h6 o2 k6 E) t( Y
3 G& P) |& D w l3 H+ z( k& S E, v, j try {; t( \7 s2 y' E+ z7 J4 n
Heatbug proto = (Heatbug) heatbugList.get (0);
- ~6 ]5 K% V* V/ | Selector sel = 9 `; D3 p" I" t) o5 W4 z# @" E
new Selector (proto.getClass (), "heatbugStep", false);
" u& b/ J; |$ c8 H actionForEach =
) E0 }* ]# y/ p5 ?. L5 y modelActions.createFActionForEachHomogeneous$call: ?0 \. N: j) z- [
(heatbugList,
0 n: X1 b f; d. V4 W3 \0 i: F new FCallImpl (this, proto, sel,' c7 }, S* t* M9 ]" M
new FArgumentsImpl (this, sel)));: v U5 d& f3 {) Q5 x, X2 X4 P3 d/ [' t
} catch (Exception e) {4 X& O+ W% D ~6 r+ i
e.printStackTrace (System.err);
6 M" F# F" {( D; z; W) g1 k }
m8 F% `, F- U! v, }
! L2 |7 f) t1 ^2 p0 W syncUpdateOrder ();
[( w4 K& b( E6 n1 i* U% e4 s+ J* ?& y( |
try {1 h6 L, x2 d1 }! a2 F% G
modelActions.createActionTo$message 8 O" {9 g* e5 T2 J
(heat, new Selector (heat.getClass (), "updateLattice", false));
# [- ~$ T/ Z+ C6 N# Q. n } catch (Exception e) {
: S( ~# O2 i# }+ ^5 z- i0 B' f System.err.println("Exception updateLattice: " + e.getMessage ());
c% U+ X5 C+ q' Y* K, x }' i" j2 P6 f. U/ z- K
& U/ L# q1 V; A7 ~ // Then we create a schedule that executes the
9 O4 l( R8 S; U // modelActions. modelActions is an ActionGroup, by itself it: t8 H2 K4 I* B! J- _
// has no notion of time. In order to have it executed in
& l. E. o4 F. y2 z3 D# `- ?$ n // time, we create a Schedule that says to use the3 }( { z. M+ g$ t# r
// modelActions ActionGroup at particular times. This7 I I F! g2 V/ P4 k
// schedule has a repeat interval of 1, it will loop every
0 U3 P4 ~, z6 S // time step. The action is executed at time 0 relative to
! K8 b Y: R8 o* B4 o2 L // the beginning of the loop.
3 F, t3 f2 @- f) t) `" W- ?' M5 Y" x O/ m
// This is a simple schedule, with only one action that is
& z% x7 P, K% E" m // just repeated every time. See jmousetrap for more) o7 U* O: |( S) U. ~' r& k1 X4 O
// complicated schedules.
/ M1 `" t4 d" E
$ i) r$ r! f: P& a' m: U modelSchedule = new ScheduleImpl (getZone (), 1);6 i3 w- X$ z- f' u( X: }3 A: e
modelSchedule.at$createAction (0, modelActions);
* G, @" X5 I* i4 T# y 4 }, M! b R) V
return this;
& u* c- A2 b9 s7 V# a } |