HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
1 |& l3 F4 p' e5 |
, Y7 `7 ]( M; ]. [ public Object buildActions () {% x( n9 i' F* y; l0 R6 A5 L) i
super.buildActions();
8 G0 {! c( ^( Z9 m% ~; f& { ! j' K6 t" m1 } L
// Create the list of simulation actions. We put these in
6 I. ?% T& r3 N // an action group, because we want these actions to be2 ?( x' w. h. e/ ^6 @: g" L
// executed in a specific order, but these steps should8 K: E( [* W& f& j T# r2 c7 N. U
// take no (simulated) time. The M(foo) means "The message
1 C+ A; P2 W9 j; u // called <foo>". You can send a message To a particular. w! q( \8 s& m6 k
// object, or ForEach object in a collection.
" P7 G& K7 K1 {2 V ! @! v8 H" W7 p R" x
// Note we update the heatspace in two phases: first run+ A9 S3 I, t# Q
// diffusion, then run "updateWorld" to actually enact the
# v& o& F2 g) ~( } // changes the heatbugs have made. The ordering here is
& P0 i% C" f% v4 v& }, ?7 { // significant!; L( i+ y* e2 g/ e. k! g
: Y4 n+ H* g( o# ~' p1 L5 ?
// Note also, that with the additional
# ^1 E; K+ T4 `: ?" r! a // `randomizeHeatbugUpdateOrder' Boolean flag we can0 R6 \4 l' f8 n
// randomize the order in which the bugs actually run' J _# R3 B0 D0 g
// their step rule. This has the effect of removing any
( x$ l7 y. J* ^- O8 ?: ~ // systematic bias in the iteration throught the heatbug) W: a7 y2 k9 e% f4 w \. X
// list from timestep to timestep
& Y0 X. a- N2 z7 `& i3 |+ O" `) ] : U2 v+ g {5 \ J# }
// By default, all `createActionForEach' modelActions have
; n6 W( a# }- O6 ~ ]% ^" q // a default order of `Sequential', which means that the( {- q% e f1 s6 f# [$ H
// order of iteration through the `heatbugList' will be
2 R( @# E9 ]- e$ ]! A // identical (assuming the list order is not changed
" ]: P; y! w4 j/ S2 y // indirectly by some other process).
+ ^8 f2 |+ Y# T; W& V$ x' k' c! K j
( i) ^! C' @9 t" }; P6 ?0 Y6 { modelActions = new ActionGroupImpl (getZone ());! h- c6 P7 @5 [5 A
: g) p$ O0 r' `( s
try {6 ]$ k& {/ J4 i0 D' m
modelActions.createActionTo$message0 @7 b$ b7 h5 R+ x/ B/ S
(heat, new Selector (heat.getClass (), "stepRule", false));/ @6 X. Z' t1 u# c
} catch (Exception e) {
6 f, w# |. N* B5 X$ ^2 K System.err.println ("Exception stepRule: " + e.getMessage ());
8 \/ D/ x+ l; e# v- |3 G5 Q }: ~9 x! m1 v) R# P% O
: F. x7 _" V! ^9 W7 |2 O try {
$ w5 B) A# ]/ h; y2 O$ l+ h Heatbug proto = (Heatbug) heatbugList.get (0);% f- c, [! }( b
Selector sel = " @. J- D" z' [* _7 n6 F3 i4 J
new Selector (proto.getClass (), "heatbugStep", false);6 D$ j9 t# s L: Y
actionForEach =
7 ]( b! L2 }! Q$ g) z ^: ] modelActions.createFActionForEachHomogeneous$call
, x7 R2 m; ^. W0 b6 G8 L5 ~& B( ] (heatbugList,% i T. F8 _" K2 x4 g, H
new FCallImpl (this, proto, sel,1 A ~0 U! P, v7 e- q& Q
new FArgumentsImpl (this, sel)));
; _5 a, k+ y/ v. k3 G4 t& S6 ~5 k: y } catch (Exception e) {
& H2 D! V# R1 F: d4 H* A e.printStackTrace (System.err);
1 h7 z' \' N3 m4 n( J: Z0 q0 R$ u }# F+ o* j q# y5 P1 y. s0 e
# l& E& W1 ^6 J' s syncUpdateOrder ();
7 g$ F$ A+ O! j/ S/ v. H
5 \* x7 f) w$ T1 a0 M/ I try {5 B8 |5 T% w. B1 v/ l( [/ {9 h
modelActions.createActionTo$message . t8 S- P9 E9 h p- }) q
(heat, new Selector (heat.getClass (), "updateLattice", false));
( h0 N; E" S- a" o# ~+ M } catch (Exception e) {
' I `0 }$ D$ k$ F System.err.println("Exception updateLattice: " + e.getMessage ());
) V$ ?$ \1 w( x0 g/ }& ` }
9 ~# b4 F& `3 {. ~7 D
, x" D8 F. x( H0 s0 T- L! C9 E9 w // Then we create a schedule that executes the0 F: ^% l/ S4 V
// modelActions. modelActions is an ActionGroup, by itself it
( c9 T! ]9 u4 B6 W // has no notion of time. In order to have it executed in; {4 n5 N$ A% g7 K* A
// time, we create a Schedule that says to use the4 Y" F7 m5 e3 x5 W; X
// modelActions ActionGroup at particular times. This
2 C* A$ i |8 W. Z4 r9 Z // schedule has a repeat interval of 1, it will loop every
( U3 _- J4 Y9 [5 e) w // time step. The action is executed at time 0 relative to
) D0 n; R3 v2 _# x: c // the beginning of the loop.
1 I/ g. C( ~# b' { L- t3 K* S8 V9 k8 a- j; L7 t2 u7 }
// This is a simple schedule, with only one action that is
6 J$ \ H( a2 ^: _6 g // just repeated every time. See jmousetrap for more6 n/ d# I3 S- e1 }1 |3 k
// complicated schedules.
8 L% }; }9 v. r 3 s8 y+ I: P* S3 j; t2 b
modelSchedule = new ScheduleImpl (getZone (), 1);1 P2 R3 ]$ p3 n$ D! T; i
modelSchedule.at$createAction (0, modelActions);
; v% f0 h" N% F2 |( R/ u - v- K P1 Y5 b" s6 s2 M! V) o Q
return this;5 n. Y' W& z- p& V& Y& v
} |