HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
2 @% h. \; c/ b4 j8 n9 q( r
) ?8 N, M1 Z0 a/ Y7 l, } public Object buildActions () {
L4 Q2 F1 c8 j0 P/ g- ^ super.buildActions();
! `- }8 B5 i- r0 C6 @; {1 I
8 S) R0 x Q$ b7 X5 G. B: L. ?/ F2 q // Create the list of simulation actions. We put these in! k2 L& x. g- a2 q9 h5 M
// an action group, because we want these actions to be7 n: |9 g' F% f* x6 J
// executed in a specific order, but these steps should; G3 A* J, P& r' P* ]9 J d
// take no (simulated) time. The M(foo) means "The message
- Z$ h" x9 ^# i1 } // called <foo>". You can send a message To a particular. Z* O5 ^7 _5 i1 O$ I
// object, or ForEach object in a collection.
+ q( ~7 U, E% |1 P2 D, }* d 3 |# p% a% t: [- T* p
// Note we update the heatspace in two phases: first run: j( c8 u! H. R2 O) r
// diffusion, then run "updateWorld" to actually enact the! r" q) g; A4 X; k3 ^
// changes the heatbugs have made. The ordering here is
& e# H+ a$ ] f9 i J+ d. h // significant!' b9 n& c# ?% \0 I; [
% |& L$ U" a' s, a // Note also, that with the additional, D: V, @4 r% Z: q# x0 ^! V
// `randomizeHeatbugUpdateOrder' Boolean flag we can
) _9 m, \% N: V6 Y$ l% z // randomize the order in which the bugs actually run' T$ m, v3 j. }8 F+ a
// their step rule. This has the effect of removing any
, J; p- ]* M. i E // systematic bias in the iteration throught the heatbug O3 s5 o( s! Z8 P) r
// list from timestep to timestep; V, o( i9 \" I
4 } M1 |1 e; p/ B) D4 l- R
// By default, all `createActionForEach' modelActions have
+ f1 L7 i2 `* V- ` // a default order of `Sequential', which means that the9 R" w7 b' J6 R; d1 y ]9 S
// order of iteration through the `heatbugList' will be0 j$ X% W+ }$ v, L0 U# r' J7 m: `& G
// identical (assuming the list order is not changed" Z+ @# l: |; K8 h$ G
// indirectly by some other process)., K' E* d( ~4 j5 z. U( i
- m/ |" @- y2 @' P$ F9 t0 a2 d8 V5 ^ modelActions = new ActionGroupImpl (getZone ());
5 {+ t1 E4 [8 V4 b* s! d" m6 W( m1 ~" B7 {
try {7 X" _( r7 [' a0 i8 K
modelActions.createActionTo$message8 v3 }8 c; ]$ U* f* d1 V! B* `
(heat, new Selector (heat.getClass (), "stepRule", false));3 G. C( l1 [: t1 ]
} catch (Exception e) {
# h2 H- i2 m0 F6 {. r System.err.println ("Exception stepRule: " + e.getMessage ());" f9 n j6 b0 }' j6 T
}3 Z, K( N! y8 N( V
3 u+ }+ u8 r( {5 C- P
try { V2 g: [# R4 ~) P/ ?! E7 B; t. p
Heatbug proto = (Heatbug) heatbugList.get (0);( b" [" r( m2 A- @9 v
Selector sel =
$ f9 S, ~- J4 ? new Selector (proto.getClass (), "heatbugStep", false);
9 R" R! [" f' p- I# D actionForEach =2 ?" |$ X' C) f
modelActions.createFActionForEachHomogeneous$call
9 V8 i2 @. ?/ B$ m( s (heatbugList," h) ?5 }) J. U6 N
new FCallImpl (this, proto, sel,
: [: J4 H8 c: P7 [, w0 V+ S new FArgumentsImpl (this, sel)));
8 t7 g; w/ G! T8 \ } catch (Exception e) {
! n( y9 \; |3 O5 Z e.printStackTrace (System.err);+ j7 S* L! d4 s
}- ?0 \# M# K! x: g0 f* Q# h: x
: c; S! W, l, v; `+ Y syncUpdateOrder ();4 z5 P `, { ]
( s* M& h. K0 G try {
* c) C; ?. Q* Y) ]5 A modelActions.createActionTo$message / U4 P- A* m2 Q, e _
(heat, new Selector (heat.getClass (), "updateLattice", false));3 L, H: M) P# x7 E
} catch (Exception e) {
9 [, I7 V5 M$ I( S2 Q% } System.err.println("Exception updateLattice: " + e.getMessage ());
( Q/ ^8 M. x, D! F5 L }
& q% o8 m* @0 M( }( o$ u9 m 7 \% L$ [( a( P' E% C
// Then we create a schedule that executes the
, h$ M3 x; B" d+ u1 Y6 q" ?+ s ? // modelActions. modelActions is an ActionGroup, by itself it
0 Q+ H7 r* X5 J# M \ // has no notion of time. In order to have it executed in# _- r( W4 b0 ]2 z
// time, we create a Schedule that says to use the
7 l4 t" G2 P/ Y% X // modelActions ActionGroup at particular times. This5 T0 f* D7 ^4 {! w
// schedule has a repeat interval of 1, it will loop every
! ^3 a! T' H7 y' d9 O2 y) F // time step. The action is executed at time 0 relative to5 r4 _' b f/ u7 H: x1 k
// the beginning of the loop.- `# u$ t# V$ s
6 i6 n. R2 _8 k. i @: h // This is a simple schedule, with only one action that is- K: k4 L0 [* `
// just repeated every time. See jmousetrap for more# `' Y4 m9 l1 b% A& S
// complicated schedules.6 o0 f# I6 t9 O3 O; N
2 Q8 n' x) a9 Z/ ^: N2 U
modelSchedule = new ScheduleImpl (getZone (), 1);
7 Y$ T/ _; \+ s+ W4 _4 d, h modelSchedule.at$createAction (0, modelActions);3 H- c' C$ _# h! l
& k Z) C. g4 Z8 o e& v, k6 y
return this;
" \! B- J! y. }8 U {, `1 r } |