HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
7 W. x1 z" |$ D& s- q/ Y$ x
2 { s: C! R- e8 w! x7 l9 | public Object buildActions () {0 l+ C* [* e6 k/ \! @8 N
super.buildActions();) Z8 v N" W* u# E% p5 _3 W3 W
6 J7 x* M$ X* o* O // Create the list of simulation actions. We put these in
3 z5 B, _' y' d // an action group, because we want these actions to be
" p) e$ o, [9 {& D( m- }/ `: W // executed in a specific order, but these steps should/ p+ c$ s: G# \1 y2 H' K2 ^
// take no (simulated) time. The M(foo) means "The message
?8 o; A N4 \0 y // called <foo>". You can send a message To a particular% u% i& e- e. E- {; M7 G
// object, or ForEach object in a collection.& ~7 E! j% T, P, B
; `- z( C' v: g2 p // Note we update the heatspace in two phases: first run( e) }. {/ `" E( L7 w
// diffusion, then run "updateWorld" to actually enact the
' A2 Y, t B, y/ H, k' m- y+ a // changes the heatbugs have made. The ordering here is0 E+ a5 T, L& @
// significant!
( F% _; n+ p( i! E& A* r2 U/ t
^1 Q: {" O& o // Note also, that with the additional
) g$ _; \, J$ S // `randomizeHeatbugUpdateOrder' Boolean flag we can
& y) [- {& t( q' J9 k // randomize the order in which the bugs actually run
$ V9 G* }- G5 U: M // their step rule. This has the effect of removing any
: D4 b0 X# q5 g // systematic bias in the iteration throught the heatbug- W& W- x/ |) @5 N
// list from timestep to timestep* e: e0 m" {. a0 R
' a& n- ~ E& C$ t1 D5 }8 L" `5 Y/ O // By default, all `createActionForEach' modelActions have
+ d$ I: B: V" N* E- T // a default order of `Sequential', which means that the
8 z) l: U1 s3 J // order of iteration through the `heatbugList' will be
5 R* Q& r4 s8 t // identical (assuming the list order is not changed( h% t+ c3 F' E3 K0 s: q
// indirectly by some other process).
5 S4 H* @9 W; J$ @ y " t; D& N* S" l j+ W
modelActions = new ActionGroupImpl (getZone ());" G* F: E& [& ` U o0 J" X: L% C7 T
% h9 z8 P. |4 g1 R try {( K r# O( N1 X* I( ~: Z
modelActions.createActionTo$message
% c- v( X1 E9 B: Z5 S. P* l$ l6 x (heat, new Selector (heat.getClass (), "stepRule", false));
6 l) q* R1 t2 V# q _ b. m } catch (Exception e) {
# z# |# j# m4 n0 }. f+ B' y/ b System.err.println ("Exception stepRule: " + e.getMessage ());
$ i1 g# A, E( i/ r$ `) ^ }) s! f4 ~/ }8 V# l0 X
- K, t1 _/ Y- V( X' O: o: Q9 j try {7 D+ n" \7 \$ }6 ~
Heatbug proto = (Heatbug) heatbugList.get (0);3 K% v& o* d9 u$ `( V
Selector sel =
" c7 N, B, J( G% _2 S new Selector (proto.getClass (), "heatbugStep", false);; g, r* ] b+ L3 ^/ F# }
actionForEach =
8 f6 K8 T# D5 Q modelActions.createFActionForEachHomogeneous$call
" n3 ?0 G6 j% Y9 d+ z$ ~% b' G (heatbugList,
^% ?: s: s* i# d6 z3 o+ A% w% u new FCallImpl (this, proto, sel,, G+ A- i% ?0 l u1 o1 k
new FArgumentsImpl (this, sel)));9 P1 o! G1 K1 n" u7 \ {4 k# D; w
} catch (Exception e) {
6 [/ S/ |6 F4 `( C5 R$ K! \ e.printStackTrace (System.err);
$ C; _$ G3 z0 H$ ?: ^' C6 ` }) O' H. O) h$ ~. z1 `3 z
, m- X$ R/ P" ^ syncUpdateOrder ();5 g. W' L: d& t) w
& ^* z& y- N9 I8 {8 ]
try {2 {+ X+ ?( {, g
modelActions.createActionTo$message $ Z; H1 m# L6 C' _
(heat, new Selector (heat.getClass (), "updateLattice", false)); r+ J1 E; G" A4 @7 c; U. K& N
} catch (Exception e) {
8 j( J' z$ I: ?- R4 o. S4 l System.err.println("Exception updateLattice: " + e.getMessage ());
+ n5 c/ f% c6 y- h/ ^) j% X } Z0 v5 M; Z" ?' W0 n
" Z0 N" x! { L8 n2 E" `: G! V$ X- \ // Then we create a schedule that executes the" h* o# u4 v0 o; i5 r
// modelActions. modelActions is an ActionGroup, by itself it
# V$ f, U3 {- l // has no notion of time. In order to have it executed in
2 S+ k: S- B3 y! `/ I // time, we create a Schedule that says to use the
$ C( x2 M* @+ s. Z1 C // modelActions ActionGroup at particular times. This7 p9 J& l$ G, D$ |
// schedule has a repeat interval of 1, it will loop every% G/ l, i5 [( W1 T7 N
// time step. The action is executed at time 0 relative to
3 z7 b6 }6 x2 x! A% \ // the beginning of the loop.$ r) X' {3 t6 b) l
: ~& j+ W5 L% B4 ~
// This is a simple schedule, with only one action that is
0 }& r- g9 _/ g3 q0 b( ` // just repeated every time. See jmousetrap for more
( J, D$ u( l6 M+ y! i // complicated schedules.
7 e! n) f g; m+ r . X7 p+ T1 Y: k7 b, {5 i3 N* v$ C
modelSchedule = new ScheduleImpl (getZone (), 1);* Q2 w8 p; P& r8 r: W
modelSchedule.at$createAction (0, modelActions);1 u1 w( h7 l$ h' F
. m# `* q+ C9 I return this;, O7 M. {; |# H% y: |
} |