HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
3 }; D4 i8 |5 H+ ] M, K7 K: y p8 G* G% {! [( W' J) x
public Object buildActions () {2 M8 p" V; ]7 u) O
super.buildActions();
! N0 A7 ]( a8 K7 M
! ?! P8 y+ @3 a9 k5 O: o // Create the list of simulation actions. We put these in* @& i# [5 W0 a: D+ R/ ?
// an action group, because we want these actions to be" t$ V% m, R' d6 \
// executed in a specific order, but these steps should
6 L/ N& e" Z) B1 E: c# \ // take no (simulated) time. The M(foo) means "The message
' H# p, J6 M8 E3 j. \ // called <foo>". You can send a message To a particular
! R8 E# N- u! n; e. o0 h0 W" K0 ^ // object, or ForEach object in a collection.
b: @% T- O, S/ O! z, S & A$ ~# w5 y+ Q N- Z
// Note we update the heatspace in two phases: first run* u3 \& K( ]1 O
// diffusion, then run "updateWorld" to actually enact the
" C$ K5 ~6 s& d9 G$ q // changes the heatbugs have made. The ordering here is4 N' ~. o4 |, q3 R( m5 |
// significant!
5 S5 G6 L$ v0 l) n / L( K' l5 J) u% Z/ U
// Note also, that with the additional8 A8 G- F6 m4 \% k. q3 Z- Y
// `randomizeHeatbugUpdateOrder' Boolean flag we can; t. Q5 P3 N5 B/ z5 Q2 k, } ?
// randomize the order in which the bugs actually run
' r* t" n/ l" y. i // their step rule. This has the effect of removing any
' O/ M. m1 ^" a3 v0 F // systematic bias in the iteration throught the heatbug$ F. K+ L" q1 T1 X, a4 S" o" \ k
// list from timestep to timestep8 P: H; \' \, C2 z! }
g+ o( u. U, d7 o3 G ? // By default, all `createActionForEach' modelActions have) W4 t/ }+ L7 V$ H' s" I9 U% C
// a default order of `Sequential', which means that the
8 g; W5 q* r' B4 N* c% b, i s // order of iteration through the `heatbugList' will be
4 Y1 b ~. m" q9 W" z // identical (assuming the list order is not changed( N, k0 m" q6 D, Y$ X' W7 X* b
// indirectly by some other process).
3 B/ L& Q/ s' c5 N. S7 W % o( _1 p' z/ \; J! g! M" I
modelActions = new ActionGroupImpl (getZone ());; L8 n! V( Q: g2 W9 M6 y
9 B+ H. N0 g6 _) s) b- | try {& E) S8 K: A- Q) U8 U, q
modelActions.createActionTo$message
8 f( }: U: t! f: c8 {. y- t (heat, new Selector (heat.getClass (), "stepRule", false));
: I7 D! r) w5 R9 l8 O } catch (Exception e) {
2 p5 ~3 g o X, [8 ~8 k% K0 f& X System.err.println ("Exception stepRule: " + e.getMessage ());
5 _# K* V) o$ L. P$ a }
* `$ P8 }& J8 w" H0 T& }$ T) M, @9 A( b' m
try {5 x: R! t4 t, p! z
Heatbug proto = (Heatbug) heatbugList.get (0);
0 }2 e7 i& J- H8 n5 M6 f% w$ u- D, \ Selector sel = % X, j; l2 _ d5 q" Z' x
new Selector (proto.getClass (), "heatbugStep", false);
$ i0 |3 e4 @8 n% B- B' L) u. k" f actionForEach =+ z% ?: T1 F- t8 n1 {, N, W4 c8 f
modelActions.createFActionForEachHomogeneous$call) p2 x- q# K1 Y- T8 [
(heatbugList,9 i$ f" q+ h& O( @0 z$ C+ k
new FCallImpl (this, proto, sel,* t9 d% U, C$ C6 B
new FArgumentsImpl (this, sel)));
' F: G" n8 K1 H) E } catch (Exception e) {
: d+ ?& A* j$ E0 c- X e.printStackTrace (System.err);+ T8 D- I- r, w) j+ D. C
}
) u; o5 T6 X5 F6 p0 ] 9 Z, f0 Y: {- T$ Q( k6 K- g
syncUpdateOrder ();
# s" a' t7 U* g5 R X; R
0 ^- C& Z$ M) S6 B try {/ a5 h9 z0 c. B# M# Y' L+ |% p
modelActions.createActionTo$message / `$ |9 G9 O, e4 q- {
(heat, new Selector (heat.getClass (), "updateLattice", false));; @6 `5 y1 R! P1 c0 Q3 e v( ?' o
} catch (Exception e) {# d9 H3 I, n g6 D
System.err.println("Exception updateLattice: " + e.getMessage ());
/ o8 f1 }3 l0 r/ W! E9 @- G: d }1 g+ O4 K0 d3 X5 x
" u( j2 Q0 l! d" u# b: b // Then we create a schedule that executes the; P& Z$ U6 s2 B
// modelActions. modelActions is an ActionGroup, by itself it
# H& \% u0 p% {8 p7 _! S9 W // has no notion of time. In order to have it executed in! G$ h: X" Z4 z, ^7 M% Q9 K
// time, we create a Schedule that says to use the
, p$ D. V: @/ p! C$ v // modelActions ActionGroup at particular times. This7 \* ^4 j2 E/ t$ [$ Q3 V- k9 }
// schedule has a repeat interval of 1, it will loop every
+ T% n8 Q+ l. a X // time step. The action is executed at time 0 relative to* m- x; `9 Y3 s5 N, q
// the beginning of the loop.( @; M$ ?- Y1 l) E2 T
8 Z4 m6 C8 H. H: n/ b
// This is a simple schedule, with only one action that is& e# o0 J) j: C! ~) ^, g- P
// just repeated every time. See jmousetrap for more
4 e$ P* J7 L' l. k* h* H7 J // complicated schedules.
% E2 {, U7 U+ I2 c 6 D" X/ u5 ] D5 ]' b" f$ [
modelSchedule = new ScheduleImpl (getZone (), 1);- n% M* h4 r) d# @) u
modelSchedule.at$createAction (0, modelActions);$ Y2 r0 m$ a" V; K3 J- \% F+ }* ?
& u8 u. t( N C' N$ T3 c
return this;+ s: |* q0 B5 h3 n" J+ y7 D
} |