HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:. W% H8 t5 N: u7 ?
1 F m1 V& d& q9 o( ^7 S
public Object buildActions () {
) |4 Q- t: A9 B0 M2 V super.buildActions();
0 E! e- J# S! w1 n8 ^/ q - e, e" c4 ?0 E7 @# {5 u
// Create the list of simulation actions. We put these in0 D) U) s3 g5 z, {) X- u
// an action group, because we want these actions to be7 c# J' O% }! `, \$ v, D7 P* ~% A
// executed in a specific order, but these steps should/ A3 [+ K$ @; R1 Z( s
// take no (simulated) time. The M(foo) means "The message" Q/ ^2 e7 _ p V
// called <foo>". You can send a message To a particular& O5 g3 n' o3 m# |1 R$ B) ^
// object, or ForEach object in a collection.
; Y5 {) _# v( _) f
& ]& D t9 c. ~: V$ Z7 z // Note we update the heatspace in two phases: first run
- u- D7 I. y; H3 V' E // diffusion, then run "updateWorld" to actually enact the
$ D& x/ X/ w, ]" ~: q0 a6 P // changes the heatbugs have made. The ordering here is
% e& n3 ^+ M( l0 r; D# l1 ]; a // significant!
; q K( C6 Q- D8 C$ @8 w4 i & u; B; y- B, b5 l9 q$ Y$ L3 d
// Note also, that with the additional
/ y6 c- P0 P2 M6 q( P& T, z // `randomizeHeatbugUpdateOrder' Boolean flag we can" q$ p8 e/ P% }0 k' R# M& s
// randomize the order in which the bugs actually run' C: K* ~% e) Z; c- c
// their step rule. This has the effect of removing any! a6 B# R7 G3 W F
// systematic bias in the iteration throught the heatbug
( B0 C% N# k% i) r( p: V3 D // list from timestep to timestep$ e; d( Y8 ]1 n3 h0 X" C- T/ M
1 ?% O- P/ G: h6 S // By default, all `createActionForEach' modelActions have
1 i& N' m9 |$ m0 L' C0 e // a default order of `Sequential', which means that the s @. E- v) \4 O, \3 X6 Q' z
// order of iteration through the `heatbugList' will be
$ o3 |5 u# i) e7 d // identical (assuming the list order is not changed
2 W6 G% k1 K9 c S5 v3 U // indirectly by some other process)." O: l1 X- d2 E+ u2 O6 i0 y w
: |( X# A% g8 @2 P modelActions = new ActionGroupImpl (getZone ());
0 v+ } D4 {. H$ A9 c# B0 f
7 M: p" E$ i5 ?6 z' U, l try {
9 m9 `; c6 f8 u# Q8 ] u8 F( o modelActions.createActionTo$message. w0 {/ H4 D& B4 h# `+ m2 R
(heat, new Selector (heat.getClass (), "stepRule", false));
( P4 j9 p6 h$ R } catch (Exception e) {
. \; ]' x1 B. p- t% H System.err.println ("Exception stepRule: " + e.getMessage ());
# D# h3 u2 f) g! F3 J8 S. g/ t/ R# q }
# O* c8 J( I9 w9 P; F h+ \
7 L! L$ ?# J& B& Q7 X* K: n+ K M5 l try {& w. h. r5 a7 M. ~3 d; m
Heatbug proto = (Heatbug) heatbugList.get (0);
; b. @4 _% q# G' N1 ?1 l x3 ~3 |9 q Selector sel =
9 U: U6 Z( j9 j! q: e8 _ new Selector (proto.getClass (), "heatbugStep", false);/ o p: h8 o+ r7 `- z$ y( o
actionForEach =% R$ f$ h+ [& [# C7 t! u. D! c% ?$ [
modelActions.createFActionForEachHomogeneous$call
& j3 }. p- X8 _: R) x/ K& A (heatbugList,4 ^- n. H" U. {/ ^5 J6 v
new FCallImpl (this, proto, sel,
/ t- W2 u, o8 N( `. ^" K new FArgumentsImpl (this, sel)));
, j/ E# Q0 {; ^/ F7 j* k+ i } catch (Exception e) {
' ]& E1 w) a% r+ P' Z9 c9 Z! k" h# Y e.printStackTrace (System.err);9 ^- J+ v3 \! g! g' N. @
}( t4 } g8 R- q+ f. V* q
' u: w- S/ Z) P7 {, t
syncUpdateOrder ();2 ^; A5 P' R1 W. s
# b* r+ P6 n( z: ?# L try {* ^% f) }3 `* i$ G
modelActions.createActionTo$message
2 w3 B! K3 O* l/ h (heat, new Selector (heat.getClass (), "updateLattice", false));
! @( S( ]7 o; N+ q2 D4 C, `/ ` } catch (Exception e) {# ^3 ]' t9 I4 Q2 V! x% \# ]; c
System.err.println("Exception updateLattice: " + e.getMessage ());
8 x; s6 t0 j$ ~; T2 H }6 f- \ I# J$ F0 l Z8 u1 d; S
# s$ v! ?) A5 i# P. G+ Q; w- E
// Then we create a schedule that executes the
; ]2 a& }* ~5 @; f: p5 c b // modelActions. modelActions is an ActionGroup, by itself it3 s' q. v4 q1 u' t6 k1 B
// has no notion of time. In order to have it executed in3 k& \2 }1 C1 q: I
// time, we create a Schedule that says to use the' \, _6 J& z& v# H* C
// modelActions ActionGroup at particular times. This
. z8 y2 f+ ^% t* z- O M // schedule has a repeat interval of 1, it will loop every2 Y9 S" ^$ _# [2 Q/ Z6 W
// time step. The action is executed at time 0 relative to
7 Q* ^; J$ o: M0 M+ W" q // the beginning of the loop.
5 x0 C t* g2 T- b
: u/ [: R8 f. j! o. p$ Z* a // This is a simple schedule, with only one action that is
- Q4 o( ]# |! o4 ]! [ // just repeated every time. See jmousetrap for more
6 |% U2 `. \6 c; S% j // complicated schedules.4 y7 x5 E' m) W* s @* s* |% \5 h
|, j8 ?1 @3 C+ T3 N8 O
modelSchedule = new ScheduleImpl (getZone (), 1);5 W/ m( h. `6 L' [. X
modelSchedule.at$createAction (0, modelActions);
5 ^5 g/ ]! k. a' U# w( b. I ! G1 x9 l, s/ V0 V# y2 w( n4 C
return this;
0 e2 ^. g$ X1 Q$ w) [0 S } |