HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
2 _* S _/ n' |: q
1 h$ m! [. n! I9 g# ^ public Object buildActions () {
. `: ^. `! g& f' g7 t! Z super.buildActions();6 Y: ^/ l. S7 j2 y
: t6 S( X5 q. V5 o // Create the list of simulation actions. We put these in1 X9 R. Q* s; m2 R+ G1 Y
// an action group, because we want these actions to be7 D D8 D( d! F- ~
// executed in a specific order, but these steps should
8 B# g* Q4 }$ \) m+ D // take no (simulated) time. The M(foo) means "The message) P! P) j! A/ V. G
// called <foo>". You can send a message To a particular8 L2 |) d9 s1 E6 _
// object, or ForEach object in a collection.1 K3 f3 c* k& i# E, o, V
- M8 {( @; g; f/ x; I // Note we update the heatspace in two phases: first run
7 J+ W9 h. A: t2 x, c // diffusion, then run "updateWorld" to actually enact the
% e5 m$ t7 q3 M$ @ // changes the heatbugs have made. The ordering here is5 \ A8 O/ A% p/ M! n0 \, z
// significant!( g7 D& F9 N M3 Y
5 Y( |5 l5 q/ ^1 ]- {
// Note also, that with the additional
. o) N1 z- R' H/ B0 ]4 K; L // `randomizeHeatbugUpdateOrder' Boolean flag we can" I% g$ m: z8 \ W" i; j1 B6 p7 f# T
// randomize the order in which the bugs actually run0 A/ S! L8 M. h% i* r# i4 [
// their step rule. This has the effect of removing any' a: o+ @* e2 A; u0 c
// systematic bias in the iteration throught the heatbug
E+ Z8 V1 W/ H( G" v // list from timestep to timestep
. e+ E' n/ v8 U* ]! V , v; K( x; C$ `- I
// By default, all `createActionForEach' modelActions have
. n* T5 T6 D6 `+ r- Q // a default order of `Sequential', which means that the
* }' x- A& y# d, A y9 Z8 t // order of iteration through the `heatbugList' will be! q1 c& z( Q; D+ x+ b& Y, ` ]
// identical (assuming the list order is not changed0 d/ @3 Y! i: X Z1 E
// indirectly by some other process).2 f$ _, k+ S% O; Q5 Z
" k* T' U" y" L# j, t
modelActions = new ActionGroupImpl (getZone ());; b- H2 t' G+ s. l" f. n
! j1 B! s7 O/ C try {; G3 |" Y: O$ j8 G
modelActions.createActionTo$message
' L5 i5 p0 Q- [2 l+ ~( E8 W (heat, new Selector (heat.getClass (), "stepRule", false));
4 s. g; r3 p4 `; N6 a } catch (Exception e) {8 o) i% w3 a; n8 Q) ^' {; P0 P
System.err.println ("Exception stepRule: " + e.getMessage ());5 E! j; i {1 ~3 P, |
}# r9 \* _: q# {3 k
: B% c1 w" v. l try {% |( D6 o7 J% B
Heatbug proto = (Heatbug) heatbugList.get (0);
9 d- E$ p6 I( o0 e! g3 s Selector sel =
" l& v# C: g Y" F new Selector (proto.getClass (), "heatbugStep", false);: F1 a1 q: X# T6 a/ X8 ~0 q8 c1 W P
actionForEach =' ^) Z. p n/ Q, { S. l5 N( w) V) U
modelActions.createFActionForEachHomogeneous$call' J$ [+ R: u; |/ ]0 {* B e
(heatbugList,
$ V( }3 r) q2 o+ k- }4 Z& M0 y new FCallImpl (this, proto, sel,; v7 G6 L6 S* e& N$ X2 C
new FArgumentsImpl (this, sel)));
% g, W/ ]5 }( I; X m } catch (Exception e) {% t$ r( s3 J1 l
e.printStackTrace (System.err);
1 M! L- Q, V' ~! @. n0 U& m' d4 [# t }
& o" t0 @- Y; v5 j. \# B* ~: {! N: k
* G- o5 c$ w% G3 v# _3 o syncUpdateOrder ();
9 M. ^1 ^6 ^3 h) e2 ]9 G9 }
+ `: U& x6 G9 [6 g; I try {* a X ~6 H5 N. @! J b, z( c
modelActions.createActionTo$message & k# O6 J$ O" f6 x8 y
(heat, new Selector (heat.getClass (), "updateLattice", false));) l* U4 s, v+ e+ h% Z9 {# c0 i
} catch (Exception e) {
0 P, J# a: j4 k& N! P/ `% r System.err.println("Exception updateLattice: " + e.getMessage ());; ?) N/ e0 R. _& K4 c& K
}# _. D( E) o2 P5 i( a5 N2 z9 j
9 {0 [5 b- x( V) Z
// Then we create a schedule that executes the
4 i) j ]: z$ x8 x // modelActions. modelActions is an ActionGroup, by itself it
9 G) a2 o6 ~9 |% f! n1 T4 c // has no notion of time. In order to have it executed in
+ X( |9 B b" H, Q // time, we create a Schedule that says to use the
- f; b4 O7 S( Y* i( J1 P( {! y // modelActions ActionGroup at particular times. This
3 V2 H1 K/ j7 \) x, ] // schedule has a repeat interval of 1, it will loop every# y4 J. E. S' h& E" n( E% G
// time step. The action is executed at time 0 relative to
4 ~: V' ?% D5 `5 h+ c* y$ ^6 K // the beginning of the loop." p7 J+ W2 K ^: z S! i
% i/ E0 l& Y2 Z, w! j1 k! h // This is a simple schedule, with only one action that is
# b; o! `; b1 r9 v- K B o // just repeated every time. See jmousetrap for more! Q. \8 |' p* X' A( Y
// complicated schedules.; D( ?& h2 D: X8 O2 J- u. g2 f
7 x9 f$ r7 m: V7 V modelSchedule = new ScheduleImpl (getZone (), 1);9 o' d( W& {" j7 Z. p
modelSchedule.at$createAction (0, modelActions);' @5 K$ r6 A1 C% j" C! }& l
" P/ W2 I4 d5 [3 w" _* j) F) ^4 o return this;
* \" V8 V* {8 M. @( r } |