HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
w% G* e& b! t( {% I4 L4 L5 {
+ O J: B9 n& e public Object buildActions () {! v3 @ u" J3 o5 r
super.buildActions();; q& p O# q( X# H3 d0 c5 Q
5 C& ~( I: C; k! B/ g1 ?* W, s // Create the list of simulation actions. We put these in: ]! s" r0 T$ e5 L6 X
// an action group, because we want these actions to be+ T" F; O E/ e
// executed in a specific order, but these steps should
( T7 M+ m% V. P) [* }' { // take no (simulated) time. The M(foo) means "The message
* l- o( m, h/ Z# Y // called <foo>". You can send a message To a particular! d: ?2 c7 E/ ~1 a! P0 ^$ d# k5 Z
// object, or ForEach object in a collection.
( r: ^* g/ \ s- t ' H) p r9 ]: W4 O g1 M5 K- U
// Note we update the heatspace in two phases: first run
( x- F( q! l, R0 x& V7 T // diffusion, then run "updateWorld" to actually enact the8 m* h, W( Y0 q# v
// changes the heatbugs have made. The ordering here is
# \& s4 k' v8 F0 N; |2 |" t // significant!* b+ I- h( d* }5 B/ k) F3 E
; u E5 _ h* H' @6 v4 |4 N$ h7 w // Note also, that with the additional: ]' V! T( e$ G' R! S% b: ~; }
// `randomizeHeatbugUpdateOrder' Boolean flag we can. |0 C5 O0 ?! r. q8 ?5 i4 ~# ^- k
// randomize the order in which the bugs actually run+ I0 U- f6 s) I
// their step rule. This has the effect of removing any( N+ E9 x. L4 c% P3 @" Q
// systematic bias in the iteration throught the heatbug
0 v7 r' o& f! |% y" U$ W5 B3 m$ i7 N' T // list from timestep to timestep
3 e' P) C% i1 ^2 ]0 X5 F4 ^
6 o4 t- ^& c& }5 @- B; M8 ^ // By default, all `createActionForEach' modelActions have
# `9 [; F! t) ~+ w0 E // a default order of `Sequential', which means that the
; R( s3 m5 l! E6 k4 j& m // order of iteration through the `heatbugList' will be
1 n; |" ?9 r2 \" b0 d7 p6 |$ J // identical (assuming the list order is not changed
5 D0 b$ |' \4 @+ _ // indirectly by some other process).6 a! u$ x4 t! P/ J$ m
1 ~ m: ^ D6 l5 h( ~3 F& ?' ? modelActions = new ActionGroupImpl (getZone ());0 g1 z. a8 u" |6 m/ }+ Q, h
1 ?/ n# V* a' ^: M5 t; D try {
! ]2 [' @/ W, e% i' k; U modelActions.createActionTo$message4 W8 h8 |( n+ D; k, O
(heat, new Selector (heat.getClass (), "stepRule", false));. ~" A" Q/ ]: t) T! z6 Q1 e
} catch (Exception e) { d( s! A" [( y) D
System.err.println ("Exception stepRule: " + e.getMessage ());
" k9 S- S1 t7 d6 e+ u. L- q# n }
4 w* y2 w7 ?% b3 H' z0 `% e9 R
5 G! o% X; z( U2 V) |$ [ try {
5 W8 B: s H8 d( L0 p& o! l Heatbug proto = (Heatbug) heatbugList.get (0);; U/ g8 {$ x( F" S9 E$ L* T) l
Selector sel =
; e6 ^( K( P6 e- F% e- V9 S new Selector (proto.getClass (), "heatbugStep", false);
0 w9 O" [8 N/ m1 A9 r* {; ~6 [ actionForEach =
$ p. g. `' u; r modelActions.createFActionForEachHomogeneous$call
* O$ i1 y4 F M- [9 z (heatbugList,( D% @7 ?5 d3 v& l3 ~2 H, G
new FCallImpl (this, proto, sel,
; l% J* ^/ r. _& g new FArgumentsImpl (this, sel))); `' J) t$ Z# b
} catch (Exception e) {# `/ i* ]! }! b2 q. n0 B' k
e.printStackTrace (System.err);$ T* u* D' g2 C2 X
}, A1 |+ o" |$ [+ n/ L
5 U$ Q8 Y- R1 l" c& Z" x( O
syncUpdateOrder ();+ D0 p" U7 n; ~8 \* p5 O
2 {' V7 A% t" y
try {; ?- K; @7 L# ~5 t
modelActions.createActionTo$message
, u% n1 k: f/ d/ y( _1 w6 S (heat, new Selector (heat.getClass (), "updateLattice", false));4 j/ [3 e. a4 z/ x* b9 ^/ H
} catch (Exception e) {% \! Y. s5 N0 w' D7 _! R" U- g6 o
System.err.println("Exception updateLattice: " + e.getMessage ());
- a* _7 D; D3 g! u7 y( H }
2 i8 O2 W2 \& l
+ y7 l( c! V: l // Then we create a schedule that executes the
/ ~* {0 j2 B& k0 H7 h+ A1 t. x // modelActions. modelActions is an ActionGroup, by itself it1 E$ w; @* t# c3 c1 J4 w
// has no notion of time. In order to have it executed in& B0 z8 K" i. k+ z
// time, we create a Schedule that says to use the
. F( v3 j6 g* D0 T, ?; Z$ C5 A // modelActions ActionGroup at particular times. This
. F. M. F6 k, u# Q6 K: h5 g0 t // schedule has a repeat interval of 1, it will loop every) k y: D: Z8 k2 V. ^, _$ v6 f
// time step. The action is executed at time 0 relative to( F# ]: [5 b9 u6 f3 q8 u9 M
// the beginning of the loop.
$ l' p; H2 M+ S) z" K. @: U
. f: b' b" d" G+ J: [0 w9 ^ // This is a simple schedule, with only one action that is. Z1 a7 e$ [3 W
// just repeated every time. See jmousetrap for more) F+ I/ Z9 ~5 y3 B7 P
// complicated schedules.3 }8 r- Y- Q8 Q# j* L4 [' E4 _
& [; `& h& _% I; l5 M
modelSchedule = new ScheduleImpl (getZone (), 1);
. L3 B$ \& T& W4 P, z& J7 r) i modelSchedule.at$createAction (0, modelActions);
8 T$ c( r" M. m" Q( L
2 i6 z' c0 h6 w6 n return this;: l$ x9 O- u" S9 x5 x
} |