HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
+ }4 `) u% \0 H# c/ X3 ? ^& ~7 o7 B
public Object buildActions () {- X1 z# x9 } X5 G
super.buildActions();$ K- I& J. u) L: n
) y e; T, a3 a) C% I( s
// Create the list of simulation actions. We put these in
$ w; u5 H+ Y' L // an action group, because we want these actions to be: v( b0 S/ T2 O" q. B9 E8 l
// executed in a specific order, but these steps should
. K4 F I' g+ M+ b6 A6 I // take no (simulated) time. The M(foo) means "The message# D) d0 |, z5 |; L1 Q1 c
// called <foo>". You can send a message To a particular. L4 F2 k# |" Q6 b8 w6 u
// object, or ForEach object in a collection.( Q% H2 N! L6 T
) ^% z9 E2 l4 |! m# y
// Note we update the heatspace in two phases: first run. w0 @& z( r' q- D+ _
// diffusion, then run "updateWorld" to actually enact the
- h" a5 s' _8 w2 Y // changes the heatbugs have made. The ordering here is& E3 v( g. b; n' P: e7 f- K
// significant!# M- Y5 W* u# e! x, O' _) c
% N, u4 @% T* g7 K; [ // Note also, that with the additional
" b9 Z! k. H# H& B8 i3 a6 O1 q& p // `randomizeHeatbugUpdateOrder' Boolean flag we can+ M5 U# Q3 A8 ^' H. u9 A
// randomize the order in which the bugs actually run
3 O0 ]4 o3 ~9 I/ T3 | // their step rule. This has the effect of removing any6 K, F3 r3 c0 {! ]( b
// systematic bias in the iteration throught the heatbug: v3 z! ~ u1 R9 d6 }
// list from timestep to timestep
; k( l, F& u9 ^/ D5 u7 q) I0 ? 1 o7 P: U% t# \. q
// By default, all `createActionForEach' modelActions have3 d& `# r" v4 [- x8 A5 Z2 p( P5 r
// a default order of `Sequential', which means that the
8 C& i- a& N! ] // order of iteration through the `heatbugList' will be1 c& v# o+ j* S9 m
// identical (assuming the list order is not changed
# e3 Q% s- [" V- w // indirectly by some other process).
9 v% F1 {6 L0 q' k: F& Q
?7 x4 R/ e* K- P9 H modelActions = new ActionGroupImpl (getZone ());! e z1 R; [1 B8 F& w
, ~5 s8 C; n7 U2 S try {
6 h2 } \; y, ]3 @ modelActions.createActionTo$message. }+ J) x# j' T! j3 Q0 u
(heat, new Selector (heat.getClass (), "stepRule", false));. A* W a3 Y* K" ?9 [# @
} catch (Exception e) {& c, h( f+ G5 q
System.err.println ("Exception stepRule: " + e.getMessage ());
+ ?# @: f6 I) c4 t% g# M H6 S }1 {, _5 A5 G% x; n
t: r( L5 m; M" q, Z0 [" M% {
try {' [- {. t0 b2 v( ]
Heatbug proto = (Heatbug) heatbugList.get (0);# ^3 b, k% M$ i8 x
Selector sel = 6 K, s3 `+ j- h4 w, Z& z
new Selector (proto.getClass (), "heatbugStep", false);' F4 B# Z0 @$ y" C1 g# I$ {
actionForEach =& z4 i; L8 I0 r w6 C \
modelActions.createFActionForEachHomogeneous$call
: _% |) i+ }* q; b/ E3 }! ?7 \ (heatbugList,
+ e2 K, F t- l: f* S new FCallImpl (this, proto, sel,+ Z9 H' L; A$ Y
new FArgumentsImpl (this, sel)));
! ]8 Z1 [' i# ] } catch (Exception e) {8 a6 Y% q" ~+ z2 B i- E
e.printStackTrace (System.err);
/ ~6 B. I7 k, L: a8 g4 d! m }% I$ O- }- k5 g+ W6 x Z
. D( C8 |+ H, Z. G8 Q
syncUpdateOrder ();
. r' R# K+ d3 X9 w" F) j: v
$ y7 a$ A6 h7 f R' t( [ try {: J- f2 a) S0 |; }1 i
modelActions.createActionTo$message 5 z/ L! Y& x3 U+ v% e
(heat, new Selector (heat.getClass (), "updateLattice", false));3 V0 b- E+ \# e
} catch (Exception e) {$ Z3 V7 v3 J" C! M+ w$ K; a
System.err.println("Exception updateLattice: " + e.getMessage ());
( u x& Q' B6 I" I8 d2 h* U }" T: Q) p+ e- d0 B; P
) E' `% m2 L. ]2 z* c& |
// Then we create a schedule that executes the# j8 z: f/ Y( F$ y, N% G. w
// modelActions. modelActions is an ActionGroup, by itself it
+ R; E+ a9 o9 _% f7 [ t- z# Z. @ // has no notion of time. In order to have it executed in# K5 B B, {3 ]8 a+ A2 x
// time, we create a Schedule that says to use the
{2 ^/ f7 c4 H1 E2 [+ F // modelActions ActionGroup at particular times. This T! g! J' v* M p# I
// schedule has a repeat interval of 1, it will loop every
& {& T5 h+ x5 K // time step. The action is executed at time 0 relative to0 O2 n( O P* F+ R$ ^
// the beginning of the loop.3 }# v8 N4 J) V' U7 o3 ]% e4 s
8 B# H& h) A1 r+ X
// This is a simple schedule, with only one action that is
$ I7 O/ k" _; p! e // just repeated every time. See jmousetrap for more
4 I4 |* K- b1 C1 b // complicated schedules.
# ]7 T& S: n( {3 A( u3 d% i/ b$ @) f( z3 T
7 e) f- I- T3 b5 c: R: C modelSchedule = new ScheduleImpl (getZone (), 1);2 P0 F# c1 V* ]- t
modelSchedule.at$createAction (0, modelActions);
4 {+ T1 |+ @; d* z; n! X/ [
0 _2 E: b# T& K* d/ m- P return this;
# s9 c8 ^! H" U9 N2 n } |