HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:0 ]% P) _" K5 D( u
. d" D1 u$ N) u& ^# E( h public Object buildActions () {
$ n& s8 J4 F7 s. ` super.buildActions();
; S" q$ s b4 {" |/ e5 l
) e* x) O+ X: g& { // Create the list of simulation actions. We put these in
% m$ Z7 x- ~3 m1 ?3 e+ S // an action group, because we want these actions to be( F1 N P# q4 G% }
// executed in a specific order, but these steps should {/ p5 y3 V# m% @( Y
// take no (simulated) time. The M(foo) means "The message
! M1 O! m2 P% c, C, ` Y9 ~1 I; K // called <foo>". You can send a message To a particular4 T: m$ r! R* D& X; }0 N8 m
// object, or ForEach object in a collection.9 m. R7 D; o# K& N" w6 F. S
: X8 Y. h8 V$ N! s! U; _ // Note we update the heatspace in two phases: first run6 r. J6 w# H$ }! _1 @: G
// diffusion, then run "updateWorld" to actually enact the
, d$ [: V7 y) G4 W // changes the heatbugs have made. The ordering here is
$ v9 C6 ]$ S( }& B/ r+ H6 } // significant!2 s7 D# h8 W3 x9 q
3 g, g3 m( |2 _- N U+ @3 h) K+ j
// Note also, that with the additional
0 R5 @" d/ v9 E: z // `randomizeHeatbugUpdateOrder' Boolean flag we can3 [$ r" P" r9 z0 i: U N8 w& F9 \
// randomize the order in which the bugs actually run
4 q" ~' @- l3 J: } ? // their step rule. This has the effect of removing any: z5 T! w! z8 y4 M, Y3 \1 u1 o; T
// systematic bias in the iteration throught the heatbug- X, Q. |- e, j" `. p* B0 p8 ~* t
// list from timestep to timestep
' s- X7 h+ t/ l6 ]: z. I ( S$ J- v5 b: h/ O# z' @
// By default, all `createActionForEach' modelActions have# {, x' D0 y! {% M! T$ j. h
// a default order of `Sequential', which means that the
/ F% p+ w0 Y- h# z6 ` // order of iteration through the `heatbugList' will be ?$ e0 O) R8 ` f$ Y! `
// identical (assuming the list order is not changed: ?* D! @ R" l
// indirectly by some other process).
+ U+ A+ n+ p+ c: ^8 ^8 s ^ ! ~# |' t) ]7 u- v$ N* K7 z+ r
modelActions = new ActionGroupImpl (getZone ());; k3 [- e8 W0 U* Q
6 r J- N: K9 |" C
try { c2 B: d3 A) B1 r4 _
modelActions.createActionTo$message
/ |( H3 F2 n L# g- P8 r" U2 U (heat, new Selector (heat.getClass (), "stepRule", false));
" }% I# G1 c7 Z& n } catch (Exception e) {& O' y- O* u+ @9 Y s7 G K" Y
System.err.println ("Exception stepRule: " + e.getMessage ());: Z$ ]7 L, T9 ^. c9 f& k/ u/ a z
}6 p+ N* s2 }9 a& g# B
! A( T) T5 O* e3 x7 W5 q try {
. L N- I5 U* W Heatbug proto = (Heatbug) heatbugList.get (0);4 S; @+ Q8 o6 e$ }- c" R
Selector sel =
5 i( j$ Q% t9 \ new Selector (proto.getClass (), "heatbugStep", false);: I* m: U' w" L- u0 M% S& ~
actionForEach =# P! P. |2 R6 u9 G
modelActions.createFActionForEachHomogeneous$call/ @- N; U- S. \1 w3 f) A- v1 ]; Y
(heatbugList,( ?2 w B B; u& Y+ f6 T( Z
new FCallImpl (this, proto, sel,
% u; w K0 Z$ ~( J/ ] new FArgumentsImpl (this, sel)));
9 M& }' m4 R1 [9 ~ } catch (Exception e) {
2 r- r4 V0 o% S7 V* x1 z" R6 z+ O6 e e.printStackTrace (System.err);
- x1 m- _( }8 V) i3 a- O: u( l/ r }/ V Z8 W% a. N3 N: W2 h# O
8 n) m" |0 ?8 O0 ^, \) i: v
syncUpdateOrder ();
; k r6 z9 I8 B4 Y
) [8 k% n+ v" G$ i, A1 V3 g7 f1 \ try {
: r( R4 b, D7 M) k( i; O4 Z modelActions.createActionTo$message
% H: ~* p9 ~' l5 X (heat, new Selector (heat.getClass (), "updateLattice", false));
3 e2 ?4 T- B* o5 } } catch (Exception e) {6 Y: Y- J& _ s- ], |
System.err.println("Exception updateLattice: " + e.getMessage ());
# b. T% C, g0 Y4 `8 l P1 k }& X1 `6 x/ H1 j _
$ _0 E; W$ l. ~5 S // Then we create a schedule that executes the
" a" H3 ^6 g( Q) a5 v // modelActions. modelActions is an ActionGroup, by itself it' d8 L7 x: i0 [- M
// has no notion of time. In order to have it executed in
; f4 X9 Y: C, F1 j9 v+ l // time, we create a Schedule that says to use the0 i. a) u5 K2 s9 _9 F' p
// modelActions ActionGroup at particular times. This
9 J$ q2 ]/ d' C! ` // schedule has a repeat interval of 1, it will loop every
0 Y! S3 j6 @+ m // time step. The action is executed at time 0 relative to
" v6 c2 t, w9 s( G4 J2 \ // the beginning of the loop." P9 j1 a/ s; k& A$ T
5 b. D1 S) ]6 E& q1 a4 W/ W" I5 W // This is a simple schedule, with only one action that is3 @% ~% U9 v& \- F
// just repeated every time. See jmousetrap for more( t: @4 H. ~! I4 ^ E: ~6 q: B+ o' @; }
// complicated schedules.5 {5 E. L# j1 _
) [7 o% u3 J0 _" K8 D' A
modelSchedule = new ScheduleImpl (getZone (), 1);
+ x4 k9 C3 s% E, ?. V6 P6 ? modelSchedule.at$createAction (0, modelActions);
! X5 E6 i1 s2 v" y5 e1 [6 `# T ; A* N1 j; X$ Y" [4 T
return this;" q+ n/ H5 K; J/ x2 F
} |