HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:* V* p0 l6 P5 o: @
" D5 z: W/ H9 o! N2 V4 B. ~
public Object buildActions () {" ]. N0 T7 O3 R/ O
super.buildActions();& H& {- n6 J- O. Y7 Z! i- |8 L
3 `" a6 _: A/ E9 _7 o$ e // Create the list of simulation actions. We put these in( u( f. T. Z8 M$ C6 ~7 s& f. M
// an action group, because we want these actions to be
* J% \' J4 d7 s! r; c. m# b // executed in a specific order, but these steps should9 w" w8 ^4 N: d( C- l K
// take no (simulated) time. The M(foo) means "The message6 E' r8 y3 m6 y" N( Q" n: w
// called <foo>". You can send a message To a particular
: _/ r0 v% L% |. B& ?0 N // object, or ForEach object in a collection.
! Q& o/ q, y* m- B, ^4 Q2 ~. a1 }- E ! G$ k5 O# J2 O! Q2 f5 ?
// Note we update the heatspace in two phases: first run
! ?3 A, y+ i+ X5 G) U // diffusion, then run "updateWorld" to actually enact the
! r1 J0 G1 t( `; A6 R // changes the heatbugs have made. The ordering here is
+ X/ e$ ~% i1 t- v' \* R // significant! V- G% y/ ]& P+ J! x
# l% b0 | u9 j4 k6 A& \9 v // Note also, that with the additional5 x$ t4 k9 C* M- k3 r. h
// `randomizeHeatbugUpdateOrder' Boolean flag we can
) G4 V6 {8 r% s+ N, [& { // randomize the order in which the bugs actually run8 X9 ~7 T; ]7 I, m' m: ?" V+ a, u
// their step rule. This has the effect of removing any" q7 x* l9 f& g
// systematic bias in the iteration throught the heatbug
4 r# c- K; v1 p3 a& E7 a J // list from timestep to timestep, M. ]5 |; {3 N' [% |; i
5 {2 S, j% B5 u( M$ Y o, U
// By default, all `createActionForEach' modelActions have
' y3 I% Y* Z( c( g4 N( L" k // a default order of `Sequential', which means that the% c; Y3 J& {7 a7 S% j1 a, J
// order of iteration through the `heatbugList' will be) g. j" O; p) H# b" p
// identical (assuming the list order is not changed
0 }$ w4 n# G5 @6 J# ~$ D6 J5 ^: H1 S // indirectly by some other process)., Y( D2 V( G/ @
' P1 I1 L2 `9 p6 w! a modelActions = new ActionGroupImpl (getZone ());# r! u, s: x& u
, a6 n1 j) @3 A" Q8 K9 W2 P
try {
: _( z! C1 W" d, G* m modelActions.createActionTo$message2 z% o% X- i) i# o4 N! [8 Z; j
(heat, new Selector (heat.getClass (), "stepRule", false));
( Q( f1 g2 J$ A: U% Q* }3 _ } catch (Exception e) {
* b) I+ E' t0 ^0 O9 K, b8 @ System.err.println ("Exception stepRule: " + e.getMessage ());* y7 G. F9 t- P& c( {. h" b3 k3 ]
}3 i+ w8 @1 q& _
8 w/ @/ F, H: ?( @ k( d* C9 ~% {: z try {
5 R! `8 K1 j, r+ R3 L+ T Heatbug proto = (Heatbug) heatbugList.get (0);2 v6 E& `& `" k5 L$ r% _
Selector sel = % v8 ?! \: m- A7 c7 c; _4 n; d
new Selector (proto.getClass (), "heatbugStep", false);6 N4 e! t4 X' X. }: I; @
actionForEach =0 |2 V u) m o# Y$ F( K% U. u& f
modelActions.createFActionForEachHomogeneous$call
& t! J! i; Y1 ?9 L (heatbugList,9 n" k @7 G7 @: t
new FCallImpl (this, proto, sel,
) t& {6 O2 L, c5 ]. l3 W0 B new FArgumentsImpl (this, sel)));- l- g: T4 {6 G) E
} catch (Exception e) {
: A5 |; N5 e, ?- ] e.printStackTrace (System.err);3 R- ?# J/ E# }3 p$ e
}
' K% g; k) S! C2 l: l. n
/ R8 t3 z% M# l syncUpdateOrder ();; \7 W4 f2 D2 `+ E
- A8 |3 u, y7 w2 z7 p2 [+ f
try {
F& g9 w1 Z2 }% H& l; y K4 x8 m3 j modelActions.createActionTo$message
; D4 J) Q1 k2 l9 X9 n& c (heat, new Selector (heat.getClass (), "updateLattice", false));2 O# [; C0 U7 A" R$ {. \
} catch (Exception e) {* Z1 S% ?& [& b6 b% R3 n3 W
System.err.println("Exception updateLattice: " + e.getMessage ());
# Z- |% C2 H/ {+ c- N+ n }
) e I. r3 r! Z! }; V
1 J( x$ v6 R5 b8 |; ^: s0 _ // Then we create a schedule that executes the
+ P9 O) c* Q# b // modelActions. modelActions is an ActionGroup, by itself it
6 b7 y+ t; K/ ]2 g/ j1 B. J& O5 I // has no notion of time. In order to have it executed in8 _# a* P: S! }0 ]
// time, we create a Schedule that says to use the
# S; C' J3 N# k3 l& Y$ @: `' A // modelActions ActionGroup at particular times. This" n" {. R! y: A
// schedule has a repeat interval of 1, it will loop every% q& u4 o# s! x+ L" @ J
// time step. The action is executed at time 0 relative to
1 n+ M+ a+ U8 E | R# ?) w0 W // the beginning of the loop.# r/ ?& d) n$ W3 y5 H+ U2 {7 L8 F
# d- I/ V. S0 b // This is a simple schedule, with only one action that is/ R' m* ~% _- S& c
// just repeated every time. See jmousetrap for more
; t' s. j; U4 `% Z4 B // complicated schedules.
$ q; i- a2 O. P+ l7 D! {6 _/ ]& e 5 |& X' ]7 [$ V. i! X( J. ~" F2 a
modelSchedule = new ScheduleImpl (getZone (), 1);' p9 s2 t7 ^3 `3 E, i& u% ^) ?
modelSchedule.at$createAction (0, modelActions);
3 Y4 H- a$ D" l4 U) h( | $ Y0 l0 x: S1 H5 L/ w
return this;
% d# U6 V% w9 X2 j } |