HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:- }. d: m) n" W% y" K
1 ]8 c! E( c5 ]- F# r: t, ~ public Object buildActions () {
# R5 r: K5 }7 N9 w super.buildActions();
! [% R% p7 z, w; R: I ' f$ Y0 {' ~0 l0 v9 c0 I4 v9 ?% R8 [
// Create the list of simulation actions. We put these in1 I4 \+ T. [8 w% F: k% j8 }
// an action group, because we want these actions to be7 J8 h9 W, l2 V7 L! r6 z/ e+ n
// executed in a specific order, but these steps should4 K i( B9 {& F7 t
// take no (simulated) time. The M(foo) means "The message
1 `8 j& D7 l: O0 X' G! s // called <foo>". You can send a message To a particular
+ O; z" N; d8 E5 w+ W // object, or ForEach object in a collection.! l( q1 U9 z4 O" ^! ^; h% k8 w
6 i# C/ T- c$ C7 j, T9 a, ? // Note we update the heatspace in two phases: first run1 L2 w- ]+ F- W: z, C T& I
// diffusion, then run "updateWorld" to actually enact the
6 E4 k$ C/ S; B& [ // changes the heatbugs have made. The ordering here is# u) `& K! R. Y& u; \8 |; F
// significant!! w; X5 k1 o, u' N9 G, Y- E+ F
, U* l1 L c5 m* V( M8 w
// Note also, that with the additional
# q* {1 G/ R& u3 U // `randomizeHeatbugUpdateOrder' Boolean flag we can
5 ^; I# | U6 u9 a6 {% B' o // randomize the order in which the bugs actually run
2 j1 Z4 H, I Z5 J- z; K // their step rule. This has the effect of removing any
% J6 A N& h( _0 @" C1 d // systematic bias in the iteration throught the heatbug
' G$ c) I. l: Q* c7 j% s // list from timestep to timestep! Y; p" \- z* [3 r0 {* r
/ e6 z5 I8 p: b {4 h8 N- Z* Z // By default, all `createActionForEach' modelActions have! f2 f1 _( `; |( c. D* i
// a default order of `Sequential', which means that the
$ m$ N2 `! a7 h" X8 A& ^" P // order of iteration through the `heatbugList' will be
0 {1 h$ g, j2 O2 [5 A // identical (assuming the list order is not changed' M- f0 t! i. o9 L; v m
// indirectly by some other process).
_0 j% ^% q- P2 J! y0 s% c 8 E. P$ f# f j6 p
modelActions = new ActionGroupImpl (getZone ());" Q0 N7 I; X0 a9 c+ V
+ A- R# f8 R4 `5 {9 O1 k, F
try {% A, t: A' r3 F2 S6 ~. d
modelActions.createActionTo$message
! I7 s( B1 a4 D" y7 j6 L) |) C (heat, new Selector (heat.getClass (), "stepRule", false));
% I* Y# ~) i" y: o } catch (Exception e) {
' k; Z" J1 a+ X# x System.err.println ("Exception stepRule: " + e.getMessage ());
3 e0 W2 s% M3 Y. t1 v, x' Y. N }
& a1 y5 a8 f- y& P! z
8 m( y( @. w' H4 s0 i" z try {6 L/ J+ j& m7 Y0 K/ H: e
Heatbug proto = (Heatbug) heatbugList.get (0);5 F5 u8 `: m& x% |: |4 U8 ^" M
Selector sel =
. [% \9 S% J& p( Z, }0 z5 }2 p7 P new Selector (proto.getClass (), "heatbugStep", false);
7 B+ @% N; R4 E9 [) \. q" ? actionForEach = r" \3 b7 I3 i! i9 E6 i# w/ V
modelActions.createFActionForEachHomogeneous$call
. ~$ T, L% ~2 X4 v; p. y H' Z5 i (heatbugList,
# K# x F0 ^# ?( D/ D new FCallImpl (this, proto, sel,. h+ e3 U6 m* t9 g' S+ [
new FArgumentsImpl (this, sel)));
! }; |5 L! `: P6 `# z: L5 W8 w } catch (Exception e) {0 G4 I- A3 r4 o* s0 B: X0 Z# H; @
e.printStackTrace (System.err);( w0 @6 I. F& N$ C
}+ k* k$ Z5 y6 B1 x- I* j
! f# [1 l% H ] syncUpdateOrder (); }9 Q3 l0 E. F2 P
0 P8 n$ B ^; H5 {4 U try {, K0 _0 R7 w. `
modelActions.createActionTo$message 3 j- _% N& m# d
(heat, new Selector (heat.getClass (), "updateLattice", false));
# d( c# R/ z7 ^' r( n- C } catch (Exception e) {
: P+ b s, {6 \6 {: h4 T' C' Y8 t# N System.err.println("Exception updateLattice: " + e.getMessage ()); O+ p: `3 K! D
}
" x8 l3 W, X7 {( n
: P, j; ^; X! u8 D3 m // Then we create a schedule that executes the
$ T# d+ l+ l1 D& O // modelActions. modelActions is an ActionGroup, by itself it! i4 F* t( Q2 r- J( V2 V$ T
// has no notion of time. In order to have it executed in9 R$ A* L6 u9 [6 E0 C5 W. _
// time, we create a Schedule that says to use the. T1 c0 E1 A- I* K# z2 R9 v1 d4 ]3 X
// modelActions ActionGroup at particular times. This
5 a7 |. L& ^( J d: C // schedule has a repeat interval of 1, it will loop every2 U' W1 ?3 y8 v3 V1 r
// time step. The action is executed at time 0 relative to- C( L1 {# r5 f5 f5 q+ z
// the beginning of the loop.; h! ~: w, t4 a7 E- r3 R' I
* ]; l; g& \6 }7 Z
// This is a simple schedule, with only one action that is% f# u. ~8 W5 p* l! w' V
// just repeated every time. See jmousetrap for more
3 M$ L( {4 g U3 c& H# c$ Y4 Q // complicated schedules.
$ ]) S6 o7 n! U0 N% f1 } - R( C# L; F+ h0 l5 m- X
modelSchedule = new ScheduleImpl (getZone (), 1);8 `' U ^* y1 ~, p9 ^( ^* k
modelSchedule.at$createAction (0, modelActions); l% _$ V- p i. R4 [) e
# }9 I' G0 D/ Z% C" p+ ^ return this; _$ N) Z1 `1 [
} |