HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
6 @9 w6 ^, e8 t
( X+ ?0 ?) Z) B2 z S$ ]9 u public Object buildActions () {
% F# V% B! N t+ m super.buildActions();5 A H S7 Z* E4 f" Y" E, p# K
. C; x9 t( L. O // Create the list of simulation actions. We put these in
" E0 g5 j. F. C0 S6 }$ \ // an action group, because we want these actions to be
+ y) Z' D" l% C: F# ~ // executed in a specific order, but these steps should6 V6 i" T4 }% ]5 A- V, v% O
// take no (simulated) time. The M(foo) means "The message
6 C6 x1 E1 ^5 f5 ~ \9 z t // called <foo>". You can send a message To a particular( M1 u& M I$ f# v. f1 s- e! j
// object, or ForEach object in a collection.% |) s7 U" L+ G6 a. [; J( d: `
4 r8 l* B; W5 e& x2 v4 ?
// Note we update the heatspace in two phases: first run
* |6 ~( v2 V2 i) n! j% Y0 w // diffusion, then run "updateWorld" to actually enact the
5 h- ^# ^, V8 _; J // changes the heatbugs have made. The ordering here is& N0 @ J; M9 R
// significant!" T; Q( b! ~- N
7 S$ @! V+ s4 W! ^5 J2 M+ r( C // Note also, that with the additional1 C* i; ?( w. z- |3 g" d
// `randomizeHeatbugUpdateOrder' Boolean flag we can
& y$ j2 K; O- t0 J // randomize the order in which the bugs actually run! M% L/ X. g' L" w$ w. q
// their step rule. This has the effect of removing any
7 i; W+ c( d' B8 h // systematic bias in the iteration throught the heatbug, E5 i" |2 y2 [; c! v8 _5 y
// list from timestep to timestep7 @: n2 E- w$ f+ S/ T+ ^
0 c' N# G: B% Z
// By default, all `createActionForEach' modelActions have1 j0 A. d- u q" T% z" s' s! h7 p
// a default order of `Sequential', which means that the$ n' z& Q$ B9 U' v0 V+ Z
// order of iteration through the `heatbugList' will be1 W. L2 c0 N- K' ?. U5 W# x% V
// identical (assuming the list order is not changed
7 A( m& R* y( _) J9 ^* y // indirectly by some other process).: _: {; l0 J3 u6 k$ O2 I1 Y' U; h, E
% N8 f9 e+ S, V9 D6 T6 E/ T9 ^
modelActions = new ActionGroupImpl (getZone ());
- ?: _1 Q: @. A/ B$ |! f# Y* v5 i9 t0 E4 p# X
try {3 k6 J- ~/ s) }+ p# t' H
modelActions.createActionTo$message5 i- g$ w8 H( h4 Y$ W9 i# v4 B
(heat, new Selector (heat.getClass (), "stepRule", false));
' Q& y: u/ \ w- F$ ~' I } catch (Exception e) {# p( @) L/ S8 `3 ]2 T$ n
System.err.println ("Exception stepRule: " + e.getMessage ());2 @$ Q* C& s) f7 R5 B2 h+ f" z6 y: _
}$ r# e7 u6 J i, |7 W/ S7 ]
( v' z2 N8 T( @% _5 s6 q& B0 u4 O
try {
3 i6 f; R! ^% J9 ^9 u0 ? Heatbug proto = (Heatbug) heatbugList.get (0);
. ?. p: b, N, j* c$ y/ L& Z Selector sel = 1 \& L% y! R: `8 g
new Selector (proto.getClass (), "heatbugStep", false);
( N1 e. c- i6 T) D& E! ^$ @ actionForEach =7 i4 {: N- H% M0 v0 Q# R
modelActions.createFActionForEachHomogeneous$call7 C4 a; q8 Q M* z
(heatbugList,. C0 q2 X3 f3 A1 x" W
new FCallImpl (this, proto, sel,
, a5 X: \" G6 t# o( V1 e new FArgumentsImpl (this, sel)));
, u6 Q4 U8 i' T7 Z } catch (Exception e) {
7 P. g8 c# z/ v k e.printStackTrace (System.err);& P; J. }( X8 L+ d8 ]" W9 G
}+ }4 O6 ?/ |( b F! k$ ~1 `
2 h6 \- }$ C* A+ d) W syncUpdateOrder ();; }. U+ K- `4 U& u9 ^4 ^
; c- c( G4 `( Q* L" H9 H' ~ try {
6 V9 T* G, b7 t# B4 h modelActions.createActionTo$message ' y9 Q8 M" l. C+ g0 E: p* U( J
(heat, new Selector (heat.getClass (), "updateLattice", false));
* b" x/ H" ^2 c: k' ~ } catch (Exception e) {
7 H6 Z/ i4 D& a# f System.err.println("Exception updateLattice: " + e.getMessage ());; t: q- t' f4 A2 n% C4 Z) I
}
+ o" K1 [4 ]: Z2 Z6 o+ i2 u0 G) | y6 L) J6 \7 {1 q% R, F/ u0 q
// Then we create a schedule that executes the
# w5 M1 A" _8 f: g0 k! D // modelActions. modelActions is an ActionGroup, by itself it) k0 i: M6 P0 ^. @- b- u1 t
// has no notion of time. In order to have it executed in$ v9 M2 J3 w$ @7 j1 S
// time, we create a Schedule that says to use the
* x$ } p0 |' ]" [' l( k" F# P$ I // modelActions ActionGroup at particular times. This4 M8 Z% z; r' q6 t
// schedule has a repeat interval of 1, it will loop every
) t0 H9 N) G# N // time step. The action is executed at time 0 relative to, @1 H, C4 k' ^! l( D
// the beginning of the loop.9 a3 J: u2 Y- Q" `) r' J
* T. N; W' o' A) L1 |2 U
// This is a simple schedule, with only one action that is
f- M6 p# @. i' ` // just repeated every time. See jmousetrap for more
7 s- {; K! ^! u0 J // complicated schedules.
! i5 j4 Y% {% i6 e. h4 z0 B
. k/ B- @ @1 R5 _2 r modelSchedule = new ScheduleImpl (getZone (), 1);
' `- f8 X- j& {, ] t+ i7 L modelSchedule.at$createAction (0, modelActions);$ n% r: T1 n* ?& d1 X$ ]/ {
/ E. Q* U" C5 N return this;+ f F# i8 h$ b! \6 A
} |