HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
% T( F7 }1 C: j ]
. k& c4 m- F6 J0 [) Y, | public Object buildActions () {+ L O& ], x% D3 K5 p
super.buildActions();1 w7 }& A3 s' Y
7 u; H: }! X* h5 O3 w) X // Create the list of simulation actions. We put these in; E! a. v: z5 P9 {' I
// an action group, because we want these actions to be
0 L. n* {2 m& ]8 j7 [% }/ @9 f2 X // executed in a specific order, but these steps should4 }8 P2 A2 H& \# n5 A& G
// take no (simulated) time. The M(foo) means "The message5 |0 ]9 W# {8 p
// called <foo>". You can send a message To a particular9 o9 _1 C7 Z% v/ n" n
// object, or ForEach object in a collection.
4 W4 m! v0 B$ Y# x1 r/ G, O# n ' b8 A% X, Y2 e" T2 B# p0 s
// Note we update the heatspace in two phases: first run
& G9 O: n% j8 v, S$ M. B2 l // diffusion, then run "updateWorld" to actually enact the
$ ^, n' N, N, ` // changes the heatbugs have made. The ordering here is
, v5 D% r4 u/ r3 a' l // significant!
) F0 j# z' a4 z% W! X }
1 I( ~/ V( V+ N // Note also, that with the additional" Y# f- R$ @) N) ?- o' G( }9 J
// `randomizeHeatbugUpdateOrder' Boolean flag we can
* t% R" \. B0 `, W2 B( d# e7 S // randomize the order in which the bugs actually run5 E+ _. ~# X- f% B
// their step rule. This has the effect of removing any
' X( `' d- _6 z! F; |4 {% j/ P // systematic bias in the iteration throught the heatbug
6 K- r' N0 A3 {. I! Z& I* q // list from timestep to timestep' Y7 @, R5 f( p" m9 x* L( b7 T: c; z
; @( ?6 ^. S! S! y" y! H // By default, all `createActionForEach' modelActions have
; }' _- r, g2 ~: G7 \ // a default order of `Sequential', which means that the: V5 o. i3 c4 `
// order of iteration through the `heatbugList' will be$ Y( P1 N+ U9 }5 C
// identical (assuming the list order is not changed1 p/ g4 ^: W2 f. s2 o1 H+ Y
// indirectly by some other process).
8 L! ^4 X8 V5 e9 X" K+ p# t
# h4 x" z+ g) P1 _' \1 I' F modelActions = new ActionGroupImpl (getZone ());
% c: A/ N; ~7 K7 L D! _, j1 z/ i0 f6 A" m' h8 m3 A
try {# v/ S8 I L5 H% y- o0 Z& \" s
modelActions.createActionTo$message
! W: N' X0 K; a4 J (heat, new Selector (heat.getClass (), "stepRule", false));3 T! L( V1 f$ I- P/ m) u8 u4 N
} catch (Exception e) {
6 T- f6 j, t( O: v0 P S2 u System.err.println ("Exception stepRule: " + e.getMessage ());1 a- A# Z, X+ `$ j3 B! J
}6 h$ M8 X: K4 I( ~3 }
! n; w6 g4 s$ n$ b* |5 B8 O0 h' e! y
try {( ? ?9 Y4 ^# f8 H
Heatbug proto = (Heatbug) heatbugList.get (0);& l9 {( Q, x" `% H
Selector sel =
- ^7 s' O& M9 R1 ? new Selector (proto.getClass (), "heatbugStep", false);
5 D. k( l8 r/ s" K& O actionForEach =, M0 Z: ?$ ~8 m9 n6 E
modelActions.createFActionForEachHomogeneous$call# E7 e/ }( C5 w7 z$ a9 y
(heatbugList,( F6 X- t4 _/ G, h& U! S
new FCallImpl (this, proto, sel,! S$ {1 E' _9 K' R. P8 x$ m
new FArgumentsImpl (this, sel)));
: @5 t, I1 X8 C4 K } catch (Exception e) {) x8 q5 Y) r/ C0 P4 _! l G
e.printStackTrace (System.err);7 U9 v9 @5 q; ]9 U0 [9 {
}
/ _/ I# Q* i+ d 5 g7 w4 R* {' V& k
syncUpdateOrder ();) e6 u3 h; N/ T$ |+ H! o: r
2 s% L8 A( y* ^7 t, ]$ W/ d: v3 I
try {) d6 y, _7 [) U C
modelActions.createActionTo$message 8 l" ]7 X/ _4 O5 _3 r
(heat, new Selector (heat.getClass (), "updateLattice", false));8 a, v% ?8 R' P* N+ `
} catch (Exception e) {* y& Q0 V( ~( L2 ^/ s$ a3 U
System.err.println("Exception updateLattice: " + e.getMessage ());
* `+ B b% N1 l$ ^ }
3 ^# J+ S: E3 Q( h& P, D
& e! _7 z7 u( D. g0 _4 g4 ] // Then we create a schedule that executes the$ E5 v* u- ]. k2 O" o/ E# f. ?
// modelActions. modelActions is an ActionGroup, by itself it: C3 p8 D$ ]/ Q! }' b
// has no notion of time. In order to have it executed in
: n ?" K+ v9 E& I3 K // time, we create a Schedule that says to use the& R+ i" }8 `0 ~6 ^6 d8 N- s
// modelActions ActionGroup at particular times. This
+ z9 Q; S1 \* i" |' X // schedule has a repeat interval of 1, it will loop every. z. O5 ^. E. j! }; Y# ^) P$ u
// time step. The action is executed at time 0 relative to
5 _1 E, X2 n$ X- n* Z ?, s" h7 {7 P // the beginning of the loop.7 Z/ g3 `0 N/ e8 P, D% E, X! a
W# w$ i( q" j p3 \0 p' v // This is a simple schedule, with only one action that is
2 D W9 g) V# N; z7 x9 j // just repeated every time. See jmousetrap for more1 H% { F% {' ? s; @; i
// complicated schedules.% k" h/ D4 F/ ^! f4 Y
0 r7 x+ B: K6 r, P& a
modelSchedule = new ScheduleImpl (getZone (), 1);
" m5 X5 f6 T1 T( y2 l! s modelSchedule.at$createAction (0, modelActions);% O" z) c& q( T* `* m+ d; O1 b; L& M
/ g* q% H( k* J0 n7 s, D return this;
0 m% N W( i5 k; b c' k! { } |