HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
4 c& }- V4 e: p! C$ ?. y1 m9 w- N o
public Object buildActions () {. p' l! o9 u4 N
super.buildActions();
7 H- d4 a3 {6 P+ ]6 \5 p% f) Q 4 l/ N. k$ o9 e4 ?+ P0 [
// Create the list of simulation actions. We put these in
: v& ?9 a/ F5 s3 n // an action group, because we want these actions to be
9 e1 U4 I) v. w% J( M // executed in a specific order, but these steps should# G2 s0 S, p$ s% E
// take no (simulated) time. The M(foo) means "The message# }; K* Y w" S6 m
// called <foo>". You can send a message To a particular9 ?7 d7 m K( h, B/ I; g. c: {) Q
// object, or ForEach object in a collection.
8 m$ g9 Z; ?3 L _$ S
- x4 a) O. B+ V3 B // Note we update the heatspace in two phases: first run
2 \8 L$ v6 |% |, c, o // diffusion, then run "updateWorld" to actually enact the5 Z# E5 ^7 f2 v4 l# x. p
// changes the heatbugs have made. The ordering here is
9 U/ H( I2 v3 @ q; ]) x // significant!
: N+ r5 w0 z+ _7 T3 L4 h& A; I# d : H8 |- n7 C- Z1 s# A
// Note also, that with the additional1 f7 e9 s7 ?1 i: }- v6 S
// `randomizeHeatbugUpdateOrder' Boolean flag we can
$ Z, e0 g& E% E) v' v5 X5 x // randomize the order in which the bugs actually run
# I5 O: A7 }3 i. K // their step rule. This has the effect of removing any
# E, k0 K# ~; j" k // systematic bias in the iteration throught the heatbug
2 Q* h( J- b+ Q! P // list from timestep to timestep Y) _- D9 l7 I$ h1 t' j& H
/ Q; A* r. Z9 b% j // By default, all `createActionForEach' modelActions have
9 A+ p( T) @9 L/ _* f1 l // a default order of `Sequential', which means that the
! ]( d8 L* j, d6 e+ V // order of iteration through the `heatbugList' will be
7 i$ O" u8 E% \6 L: w j' X2 U; L // identical (assuming the list order is not changed
! I2 Q: K4 d# u4 O9 l/ P // indirectly by some other process).% ^; Y8 T- g4 {1 U
7 u0 l; N9 x$ ~* p. o3 S modelActions = new ActionGroupImpl (getZone ());
- A( M, r( N b6 Y! a& s! J! c' W/ M, P( c
try {: k8 Z! S6 f/ T; }$ T
modelActions.createActionTo$message
: I. ^5 A" K5 b: c- m% W (heat, new Selector (heat.getClass (), "stepRule", false));
& G1 M. a2 w. e9 N3 D } catch (Exception e) {- b4 |4 C+ J/ f/ s. E0 d7 H" `
System.err.println ("Exception stepRule: " + e.getMessage ());
9 Z% D' B! B9 }3 Z% g5 o- A) o }- I h$ W+ K0 P
+ J; z0 ^& ?$ [; A7 N0 g; r* W
try {
7 K8 u. i5 y! F) w. {- ] Heatbug proto = (Heatbug) heatbugList.get (0);
& K, X& j; J1 f% s8 s( L* a. q' [ Selector sel = / m% L7 X, c! k! [
new Selector (proto.getClass (), "heatbugStep", false);
+ n* g, ?% w5 [0 n. X actionForEach =
8 I4 j" f! V: G1 ]- [* L& b modelActions.createFActionForEachHomogeneous$call* T' g- h/ t" d! _
(heatbugList,
& \6 _4 R6 Z) } new FCallImpl (this, proto, sel,- d0 h0 R% n1 E" `# {* i
new FArgumentsImpl (this, sel)));+ ~ }! {& [. O
} catch (Exception e) {
2 J& M4 `3 s' A; I0 ~ b e.printStackTrace (System.err);7 L8 |$ Q- m% H: h% v
}" x4 ]( x- d' q& K# ?
: M3 `% e- k+ }. l6 s syncUpdateOrder ();9 J! u: K0 l7 g7 B! R/ A
: O+ @7 c! s. f X, }! P
try {
{9 z. J/ i$ V8 v modelActions.createActionTo$message $ j- x: \( w! a: W
(heat, new Selector (heat.getClass (), "updateLattice", false));
# T h, R1 X* S% a } catch (Exception e) {
; q; G* |3 y: R8 B* n2 b! S7 X; L( _( H, H System.err.println("Exception updateLattice: " + e.getMessage ());
9 N' `0 o0 u( @( p6 ?- C7 L }0 K- u i T, S4 J a
" k! d7 Z8 n* ?; V; W* h# V$ } // Then we create a schedule that executes the
+ f, b2 Q5 \7 h1 O( j0 q" W* } // modelActions. modelActions is an ActionGroup, by itself it' M6 b2 p! N6 h
// has no notion of time. In order to have it executed in4 j, p* ?5 }1 q& w8 C z
// time, we create a Schedule that says to use the
9 _. W' y7 L) ?2 @* Q# z/ ] // modelActions ActionGroup at particular times. This
$ I2 a v0 k0 P9 O: _+ c9 ^ // schedule has a repeat interval of 1, it will loop every
3 D8 X! G, t) R8 \7 x8 L, Y // time step. The action is executed at time 0 relative to
- M9 Y) `9 X0 J, Z$ T1 } // the beginning of the loop.
0 } C) I4 Z8 w) L0 W7 H& Y' n$ B1 z% O/ e, G6 ]2 Z
// This is a simple schedule, with only one action that is
2 w; m. T' D' y // just repeated every time. See jmousetrap for more. ~$ e8 C. k( I: c% a6 u J
// complicated schedules.
7 \' J9 C# _" t9 w2 W1 D
5 L5 a2 G% @0 G! r" o. | k4 X$ p modelSchedule = new ScheduleImpl (getZone (), 1);4 K: Y+ ]' l$ y& p6 A+ x
modelSchedule.at$createAction (0, modelActions);
! J$ c. T$ y# i$ v+ u9 D 8 h0 Q3 Z- @0 h: h' b7 J! [
return this;
2 O ]. _6 D4 ^' X } |