HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
+ s; v" O! a1 }. Y, M$ \/ ]5 V! K* t4 C) A* A
public Object buildActions () {
3 Q2 V! G+ W3 Z; e: E! l( I super.buildActions(); v4 v- E8 i. h( c
# H6 q0 B3 n; Z5 U8 t
// Create the list of simulation actions. We put these in
( f+ X: s5 y: t/ G0 ` // an action group, because we want these actions to be
; }, d: G' X# {* o& X6 x // executed in a specific order, but these steps should$ B" W& p- H5 H% a# C9 Z6 _
// take no (simulated) time. The M(foo) means "The message
# Y* d' ?4 h; \+ [ // called <foo>". You can send a message To a particular
2 _8 ]! h: O* q! ? // object, or ForEach object in a collection.( s1 I( u, O, B9 b+ }. @
) P9 I5 e, W, e& r! q8 E& I
// Note we update the heatspace in two phases: first run' G- J/ V4 u% X
// diffusion, then run "updateWorld" to actually enact the& m) l4 B6 b' r
// changes the heatbugs have made. The ordering here is
0 j1 @8 y" d$ V/ J- J% v# j // significant!
6 T1 }: w* R/ n6 |5 l + J+ {$ y6 e, |& v3 u$ B1 D- y
// Note also, that with the additional
# X) p5 U& V8 m // `randomizeHeatbugUpdateOrder' Boolean flag we can9 d* k: H/ N" n
// randomize the order in which the bugs actually run
6 i1 o# i# L+ A3 Z // their step rule. This has the effect of removing any; H6 j- _6 ~$ d
// systematic bias in the iteration throught the heatbug# ~4 @ p' ~% E+ H3 d
// list from timestep to timestep* e; k( v, M9 |( Y9 @% O
9 z- Q% h2 f2 l% N3 P A
// By default, all `createActionForEach' modelActions have
$ U! r2 j7 T% v! W# Q9 ~: f2 c" K" r // a default order of `Sequential', which means that the
% o* @! X l9 s6 k% d // order of iteration through the `heatbugList' will be/ \( E K A! @& X9 T5 K
// identical (assuming the list order is not changed$ \: h! I( e6 V) f# i6 }; E9 _
// indirectly by some other process).
/ Z" y2 [2 E. F- H , \; b- Q3 m9 B& C2 M! v
modelActions = new ActionGroupImpl (getZone ());' E9 T- `2 [, N. k9 A
% b3 Q' H1 @" \
try {
- u; `& }' s- p% W$ ~1 X modelActions.createActionTo$message: ~; v8 a$ f9 b% W3 i
(heat, new Selector (heat.getClass (), "stepRule", false));$ D* e; J/ I. u( r- w
} catch (Exception e) {9 \( G0 O4 y4 A8 Y" Z
System.err.println ("Exception stepRule: " + e.getMessage ());; ?7 l% m' r8 J4 @5 k' {
}
5 M p9 s- E1 a/ G. F# f% c8 v" c+ j' y8 `3 d1 @
try {
5 s$ v9 p3 @4 B Heatbug proto = (Heatbug) heatbugList.get (0);; U. }" K7 T2 K) U2 t
Selector sel =
5 e( M- ~, E8 i5 U( ~3 W new Selector (proto.getClass (), "heatbugStep", false);
) ?% P! \8 ?& {' Q* c actionForEach =
- n( i6 P) H' Z2 `8 }; { modelActions.createFActionForEachHomogeneous$call
+ N! L6 h# I" R: ^, E$ n (heatbugList,
; s- I' Y* ]3 Y new FCallImpl (this, proto, sel,
5 f4 H( C8 x: } new FArgumentsImpl (this, sel)));% n8 M" v5 ~* A n4 O
} catch (Exception e) {2 B! T6 c6 u1 O( b U
e.printStackTrace (System.err);
2 f' c5 y9 |% V; V/ F3 V9 [9 i3 X }# }# u* Y# T( q; e- T6 t% T) Z
8 S4 ^9 A r- f% n8 f, S
syncUpdateOrder ();" t1 E' U6 S- i: t* Z6 Z; ]7 S
$ s- k8 }! L8 w- y) p
try {
! r6 H" L, `/ x modelActions.createActionTo$message
5 m* B: r; Y% Z: B V' c9 i (heat, new Selector (heat.getClass (), "updateLattice", false));1 Q$ b& _7 Y3 W/ y' i) b6 z3 k; V
} catch (Exception e) {; L* N- N$ u4 W* n7 x
System.err.println("Exception updateLattice: " + e.getMessage ());0 Z# t$ y" ~) |; |+ N3 m' E
}. k* d) w; _( ^+ `. I; j
0 Q7 M' \* D" ]) a; \
// Then we create a schedule that executes the
$ J* D# f7 W0 b // modelActions. modelActions is an ActionGroup, by itself it% t- l' g) r1 w; |2 W
// has no notion of time. In order to have it executed in* m, F% V, V( I8 I6 ]
// time, we create a Schedule that says to use the7 k% B. q! L4 [8 S7 C
// modelActions ActionGroup at particular times. This, i. U, r. H# Q; W
// schedule has a repeat interval of 1, it will loop every
; u2 t7 J+ M8 L // time step. The action is executed at time 0 relative to, M/ [3 a4 `9 f4 D3 @
// the beginning of the loop.
6 F" K8 N }. r, Z" H( l( m$ X
/ K! M- H1 s/ y) _! h* c // This is a simple schedule, with only one action that is2 M. c& y; i% j8 C# o" q
// just repeated every time. See jmousetrap for more
3 r9 C7 b$ K. r0 P/ a7 J // complicated schedules.
% ~1 X2 ^( [/ b% K7 \& F0 o, Y$ v & l6 b. B3 v6 D$ y: G
modelSchedule = new ScheduleImpl (getZone (), 1);7 ]& p8 u+ Q) c8 {! z
modelSchedule.at$createAction (0, modelActions);" a/ }) N& ]( a' q
( e7 W$ `5 E- q6 ?) A. T8 A return this;9 r; Y( m, a) l; K
} |