HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
9 j0 G2 i( b- A" r* c# p% _! I2 G" l' J5 Z0 ]' G
public Object buildActions () {
E6 {7 t5 R6 [* y' Y" |- J super.buildActions(); v' N5 F4 d3 \. s6 C+ N
1 m* o9 a; x, j7 e5 N8 [' ?
// Create the list of simulation actions. We put these in
# g! Y9 Q1 b M // an action group, because we want these actions to be
8 W! F" [! P* I$ s // executed in a specific order, but these steps should
. O1 L1 a+ X$ t; E7 t: I* b // take no (simulated) time. The M(foo) means "The message+ W+ Y9 M& w, E% s' S
// called <foo>". You can send a message To a particular8 G* u, ~( F+ I( l
// object, or ForEach object in a collection.$ u' u( C$ o% ?
3 L9 c# @ i/ u: Y2 z; p# m5 R // Note we update the heatspace in two phases: first run6 b4 w* K1 T/ [! M
// diffusion, then run "updateWorld" to actually enact the
+ J4 A0 r: ~% z1 ~- k // changes the heatbugs have made. The ordering here is
\1 x4 _; o* T* y5 d0 }- I0 S // significant!, Y" a+ a4 ~, [/ V/ i0 }
/ T: ]9 v5 }1 w$ c2 W# a
// Note also, that with the additional* Q0 U, K0 \3 ], f. t$ F
// `randomizeHeatbugUpdateOrder' Boolean flag we can3 W0 N5 `( d, Q' |+ T$ d
// randomize the order in which the bugs actually run3 }& U ?7 E6 @
// their step rule. This has the effect of removing any
5 n* I( l( p+ e0 |) M // systematic bias in the iteration throught the heatbug: N0 z z- f4 k, I. j6 I! |
// list from timestep to timestep
+ r& i7 k5 i4 [7 [2 K6 N& E# H% U
5 m8 r! P& N5 s+ J$ N // By default, all `createActionForEach' modelActions have& H* p4 c: ?7 d- N# [3 D6 X
// a default order of `Sequential', which means that the3 r2 N: e9 g# s
// order of iteration through the `heatbugList' will be
8 W# s$ h/ e% w1 _# f7 A // identical (assuming the list order is not changed
7 z2 h& l X. e0 F- R // indirectly by some other process).: c# |6 s. ?+ x: M, H* z( d
! X h/ s( B% B& f modelActions = new ActionGroupImpl (getZone ());1 d, B y3 D# p: }
, ^6 o/ @ D: h9 r8 }
try {
* e; O! F- Q2 O5 H% t modelActions.createActionTo$message
; R( A! [3 e( U (heat, new Selector (heat.getClass (), "stepRule", false));
( n7 c( [/ X( E+ j } catch (Exception e) {& [5 s3 Z0 w' E! ^9 b/ b+ N
System.err.println ("Exception stepRule: " + e.getMessage ());
* g$ G. y5 n8 P1 n K9 i }
* w3 Z& c# e2 M- u5 y$ \$ i( O8 x- Z$ Z+ F
try {
8 u, H" j4 \3 S; G9 j$ w, b2 _ Heatbug proto = (Heatbug) heatbugList.get (0);$ X, z, C* f0 c$ y
Selector sel = ; l* x) m9 j' B
new Selector (proto.getClass (), "heatbugStep", false);
: k2 E' q A7 N" L9 p, V3 h) U actionForEach =, G; }' {& G2 u! l4 d" s% |
modelActions.createFActionForEachHomogeneous$call
8 | B. ~% c1 u o (heatbugList,
) A' c' q" w+ p/ u) ] new FCallImpl (this, proto, sel,
0 X8 r+ d+ E; j new FArgumentsImpl (this, sel)));! T: B1 B* N, w. E/ L! P
} catch (Exception e) {; T6 q: u) {! @7 E1 X$ M
e.printStackTrace (System.err);$ [7 p2 _/ r6 u4 \
}& F/ \5 `7 Z2 E
$ v D- p3 ?4 q$ W4 [8 K6 S, E$ c
syncUpdateOrder ();: f+ }9 ? t8 T
! n" y. V5 }& F& n/ x) B
try {
& K% |4 P G4 H) |; x5 K1 ?- U) v modelActions.createActionTo$message / r& P& e% d7 y5 G6 Z
(heat, new Selector (heat.getClass (), "updateLattice", false));6 w! z. L* u! F
} catch (Exception e) {
5 R* n. Q4 |) F: S7 N System.err.println("Exception updateLattice: " + e.getMessage ());
: Q W+ L3 r: C6 _- V: c }
+ D( D) d9 B) v( D2 S5 {
! ^, L7 H D# t // Then we create a schedule that executes the/ V1 f5 X2 [* b4 B$ }. v7 ]; R7 K
// modelActions. modelActions is an ActionGroup, by itself it
! C" F2 f4 x# X# y! z2 ]- N0 ] // has no notion of time. In order to have it executed in5 N; s0 T1 S5 H2 C J
// time, we create a Schedule that says to use the* f, B. E n" T, E. H: ?! d7 A) u
// modelActions ActionGroup at particular times. This
' D* D" k0 Z! z* H // schedule has a repeat interval of 1, it will loop every' k, L" t: R# u- H$ P% R: i
// time step. The action is executed at time 0 relative to
5 b0 O" @$ l. k) H // the beginning of the loop.
+ M/ Y9 D, u7 }' B% d8 }8 ]5 K6 I& S, E, L
// This is a simple schedule, with only one action that is" O/ P9 V9 @" A8 r
// just repeated every time. See jmousetrap for more2 j9 ~: H! y6 E! E0 `5 ~
// complicated schedules.
x |1 l, E0 o2 t/ T& F 8 ^" ?& l! K3 x! T. H" `( {( S0 |
modelSchedule = new ScheduleImpl (getZone (), 1);# g) n/ c) ]& u4 o3 t7 s' d
modelSchedule.at$createAction (0, modelActions);* Z# n: W/ f, H% r) r( d7 f( R
( k6 p0 Y- f. f5 K/ u2 z return this;- O3 A' F# d# W& \
} |