HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:$ N: |6 g# y& U$ x3 J
9 [( I% D% f' Q* c
public Object buildActions () {; m* B. f. B) ]3 }3 s0 q
super.buildActions();
5 K. l- @9 r+ t9 j7 {
; v3 w" Y; d: g' e, Y: G, U2 ?6 H // Create the list of simulation actions. We put these in8 ?7 K. t! j; E; G: a6 J% _
// an action group, because we want these actions to be3 c8 k @ c; e( o1 d) `' R4 Y
// executed in a specific order, but these steps should
5 m3 H5 @0 K/ ~1 V! e$ w // take no (simulated) time. The M(foo) means "The message6 v: a4 S3 @6 Z- ?
// called <foo>". You can send a message To a particular
- R5 W. C) c3 d' E // object, or ForEach object in a collection.
8 z3 y3 ^! Q) }- Z , d7 u# {/ v' R7 a- S/ H( Z
// Note we update the heatspace in two phases: first run
8 x* i3 C! @7 \3 r' _2 ?7 ~3 E& t // diffusion, then run "updateWorld" to actually enact the9 G$ J2 W/ D5 ?4 {, A f9 R- L2 d9 i
// changes the heatbugs have made. The ordering here is( _/ t- o* _ f) M
// significant!
* Q: p, a" c" {7 a, n. B6 o4 [5 b" N
0 {2 A4 `; P- I! @" x. c: x8 @ // Note also, that with the additional) b% N2 i4 f( f7 g4 Q6 U
// `randomizeHeatbugUpdateOrder' Boolean flag we can
' F) [+ r" @! t3 y- y // randomize the order in which the bugs actually run
3 k+ W9 Y3 T# m2 L1 ~" R // their step rule. This has the effect of removing any V) G: l" a8 S; q1 d/ ]$ J/ y
// systematic bias in the iteration throught the heatbug1 s) Z6 O9 J* D! C( [4 }
// list from timestep to timestep7 \! \( f v$ F& Z% a2 C2 [9 U
# d8 l! f4 @' {7 ]7 I; T) r: Y
// By default, all `createActionForEach' modelActions have
3 h" G% P' Z3 _- M" H! Q+ Y! \ // a default order of `Sequential', which means that the
! n% _& r( v8 _& Z& f // order of iteration through the `heatbugList' will be4 Q$ \# u1 f* b1 n$ Q
// identical (assuming the list order is not changed
9 |3 j' E# d& W8 g" T( b$ R // indirectly by some other process).; c4 P+ s% c# x3 h
6 [! L4 s* b" X: Y
modelActions = new ActionGroupImpl (getZone ());! b. j8 y6 I6 F+ V# B; P
/ h0 l( a& _- c1 {' m* h' \ try {
% m; t; Z( I d' h( m9 ^0 ` modelActions.createActionTo$message/ f0 r7 k$ v; }9 }
(heat, new Selector (heat.getClass (), "stepRule", false));
0 I. [; t) m" U* Z } catch (Exception e) {- E1 V* E5 G" n6 y
System.err.println ("Exception stepRule: " + e.getMessage ());. b& J+ x0 g5 L7 P7 t
}
' n% y1 w/ v9 R* e& i( U ~! Z j! T# d
try {
! {6 n; X# B4 }8 V Heatbug proto = (Heatbug) heatbugList.get (0);& t% P; T1 q" ~8 X+ ~9 R
Selector sel =
7 E" h) Z% X: C2 T- Z9 ^! J new Selector (proto.getClass (), "heatbugStep", false);
8 H' Q1 K/ p# v- B actionForEach =
) p: {) T: ]9 p z! l; a modelActions.createFActionForEachHomogeneous$call" m Z! H. `+ p/ F( g
(heatbugList,# |' J- R1 M. C+ w1 J( n
new FCallImpl (this, proto, sel,/ n- P6 n( k5 U p. i7 [
new FArgumentsImpl (this, sel)));! k, F! l+ L+ @* v0 Z
} catch (Exception e) {3 K! z) k: q4 M( V
e.printStackTrace (System.err);; \4 ?+ |, q& Z: S3 f8 B) i0 k6 X+ {
}
& W& ?+ N& K- s& p " s. R2 l0 Y9 u% K
syncUpdateOrder ();
' l' _) A5 k( Z; R7 _% x% o. S* B: s+ H5 z: t. n
try {2 \ d# V; [5 V/ Z, k' P8 |: }
modelActions.createActionTo$message
$ {) V- _; a+ ]- L$ } (heat, new Selector (heat.getClass (), "updateLattice", false));" d' f( [/ J& u0 e6 T7 W
} catch (Exception e) {# D! X) _; F0 W/ \* {1 E- e7 L
System.err.println("Exception updateLattice: " + e.getMessage ());
9 e8 V+ a6 o0 e" M& k }
3 R' a r" _% P% Q8 ^
. q. o- A9 G( e // Then we create a schedule that executes the2 _+ z+ J! X* R- _; U* U
// modelActions. modelActions is an ActionGroup, by itself it" i1 P: g; D: b8 h
// has no notion of time. In order to have it executed in2 t( s% K8 S4 W% y
// time, we create a Schedule that says to use the3 j) u% W& I8 W7 x) P% _( I+ \7 C H& Q
// modelActions ActionGroup at particular times. This( j% @5 H' ~; ~2 l7 M, G9 ?/ A0 @
// schedule has a repeat interval of 1, it will loop every
1 \: z$ s+ D; L0 |+ ] Z0 H0 [- W // time step. The action is executed at time 0 relative to
5 x% o8 d4 x) ^( O. ` // the beginning of the loop.
- w7 I' ~; _8 r3 W, Y8 A' y3 D
// This is a simple schedule, with only one action that is: Q7 T. e+ d8 E: q
// just repeated every time. See jmousetrap for more
% D" @7 Q2 F* g // complicated schedules.3 i: a' V4 s. _
$ ]6 o3 P. v/ n% S, H# ?! J P' o) K/ h
modelSchedule = new ScheduleImpl (getZone (), 1);& n0 c$ E7 C4 x; o, ]
modelSchedule.at$createAction (0, modelActions);. t8 F7 Q' A% Y6 p3 ~0 V7 y( h
k; ], S$ c0 k- ~. c& K
return this;* |* ]! E4 ~8 E1 ^
} |