HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
9 b/ P+ `7 t8 G/ [! x5 ^; [3 u- X% g
8 G+ ~! {# T' C( Z! P public Object buildActions () {
+ |' T' z, x- K% U8 R: c5 A super.buildActions();
, ]' N+ Q2 T3 x; l3 w* I$ A
# t6 B2 o p* A' X // Create the list of simulation actions. We put these in
( K2 N, q1 }/ Y // an action group, because we want these actions to be
& i) P# D' c6 l! d3 v9 K* u1 Q // executed in a specific order, but these steps should$ d/ {( e A) R X* U
// take no (simulated) time. The M(foo) means "The message
4 H0 D6 H& d: x. p$ ~ // called <foo>". You can send a message To a particular
& d* L6 n3 {0 u( N // object, or ForEach object in a collection.: Y/ k. B4 P m; W
r+ @/ B/ H3 ^+ m6 ^
// Note we update the heatspace in two phases: first run) ?# d" a/ L2 c) ]+ e7 @) r
// diffusion, then run "updateWorld" to actually enact the" F$ t( q& t. @6 @
// changes the heatbugs have made. The ordering here is
. ]1 J, s. g" } // significant!( g! r" s+ Q [
- q5 {3 z2 y6 G- o
// Note also, that with the additional4 J9 R2 @* a$ c+ S( `" ~
// `randomizeHeatbugUpdateOrder' Boolean flag we can
# j1 X( J1 R/ z2 d+ {3 f) B+ U // randomize the order in which the bugs actually run4 d7 I, a7 s+ Q2 W
// their step rule. This has the effect of removing any) z' l" [" M% ?5 l
// systematic bias in the iteration throught the heatbug
/ @' q5 |" U( u1 C& m6 y // list from timestep to timestep; h/ ~$ I0 a. r( P
2 O0 _# i6 X# Q' p6 D
// By default, all `createActionForEach' modelActions have7 x# r& O' `3 A2 I; _
// a default order of `Sequential', which means that the
4 e, w6 y1 O6 T; ^' H% S9 U // order of iteration through the `heatbugList' will be Z& l K% t' ]! O5 G
// identical (assuming the list order is not changed
, R- o! l( _0 L/ a" U; e- a // indirectly by some other process).' [& `0 O7 Y$ y8 e2 h! L
9 Y! m2 r- l' ^! e0 k; `' P! }6 J
modelActions = new ActionGroupImpl (getZone ());! C; o9 O4 f+ |" L7 M
3 m5 D0 X/ |$ O) k
try {
7 F3 Z f/ a- P5 P& [6 H modelActions.createActionTo$message
' |$ b2 h3 w0 a) w+ G! X* ]: }% F (heat, new Selector (heat.getClass (), "stepRule", false));
/ y: W; M5 d8 A1 [% }9 K% B: S& K } catch (Exception e) {! a& G2 ~. T5 ]- [0 s0 Q% \* _
System.err.println ("Exception stepRule: " + e.getMessage ());9 d' a$ D0 J# p( z
}
$ f* E9 _4 j, @* c" n2 w S/ v
/ p% S: o; b- U2 ~ j/ f/ J try {
2 y" h& E d; G1 x- u, y Heatbug proto = (Heatbug) heatbugList.get (0);
* i9 v1 G0 a) ~' a: ~3 s0 ? Selector sel =
/ ~, ^- N$ {, P) [' r @ new Selector (proto.getClass (), "heatbugStep", false);& e) C" w8 q5 l5 ~5 l1 [8 v
actionForEach =
' V1 c4 Q- X) W f$ O9 c/ V1 r modelActions.createFActionForEachHomogeneous$call
6 t' o( E1 \# E6 |/ k4 J+ h, \ (heatbugList,
9 R% \$ X% {& W4 X4 c new FCallImpl (this, proto, sel,
8 x4 t! @. T0 Q, r1 Z. B) o/ S! A p new FArgumentsImpl (this, sel)));
' ]( f- E8 e/ V o$ o- j } catch (Exception e) {, {- z9 o: q! y. v
e.printStackTrace (System.err);0 w4 Y2 I/ S' i7 e& O
}9 }# V9 B$ B+ M0 @+ [
r1 j @8 B: y5 X; V" q2 n8 m8 L H
syncUpdateOrder ();
- N! [0 [# t( `! ~1 R3 V1 f7 v
9 b T7 V5 N, @7 K- W2 [1 z l try {& e" ~4 w: W: W5 k" q+ k
modelActions.createActionTo$message . K1 U3 d# Z( h( O
(heat, new Selector (heat.getClass (), "updateLattice", false));3 E7 U, C/ ]9 h, F |" x( {% |
} catch (Exception e) {
1 x3 N) \3 E: R2 J# E System.err.println("Exception updateLattice: " + e.getMessage ());
" X; {9 B. P; l) @' d% L1 u# Z4 N }
$ G$ D5 S5 z6 n/ L/ p! Y2 e
0 F! b4 `# w$ r! B2 ?& w+ ^4 ^, Q // Then we create a schedule that executes the5 h( W( t5 H( E/ W
// modelActions. modelActions is an ActionGroup, by itself it
- Z. s0 Z7 o6 H+ z // has no notion of time. In order to have it executed in% N% |* i7 h: t% ]3 N! H/ F. p
// time, we create a Schedule that says to use the l$ Q% c; b) d1 g$ |
// modelActions ActionGroup at particular times. This: [8 l( f: b( Q( q! Z
// schedule has a repeat interval of 1, it will loop every
8 j$ P& _4 Y% W4 E2 I // time step. The action is executed at time 0 relative to2 P" x2 k7 N! V8 j% M9 R4 r& h
// the beginning of the loop.: ^3 ^: b+ i+ x' e
# ?) Y K0 L- h& R, P7 W; _* } // This is a simple schedule, with only one action that is
4 ^$ H9 X% K) g8 z0 j2 [- U+ B3 N // just repeated every time. See jmousetrap for more
6 q0 o7 o) o1 q& M // complicated schedules.5 I4 V+ C1 E4 F, c4 r5 F
7 K& A$ W/ V: n) p+ H# c* A
modelSchedule = new ScheduleImpl (getZone (), 1);5 Q! l" ^1 y2 ~5 J; B
modelSchedule.at$createAction (0, modelActions);& m1 b5 j. i3 P o2 X% x
) Q8 I. ~: C9 [0 [! [
return this;, v6 {9 d& |! B+ V
} |