HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
. D: P3 g5 y# E3 L& f0 Z' Z; ^$ P$ ^- V8 G; i$ _
public Object buildActions () {. w6 f' x. z( N$ v" k5 \
super.buildActions();9 f( _3 H4 e) J# D
( g4 ?0 q* B o9 t" B* W6 T // Create the list of simulation actions. We put these in1 O! T% ^. Q6 w7 @
// an action group, because we want these actions to be. d. T6 ?. X8 ?( d& n
// executed in a specific order, but these steps should
! a9 u. d7 h0 e. G) n# e! q // take no (simulated) time. The M(foo) means "The message% k% q- C* I4 z Y5 v# c+ ]* h
// called <foo>". You can send a message To a particular
! {2 D) W: A9 X# S+ d/ q/ W% S // object, or ForEach object in a collection.
3 M5 l* I% M2 F' z$ Q0 C. J, x$ o : j3 X% A, j$ d/ Z- @+ X% \1 a" z0 A1 i
// Note we update the heatspace in two phases: first run+ L* c6 i' \( A
// diffusion, then run "updateWorld" to actually enact the. |7 J& T2 t7 }& v, U; o
// changes the heatbugs have made. The ordering here is! X3 s; @. @8 D4 `! P" y
// significant!
% j. O& j" U; w+ P0 Y! S ! N5 Y& N2 w9 f7 A
// Note also, that with the additional. O8 l9 B6 x6 N$ P, I2 l& e' Z, X
// `randomizeHeatbugUpdateOrder' Boolean flag we can- D! g% K) M4 e" n* t0 j
// randomize the order in which the bugs actually run
, f/ q, r R* Z3 h: r# D M: r // their step rule. This has the effect of removing any
6 j) @1 |9 n) G( _1 P1 N8 E // systematic bias in the iteration throught the heatbug, q @2 G6 e% @/ `# ]% A
// list from timestep to timestep7 ^! m. @# N5 X/ `5 I& H' B+ C
% L/ [# W) b1 i
// By default, all `createActionForEach' modelActions have3 Y0 v: ]: i, Y! X6 e5 y+ i
// a default order of `Sequential', which means that the
$ s- l/ `0 I* [. k! g, E- a6 L // order of iteration through the `heatbugList' will be# {. d# K5 N$ }7 E+ n& N- K
// identical (assuming the list order is not changed
, U6 Z! H) \5 S. H8 z& g' @( u // indirectly by some other process).
' A+ L- n* g1 S4 I 0 R5 r# U# ~. C4 y, u# D! G( @& B" f
modelActions = new ActionGroupImpl (getZone ());
; [4 L" {% m; e6 C4 r! t; H, { |- M2 n% M4 @$ S0 R9 ?
try {
/ K, M/ ]6 X \; i- X modelActions.createActionTo$message
3 @% B1 d# ^# Y, ]# D9 y (heat, new Selector (heat.getClass (), "stepRule", false));( L, l$ i- w) p3 J
} catch (Exception e) {
& e7 ], ]* V. l: c" O! C System.err.println ("Exception stepRule: " + e.getMessage ());
5 i' j) u3 z4 i4 u }
& k; \* |1 S$ h. O& Y' U7 G9 H6 A4 `6 T4 [. e% y
try {, r' ?9 O, B- s* V* K- D# n _
Heatbug proto = (Heatbug) heatbugList.get (0);
" A; h6 b8 D6 i( M% a0 S* j# e Selector sel =
$ J! s, J, I- j; @ new Selector (proto.getClass (), "heatbugStep", false);2 l+ A5 |' l# W
actionForEach = [4 N* O! m! ?; Z
modelActions.createFActionForEachHomogeneous$call
0 |" d1 k% B7 H7 F8 ^3 ?0 r% c! u (heatbugList,
3 Z( u- N' H* B6 P$ Z8 Z new FCallImpl (this, proto, sel,
8 G7 q* Y' x; m9 f' l: k6 p new FArgumentsImpl (this, sel)));
3 W- y1 Y% K7 F* ]$ k/ P } catch (Exception e) {4 H. C6 z0 b6 f" K; f/ B
e.printStackTrace (System.err);, X2 Y" Q& U6 k0 u; q
}+ i! V! A$ a1 ~2 D9 `' b2 z
7 `& c- i' q1 ~; b8 D6 X8 A syncUpdateOrder ();7 a- i$ M' {+ x [0 W2 i% F/ w
1 k! u0 ?4 Q) `) G
try {9 h7 p0 Z& l X
modelActions.createActionTo$message % ^" ~4 j! Z6 H) X1 g, c
(heat, new Selector (heat.getClass (), "updateLattice", false));( V: G. o C" l7 P [5 O/ |
} catch (Exception e) {$ ?; L8 f+ o; G, c/ R, f" Z
System.err.println("Exception updateLattice: " + e.getMessage ());) _ \8 g6 r# @1 ?8 B
}* A/ s3 [! [: e
, p* N5 n$ c: b8 p/ l
// Then we create a schedule that executes the/ h5 ]# Q: z, a; R
// modelActions. modelActions is an ActionGroup, by itself it
5 l+ J( G, I0 M1 O! `. w6 l // has no notion of time. In order to have it executed in$ o* B3 C: f% T
// time, we create a Schedule that says to use the
; h( z6 O$ h0 z( G u // modelActions ActionGroup at particular times. This
& s' a) ?, e5 P# ?& Y // schedule has a repeat interval of 1, it will loop every
) I X' p) Y! a% u // time step. The action is executed at time 0 relative to! j! Q$ n$ B( p, r
// the beginning of the loop.
4 f# w) h! Z8 P( f }; O+ e+ b! ]6 ~/ U
// This is a simple schedule, with only one action that is
* T8 t' O+ Y. a8 R7 J% d- V: F // just repeated every time. See jmousetrap for more5 x. M4 S& i% O2 `/ d
// complicated schedules.
2 s5 _1 i& b* p3 m3 }9 W ( Q( ?) U }, z- h' M+ n
modelSchedule = new ScheduleImpl (getZone (), 1);
; O( Q1 A5 @9 W+ j* v modelSchedule.at$createAction (0, modelActions);
; a9 [ M( z9 i& F7 A" n2 v
$ B# a0 g$ C# Y0 t% A return this;( Q7 F2 R& F& A, B8 t
} |