HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:5 H5 [. X7 _) ^1 m1 [
2 A- r G% n; k public Object buildActions () {" w# c: r; R* a" v
super.buildActions();
5 V N( |+ q% o9 {) Q ! I! T% r$ }$ ^. D' s8 y* A
// Create the list of simulation actions. We put these in( Y: K8 v7 K3 W/ j- m; i
// an action group, because we want these actions to be
& D: V6 |5 I7 T; m5 l // executed in a specific order, but these steps should! _, p8 s# s& n3 [3 j% \' p
// take no (simulated) time. The M(foo) means "The message
$ o5 }/ o5 x4 J7 g' L // called <foo>". You can send a message To a particular+ q4 ^' o/ N% Q$ \& ]+ }
// object, or ForEach object in a collection.) Z; A! \. m* U( o6 Z
3 D4 g7 @+ X' a1 D1 G- p // Note we update the heatspace in two phases: first run8 H4 h% q; M9 Q' Z/ q) @9 V7 D* U1 O
// diffusion, then run "updateWorld" to actually enact the
% s+ \. u* W' E. b# o( B // changes the heatbugs have made. The ordering here is9 f) H8 P Q4 t! @4 B% E0 x
// significant!
! Q! h( ?- w, r( F( Y# w
' z; g% U, I/ d4 P% v // Note also, that with the additional ]& v0 |( [( o
// `randomizeHeatbugUpdateOrder' Boolean flag we can$ t# h; N- c9 z$ J5 ?; S& X- O! f/ w
// randomize the order in which the bugs actually run% G0 }# P+ G8 V. X8 \2 p
// their step rule. This has the effect of removing any+ Z6 Q3 ^; P+ W6 i8 Y5 N
// systematic bias in the iteration throught the heatbug
/ ^# @7 V- A, O% r, r- M // list from timestep to timestep
( N0 `- _" F8 s4 B' {* f
, ^5 _4 y% h6 k: H$ p // By default, all `createActionForEach' modelActions have u' k9 s- y9 ^) {+ i. [8 c
// a default order of `Sequential', which means that the
) Y( ~2 { t) ~4 ]3 W# ?' ~- G // order of iteration through the `heatbugList' will be
# I2 O' N4 G. |5 b4 { // identical (assuming the list order is not changed3 d4 ?9 M8 Q3 i& [4 _ {* d
// indirectly by some other process).& B$ n2 `& B0 Z* H
6 }- k; [$ @' W. t8 \- \" K modelActions = new ActionGroupImpl (getZone ());- J, U: s: p5 `( B9 c
& _4 o0 b% T. C6 [& O5 L' g& J try {
: _& A7 U' h2 Z% J/ k4 M0 |, v modelActions.createActionTo$message( B, d) A7 F4 d4 v5 k. k# F
(heat, new Selector (heat.getClass (), "stepRule", false));9 S& j8 B0 b1 z, @
} catch (Exception e) {
0 h7 y& \, b6 K! L% h: d System.err.println ("Exception stepRule: " + e.getMessage ());
2 F& _" k4 z1 {8 H8 W }
7 k3 }& G% k# J
; ~& R2 ?3 B$ I F* l try {& b& W; r E, [
Heatbug proto = (Heatbug) heatbugList.get (0);
8 j$ I- ~* Q$ V; L0 { Selector sel =
( E9 F4 g1 L. d( u new Selector (proto.getClass (), "heatbugStep", false);7 d1 k% ?# V$ J8 E! ~1 w& T1 {8 j
actionForEach =* U; Q3 V: A9 G6 P3 K% Y9 ?, x
modelActions.createFActionForEachHomogeneous$call o7 Q7 U9 Y5 t3 q! ]" W Y
(heatbugList,9 H- {! g9 b! _8 ?+ p' c
new FCallImpl (this, proto, sel,
# E/ h3 g4 m/ h/ C# o new FArgumentsImpl (this, sel)));
. |. d1 k; W7 d7 _0 x4 f5 x } catch (Exception e) {
. p( ^. W& k3 F1 u. E7 z1 W3 F* T e.printStackTrace (System.err);
9 p* p% F: c7 ~- L; d' C, O9 L }
0 e& p' C( r0 [
) a7 i0 z- B: Z syncUpdateOrder ();( @7 H0 C W V& Y, W2 r% |
7 Q% Z8 T$ g% p% y0 ] try {( i$ ~& g( O! {8 Q' k/ _, V3 u: b, p
modelActions.createActionTo$message
* }4 i6 g+ t' b (heat, new Selector (heat.getClass (), "updateLattice", false));5 e- K/ ?; g j% L0 K0 R
} catch (Exception e) {7 K G3 ~' `! m! c' r3 F
System.err.println("Exception updateLattice: " + e.getMessage ());
# v. N: `! p1 l }! c+ Z- T# U2 s
6 s7 x' ~ d3 \5 R
// Then we create a schedule that executes the' Y' }% B3 P& W. l) n& q5 N
// modelActions. modelActions is an ActionGroup, by itself it
c$ i! \9 v$ A* m+ _6 ~- H w // has no notion of time. In order to have it executed in
" |& X0 {2 Z) [6 G // time, we create a Schedule that says to use the
' Z* j6 A, u! X: [ // modelActions ActionGroup at particular times. This
$ F2 k1 q: r( M // schedule has a repeat interval of 1, it will loop every8 q P( J# U9 `& Z! r) @
// time step. The action is executed at time 0 relative to7 u w% [; C: O6 v: X0 k: v- z7 D
// the beginning of the loop.5 J8 _6 y# N' \& S% o* }
2 V- z5 ~" e: z* U& [6 f" {& m // This is a simple schedule, with only one action that is
) t/ I* R. Y& ]) n! ]/ f& E/ N: C" O5 g // just repeated every time. See jmousetrap for more
9 Q# L- q- B* ~& V1 s // complicated schedules.3 h4 P* E9 A' \1 H9 G7 t2 V
/ v5 l7 @8 r" W5 i modelSchedule = new ScheduleImpl (getZone (), 1);
7 G4 U$ u8 b) Y, L modelSchedule.at$createAction (0, modelActions);
H+ T3 E7 R0 j5 G, P9 d9 s
/ z# I$ H* ?9 ^8 a$ N return this;4 }- V: l4 a p+ w
} |