HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:; _4 O5 h' c+ f- H; J
: x) h% k5 s) r public Object buildActions () {6 \8 [& }# [8 p6 y7 [9 x2 G
super.buildActions();
7 T+ j) V3 [1 y' i2 ] 8 V3 _, h% E4 N
// Create the list of simulation actions. We put these in; B( F) v8 _& a# j' ` h+ a
// an action group, because we want these actions to be E b& L) S6 @8 t; H, R
// executed in a specific order, but these steps should* ]" t# n( P- ~2 e1 S
// take no (simulated) time. The M(foo) means "The message+ ^! J. h! l0 s) e/ w( t
// called <foo>". You can send a message To a particular
9 q8 P2 ^& C: @- A2 a // object, or ForEach object in a collection.4 c& N) {3 H. ]: |5 t* H
6 a. P) v( \- y5 U
// Note we update the heatspace in two phases: first run( o1 G2 P5 v7 k; F. `: x& O" b
// diffusion, then run "updateWorld" to actually enact the
- |1 S" F" N3 |& L8 b& \ // changes the heatbugs have made. The ordering here is
7 c& T4 t( K* O& E7 j // significant!
- N/ s8 B9 V7 {" Y9 t
9 J6 V" \6 T/ P7 M! w // Note also, that with the additional
, f5 v# c3 S2 h1 Q9 T7 T3 x // `randomizeHeatbugUpdateOrder' Boolean flag we can
8 a# X, \2 J K7 k# Y // randomize the order in which the bugs actually run+ {; d5 q2 t* @; e. N* p6 V1 a1 y
// their step rule. This has the effect of removing any
9 S4 r. U! k1 Q6 z, m, X // systematic bias in the iteration throught the heatbug8 N8 {) k5 T$ z) Y2 s
// list from timestep to timestep( x$ a5 V" J, \ S) k( T X) p0 v
9 d5 d6 h6 |; C0 R! r2 C6 _ // By default, all `createActionForEach' modelActions have
! m" i/ A& g7 R2 ? // a default order of `Sequential', which means that the# q( J, T1 {" X5 d, b
// order of iteration through the `heatbugList' will be6 @4 n; Y) C4 @. {
// identical (assuming the list order is not changed% ?; c; [! t# Y: f0 p4 G; Q7 p) a
// indirectly by some other process).. u& q% o5 J( j. z8 `6 Q5 x
- V8 Z* j* e# k
modelActions = new ActionGroupImpl (getZone ());" b: E. o& E& r3 A5 [
4 t( h2 z1 b& i0 z4 Q( R& V9 g try {
+ r5 J% A1 o; {. x, g% f$ h modelActions.createActionTo$message
; m7 @9 Y( j& R/ S# C (heat, new Selector (heat.getClass (), "stepRule", false));
1 h& {3 E4 a3 h1 j# v( W& ]- ]3 N } catch (Exception e) {7 P3 e9 R- o2 |1 |! u; o
System.err.println ("Exception stepRule: " + e.getMessage ());
3 c* g+ M! \0 Z$ H4 m9 s/ O }
- l3 G. ^/ e% {$ c
4 [5 N' v% d* \9 b5 K O" ^9 M try {
7 v# a# t1 e- S8 ] Heatbug proto = (Heatbug) heatbugList.get (0);
/ l( f6 E. c C Selector sel = 0 Y& S; f K2 [" ?0 h A
new Selector (proto.getClass (), "heatbugStep", false);0 x% w* ]8 i& o8 H2 b. _# Z. D
actionForEach =
# a g6 K h4 I- J modelActions.createFActionForEachHomogeneous$call G7 X; M& S8 Y
(heatbugList,8 j) M/ ^, H8 P' T F) D
new FCallImpl (this, proto, sel,
' N" T3 g' `2 R6 y7 n new FArgumentsImpl (this, sel)));6 I" d0 U/ [% G) {7 f
} catch (Exception e) {4 V2 R$ D& T2 W; \) E; p3 @
e.printStackTrace (System.err);& ] k# j: Q2 u2 M8 {
}
- L* y/ D; p, L- T; n8 f/ u ; X5 U( n! t3 F/ m( i$ A4 t- Q
syncUpdateOrder ();
" O+ d, C& h& Y
2 p9 k* N, t9 I( u5 e: ~. S5 H try {. f3 x; N, U5 _6 O0 n& K
modelActions.createActionTo$message
( n0 s' |- g8 l (heat, new Selector (heat.getClass (), "updateLattice", false));
0 {! I, p, j. Q* I } catch (Exception e) {8 A% V- {. c+ `4 M
System.err.println("Exception updateLattice: " + e.getMessage ());
( r& U v8 f! s% g: E- v }+ Y! V( \0 V8 \; V8 e" m
8 u* M6 k5 X: |" ]
// Then we create a schedule that executes the
/ B# e0 D9 { s- w6 I0 W( G // modelActions. modelActions is an ActionGroup, by itself it
3 ^! K! F4 u6 g% @& y // has no notion of time. In order to have it executed in
" O a( M% p: R' N% G- { // time, we create a Schedule that says to use the
0 [! h1 d5 _/ M: d3 H* p // modelActions ActionGroup at particular times. This* o0 s" p! d0 D) ^( m$ B
// schedule has a repeat interval of 1, it will loop every
/ e* [; h c& i' A // time step. The action is executed at time 0 relative to* e& E/ K) U S& r0 ^' X
// the beginning of the loop.
: a1 Z% S- {2 @( O1 l- i1 w
3 i& e7 j4 a& ~. v! J // This is a simple schedule, with only one action that is* y0 ?8 {, d' o) d4 d: g( }
// just repeated every time. See jmousetrap for more
# {6 c% s# b7 t8 `: | // complicated schedules.
$ H+ C. t' |1 U; l% v4 A) ^ * y9 X% t% t. X J, e$ x0 v" P& t
modelSchedule = new ScheduleImpl (getZone (), 1);9 m! @! W6 b- G; l
modelSchedule.at$createAction (0, modelActions);
. \/ ~) K# ^( \0 a9 X; N
6 U8 y/ R) x6 g4 j return this;
8 `7 P, y8 @$ Q: m2 L" R } |