HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:, w$ p! ~6 h: v
0 l- z; `5 M; Q# L' v public Object buildActions () {! C; Q1 e; y0 O) O: L6 u: N0 X" t
super.buildActions();" e5 f% w$ [5 w+ o) c% z
. u5 \7 b ~7 h8 K! Y
// Create the list of simulation actions. We put these in; A: g. x+ f1 d; C5 A$ x' w
// an action group, because we want these actions to be
5 h" R4 _" b+ c& e C // executed in a specific order, but these steps should; F" C( C9 |7 T9 k' c
// take no (simulated) time. The M(foo) means "The message5 d' i1 J% V* G% \! |
// called <foo>". You can send a message To a particular
- o Q, L% J f // object, or ForEach object in a collection.
/ w: x* m: B8 Q! V: T+ X
+ p3 f v6 h7 @ R // Note we update the heatspace in two phases: first run
. z M3 Z0 _% C1 O0 A* C9 _ // diffusion, then run "updateWorld" to actually enact the
; ?. J, d" C9 g$ a7 D // changes the heatbugs have made. The ordering here is- c1 w1 M7 A+ B! n
// significant!2 l. X: a: i. ?# e
$ z9 v2 P# U" j // Note also, that with the additional
5 Q# o% n; z6 W // `randomizeHeatbugUpdateOrder' Boolean flag we can9 t; f" {( ~# G
// randomize the order in which the bugs actually run
# j' g D9 V0 K // their step rule. This has the effect of removing any
+ k2 v$ Y- `% Y% r" J // systematic bias in the iteration throught the heatbug, H3 d# P/ K' w9 l
// list from timestep to timestep6 ~. V& c/ g; Y# x( E
/ Q6 Z9 W, g! Q m
// By default, all `createActionForEach' modelActions have* f6 f; ^7 f- u5 Q- ~& J+ A2 A: ?, E
// a default order of `Sequential', which means that the
. ~, {7 ^% q# a: h // order of iteration through the `heatbugList' will be
/ p5 s% I* q3 x1 W( x // identical (assuming the list order is not changed7 j" J: C% H; e% c9 i$ r
// indirectly by some other process).) K& u( G# j/ }) n" e0 l5 \ c
3 }3 D0 T$ J. |
modelActions = new ActionGroupImpl (getZone ());9 D4 @$ V( u2 A. B
- I) {/ e$ x& t# {/ r4 ^ try {, ^0 _2 @% H- ]1 ~) A, {3 \: z
modelActions.createActionTo$message- P7 M8 S$ Z! b# X' {* ]3 u) M0 N& a. h
(heat, new Selector (heat.getClass (), "stepRule", false));
( w- K [$ U. ^4 Z Y0 K# s } catch (Exception e) {) c8 X7 ]8 m& ]; u& Y7 W; _
System.err.println ("Exception stepRule: " + e.getMessage ());
0 p( I6 L" ]% ~0 V+ s4 T" Z6 _ }8 t7 `7 O* @1 P
, V2 P# u c# I7 b' { try {
/ F! K, o4 e, Z6 F Heatbug proto = (Heatbug) heatbugList.get (0);$ @' e3 e. G0 k( g- F, @7 Y# O; Z
Selector sel =
& v) ~* w3 Z o& y new Selector (proto.getClass (), "heatbugStep", false);
9 e% I3 Q8 C3 u, J actionForEach =4 [" x. b8 s" U4 ^, W$ t2 u1 m3 _
modelActions.createFActionForEachHomogeneous$call9 X& {2 `& w) J
(heatbugList,
$ f; _# P7 l& Y/ j' n, S7 L0 S new FCallImpl (this, proto, sel,* c* `( U0 E8 g* I! Q: \) [5 G& y
new FArgumentsImpl (this, sel)));
! i% w7 ^. F" D ?- U k* X } catch (Exception e) {* ^$ ?; t; P6 y5 n# F7 }/ C2 h
e.printStackTrace (System.err);2 O7 d A; J# K% f" ]5 C' d
}
- d% R: O, t9 r7 C, c' `
/ ]7 d ?" H. d5 R" z syncUpdateOrder ();: x, O5 c% M- h2 H" p
9 S. L1 v' P, h% J: j% y' l9 P
try {" d; \0 B+ E5 _+ `! ]
modelActions.createActionTo$message 6 [9 f% ^8 ]: h8 \
(heat, new Selector (heat.getClass (), "updateLattice", false));
& J3 q' }5 c+ M$ t; i! p } catch (Exception e) {) x4 K ?! _( w- b* m% P. f
System.err.println("Exception updateLattice: " + e.getMessage ());2 D& O1 m4 u$ Z" u& p& a7 }
}
5 ?, {) i5 f( @' c7 N9 h( l% V . J+ ^. n3 _5 G2 T2 _
// Then we create a schedule that executes the
9 a& |4 P$ Q5 y1 L& m# T // modelActions. modelActions is an ActionGroup, by itself it
" [; l9 L3 g W // has no notion of time. In order to have it executed in ?& U) G. f9 R
// time, we create a Schedule that says to use the
( ^* }6 p3 |- U& P4 H8 g5 v6 S/ V, q // modelActions ActionGroup at particular times. This% X8 B2 }6 K# g2 L- u
// schedule has a repeat interval of 1, it will loop every B8 l* f( p0 l* \( y4 u4 T, X
// time step. The action is executed at time 0 relative to( F( x' O! E3 @, y) d0 y' g
// the beginning of the loop.' Q o6 S+ U2 ?6 k
( ^4 M5 E0 z' S. W; y1 | }5 }! A // This is a simple schedule, with only one action that is
# M( D4 E3 r4 R // just repeated every time. See jmousetrap for more3 z% D# k& c) V& r
// complicated schedules.0 _7 F* \! ?# _
" Z+ r4 _+ q# N modelSchedule = new ScheduleImpl (getZone (), 1);; z8 z; w) n6 f6 E$ s
modelSchedule.at$createAction (0, modelActions);5 J, H: @" x# t1 o% ]; Z& w5 C
$ J7 h% s. j% E3 o" J& u return this;
+ t" _4 m* u5 W0 S } |