HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
( @" B* i: l' a8 c6 F8 T6 c
$ z* i2 u& H( H8 S- J- i public Object buildActions () {
' l2 j q r3 L; O% U+ w$ I super.buildActions();3 X; v; v! C& |7 U7 P Y R
( w7 o, t7 E: ]$ M" e
// Create the list of simulation actions. We put these in3 I9 C! e: N3 c
// an action group, because we want these actions to be
/ K& b A! s/ F" R/ C/ R9 y // executed in a specific order, but these steps should- s2 X" e) H6 u" C& g- u: j
// take no (simulated) time. The M(foo) means "The message( S/ _- f3 a1 H! @7 \
// called <foo>". You can send a message To a particular+ a$ R% W- O5 V) g' `/ O( E& `2 I
// object, or ForEach object in a collection." j, ?% D& e: R& g
; ^2 \7 O4 e2 A1 d6 e0 Q2 O0 M // Note we update the heatspace in two phases: first run/ T. B$ V. L6 |. Q; V. c
// diffusion, then run "updateWorld" to actually enact the
8 q5 Y' T8 r. \4 ]8 h$ ^8 ~ // changes the heatbugs have made. The ordering here is
' ^' e2 j1 o! k( F/ { // significant!
- j1 d7 [" x4 i2 Z& y' d9 U
0 [0 G ]; L! w4 d# o9 s' c // Note also, that with the additional
/ Q9 Y6 x1 B/ Z: j // `randomizeHeatbugUpdateOrder' Boolean flag we can
# \ ^7 t+ a1 e5 z' C // randomize the order in which the bugs actually run6 |; E9 q8 h) w: l) |! E$ c, X
// their step rule. This has the effect of removing any5 x7 m' W0 s; o, A! r/ L1 A. R q
// systematic bias in the iteration throught the heatbug
, u" J3 ?* z4 {% @ @, \ // list from timestep to timestep
* L1 m5 J. Q( ~7 i- W% _ ' a, h# ^+ |9 @% q4 K
// By default, all `createActionForEach' modelActions have8 R( \6 L+ m+ A: _3 b F6 `
// a default order of `Sequential', which means that the
+ f- a: ]9 d9 Y // order of iteration through the `heatbugList' will be0 |# Y8 g: J# ] S1 K
// identical (assuming the list order is not changed7 F+ V! f6 _) ~
// indirectly by some other process)., I" E1 H4 _. ~
% j2 \. C4 D* Z$ N. J s
modelActions = new ActionGroupImpl (getZone ());8 T% z- J4 M0 @! Q0 ^6 j9 o
[( p5 z( D8 C% Z9 F try {- x) y: i2 I' u3 N0 G5 j
modelActions.createActionTo$message. B' U4 \6 G* F6 z6 H0 [
(heat, new Selector (heat.getClass (), "stepRule", false)); |. Q: V, P% ]1 j8 F
} catch (Exception e) {) o$ n+ \. ]' |: i% t+ w% {
System.err.println ("Exception stepRule: " + e.getMessage ());- O' B2 ^5 V j, q: Y
}% R* S5 ?# G6 m3 f1 G) ?6 a
5 D- J. Y. ]9 D. P* F* w* n7 N. j
try {
, M& J9 y3 a3 ^) G" D3 q! g Heatbug proto = (Heatbug) heatbugList.get (0);
5 A) s8 L- Z( b j* @ Selector sel = ' [$ J# `7 ?6 m# I" s8 e1 S
new Selector (proto.getClass (), "heatbugStep", false);9 S0 e+ \; I$ o4 G& L, x9 N( o ?- U6 Y
actionForEach =
. ^ l, B! h! E: X# |/ m5 z" ] modelActions.createFActionForEachHomogeneous$call- H" T2 u+ K1 ~( [
(heatbugList,
5 h6 I6 n- l1 Q* A2 Q1 U' P new FCallImpl (this, proto, sel,' i8 l+ U4 U- K% s" M
new FArgumentsImpl (this, sel)));/ [. O$ U( q& B; {/ E U6 }( a
} catch (Exception e) {5 V: g. ?: ~0 ?2 x3 D) Q
e.printStackTrace (System.err);
5 n' {0 o) r! H1 x }9 D3 L' D. I4 O+ x# k
' I6 c9 q: N; a6 ~1 H
syncUpdateOrder ();* K8 y0 x- t5 l7 \# ]0 q
. g0 z1 \2 e, |" o/ T try {
" F. M. F1 j9 ]& V+ n( e$ u { modelActions.createActionTo$message
7 V# \$ \5 i; d: d (heat, new Selector (heat.getClass (), "updateLattice", false));
, W/ L/ n: M2 Q- \3 P# D$ h } catch (Exception e) {
2 G6 T2 A5 e' A6 X6 }4 P8 ^7 \ System.err.println("Exception updateLattice: " + e.getMessage ());
5 }+ R/ r: O: F1 v }
% _$ S& Z' q6 e( Q# _2 f
' a% x8 U1 E, d2 @ // Then we create a schedule that executes the: x2 B3 E. u0 i* k {! C
// modelActions. modelActions is an ActionGroup, by itself it: B* O9 B' V( t/ i- j
// has no notion of time. In order to have it executed in* {0 x7 [- z5 C
// time, we create a Schedule that says to use the
. L% j/ |( {1 q+ T7 P( d% N" g // modelActions ActionGroup at particular times. This3 ~0 T* ]3 J2 w4 k M& [
// schedule has a repeat interval of 1, it will loop every
9 L; M* n1 k% J. R // time step. The action is executed at time 0 relative to
% r+ ~0 U& p9 Q" a8 E, f% l // the beginning of the loop.7 Z/ j J2 d4 T2 V
" O: p e& v1 ?2 Z! @+ }$ h& d) Y# i
// This is a simple schedule, with only one action that is
O: j5 I7 x9 J# B4 F1 H // just repeated every time. See jmousetrap for more
* ` E! F& C- W1 s! S0 T& x // complicated schedules.8 _1 `# d8 Z* @9 N
8 I% K# {2 W, b/ M# S6 Q* I/ e: E modelSchedule = new ScheduleImpl (getZone (), 1);! Q, k& c4 m% { e, c N! H- m
modelSchedule.at$createAction (0, modelActions);
2 l" C6 N( m+ R5 G5 l! L
. u9 \; n: n! ~9 R return this;
8 V! C& P1 f9 F n7 e } |