HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:- L% f; [2 W/ O( \# R6 ~4 D( K
# S+ S: h! F3 A* i& z \9 G
public Object buildActions () {
; q6 ~% A+ ^( J2 y- e super.buildActions();
- M1 u9 s- q- J$ J2 A' |9 }4 @8 r 0 N1 e6 O8 O$ S6 p
// Create the list of simulation actions. We put these in+ R' Y2 Q9 z: D$ g1 {* L/ _: k
// an action group, because we want these actions to be% X/ k# ~2 `& A! A
// executed in a specific order, but these steps should8 A6 Q9 U! m& a5 W8 ^( x s
// take no (simulated) time. The M(foo) means "The message
4 o* R J) M' D2 X5 | // called <foo>". You can send a message To a particular) J/ Q3 b* ^6 t) L$ G. j6 s
// object, or ForEach object in a collection.& |; j: d: b& R% o- k
" b0 F6 h- k* v! W+ W // Note we update the heatspace in two phases: first run: I+ S! H8 i( W+ u
// diffusion, then run "updateWorld" to actually enact the# r, K p) f7 Z7 Y
// changes the heatbugs have made. The ordering here is
& w5 F; Q0 b0 D0 A* R3 B // significant!2 `1 P- s/ w+ H$ N/ h1 x
- @+ b$ j( q U1 @ // Note also, that with the additional) E4 g; P$ o1 ?
// `randomizeHeatbugUpdateOrder' Boolean flag we can4 n9 K l3 I5 r- H1 `9 r
// randomize the order in which the bugs actually run
) Y' g' v( d% H // their step rule. This has the effect of removing any
, X8 z3 O4 p+ _$ g- W* M) a4 h% l // systematic bias in the iteration throught the heatbug
( k/ X8 D% @: [& f // list from timestep to timestep
, z! C _* ^$ v8 F 6 I# d: E2 L+ c- X4 G- Y3 I/ s# c
// By default, all `createActionForEach' modelActions have
5 W) H- L6 v2 O" r, t // a default order of `Sequential', which means that the
6 k4 _. h; @) {5 Y1 R7 } // order of iteration through the `heatbugList' will be1 X' H7 d2 i, H5 C5 G
// identical (assuming the list order is not changed
( g7 O& e. U4 F // indirectly by some other process).4 i( U4 H7 J3 P: w' L& c
$ V$ H* K0 R: n( U* l% F9 P modelActions = new ActionGroupImpl (getZone ());: h; w# X2 }( u; t. c/ g
1 B5 j& R- x& E1 P
try {$ @3 u6 `! N+ r5 i! W) E
modelActions.createActionTo$message$ }2 p5 [; u0 I2 `9 q3 Z, x3 K
(heat, new Selector (heat.getClass (), "stepRule", false));7 V5 X5 M5 t, A8 K# J
} catch (Exception e) {
: }6 h# g$ J. ?; J2 Z w$ E- t System.err.println ("Exception stepRule: " + e.getMessage ());
" @0 ~( h8 [# F8 a* T; p) h }1 J: E( \, s# Z8 G
+ Q: X$ W. [9 u
try {
: c" k2 g1 _ z Heatbug proto = (Heatbug) heatbugList.get (0);$ q( Z$ l. e2 L
Selector sel =
T$ U; {, N, G2 V6 M( c new Selector (proto.getClass (), "heatbugStep", false);7 \0 m' |9 A+ k
actionForEach =0 |% @# z% l; Y" y' h
modelActions.createFActionForEachHomogeneous$call
& Y+ m0 j$ I( t( H (heatbugList,2 G; I, I; u2 ]! ?3 k* Z1 L
new FCallImpl (this, proto, sel,2 v ]% h, Y+ M1 n' w. P
new FArgumentsImpl (this, sel)));& x [* p+ o( F& \& u% F
} catch (Exception e) {9 a9 C7 d# S. |1 l; _' R
e.printStackTrace (System.err);5 b0 C5 t9 j7 v3 N7 ^; S$ Q& B
}# R4 d: ^/ A0 P0 X6 \- J" T6 y% T
: {6 L: b( ^0 f( J
syncUpdateOrder ();9 o' W! J Q- N: [6 F
L+ O$ [: E+ i8 F0 `
try {( j& ?5 i, R0 d# W4 V
modelActions.createActionTo$message
7 N2 q; r M" T0 Q; q- G( _ (heat, new Selector (heat.getClass (), "updateLattice", false));- o. F& R0 | |$ |% ~
} catch (Exception e) {
) v9 I0 k5 k; h System.err.println("Exception updateLattice: " + e.getMessage ());
& O4 r2 q: x) B" [$ L4 Y; R6 C7 C }
# D* E# q5 S. }/ |' F' `" i: d+ j8 {
( K, {( G- |! l // Then we create a schedule that executes the
) v6 @7 _) x& Q // modelActions. modelActions is an ActionGroup, by itself it7 L: J D5 [3 S1 j& e" o7 f6 X. v
// has no notion of time. In order to have it executed in
+ Y6 i' E4 M5 a6 d6 Y // time, we create a Schedule that says to use the
1 |6 b+ J6 q. k% Z# {! |1 q // modelActions ActionGroup at particular times. This5 |9 P9 \ ?+ F
// schedule has a repeat interval of 1, it will loop every$ D* m, Q$ B [
// time step. The action is executed at time 0 relative to1 m8 R+ m) `7 ]2 V Z9 i
// the beginning of the loop.2 A4 x5 Z( Z1 R9 Q/ D* T: C
( a& s+ A0 R1 k) g" @ // This is a simple schedule, with only one action that is: w9 o% N7 ~8 v; N! ~- R
// just repeated every time. See jmousetrap for more" ]# H# K, N7 w
// complicated schedules.
k# P" w0 n( h3 n+ E% ~
: p. J0 p' Q6 i( H modelSchedule = new ScheduleImpl (getZone (), 1);
t7 U8 }% Z! e modelSchedule.at$createAction (0, modelActions);
" M% V0 c% l; `3 @+ |/ c) i # B1 @: |, j) b" i( v* a
return this;4 F% ?: }& N" U; }7 L2 e1 o/ q
} |