HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:- P8 p# Q$ }( F# \; S4 Y
& n) P# k& E* E% c9 t public Object buildActions () {8 X: `. x+ e2 E* X
super.buildActions();
9 [- P: g+ d7 n2 N
2 a1 M3 I: K! n( d# Z. r // Create the list of simulation actions. We put these in
$ E$ k6 R) ]* Y6 P1 v% W' s // an action group, because we want these actions to be
5 L, M k& o* I // executed in a specific order, but these steps should1 w8 T. F7 Z! T. [, y( K
// take no (simulated) time. The M(foo) means "The message& ^* [2 v9 r5 V" n! E: j% h' G
// called <foo>". You can send a message To a particular" l( B- J1 c1 G7 B
// object, or ForEach object in a collection.7 q' _6 s* X( v1 _+ M$ B1 ^
3 x% j+ Q0 m$ C& E4 {! c) c // Note we update the heatspace in two phases: first run/ y- j* t5 p0 z; p& L4 r
// diffusion, then run "updateWorld" to actually enact the
# X% I" r& k% Z; o* p' ~8 h5 U // changes the heatbugs have made. The ordering here is
1 s4 |" K7 b: b; g3 i& f5 ]6 P5 Y // significant!+ ?* e" V: c: Q5 x
5 T! j" c! M( `! R* W // Note also, that with the additional* U$ P2 e9 p7 a: E
// `randomizeHeatbugUpdateOrder' Boolean flag we can
( u p) s; Q/ | // randomize the order in which the bugs actually run
6 O2 n! o4 P0 }2 P$ ^4 s // their step rule. This has the effect of removing any
5 @; D8 H3 c) `0 y. T% z // systematic bias in the iteration throught the heatbug) V# c2 a( k2 x5 I
// list from timestep to timestep' b0 _' y P: Y: r
6 W8 j' o) t; z" a! j
// By default, all `createActionForEach' modelActions have
! B- l u7 i0 [ // a default order of `Sequential', which means that the1 Q2 N; J7 b. h5 D+ P( p2 U" Q
// order of iteration through the `heatbugList' will be
( M8 R2 M5 }5 L$ E+ K // identical (assuming the list order is not changed0 p0 j7 r$ @% h, p4 K/ Q/ |2 K
// indirectly by some other process).
# j+ V$ P9 t: W: l + J. R4 h* t3 Z# H: D$ c
modelActions = new ActionGroupImpl (getZone ());
1 ~+ p5 n V" W; P1 ~# L: W
1 f9 w% X6 ]* Y+ c0 X' ? try {' F! ?) A5 z, L" d
modelActions.createActionTo$message. q7 r' h7 b9 R" y( m% C; J. |
(heat, new Selector (heat.getClass (), "stepRule", false));
/ F* k! m4 V+ O! I/ G } catch (Exception e) {
/ F" f2 s. X/ V- o' z, B% [ System.err.println ("Exception stepRule: " + e.getMessage ()); K9 q8 E; |7 A
}
/ [" r( `$ e: K2 e& A i3 |- h$ u- W' }$ ^2 O* D5 e; R; n+ Z# U$ |
try {
6 Y: u& F5 U W% a" @ Heatbug proto = (Heatbug) heatbugList.get (0);
) C' l2 G7 E" ?- E! F/ \ L Selector sel =
8 B! A( Y% U w+ x) r+ ` new Selector (proto.getClass (), "heatbugStep", false);& }3 \& _6 L6 b8 R( }6 v) \% t
actionForEach =
" s' w! J. l( B* g& y5 P% k modelActions.createFActionForEachHomogeneous$call
" v* U0 [. H$ k (heatbugList,
4 h4 \" O! e$ W* V; | new FCallImpl (this, proto, sel,+ D, T' W! e3 s( k4 ^
new FArgumentsImpl (this, sel)));
e2 M7 t. J# V1 i } catch (Exception e) {: T2 O+ W3 L# D8 C A/ } \
e.printStackTrace (System.err);3 A% J5 k. q$ B
}; F8 j7 g$ o2 V3 W
9 ?% r! W( @: J0 k, [
syncUpdateOrder ();0 m5 T" K z6 [: [# S: F
' z' ~' v0 n. P/ U8 y# M) ~ try {
, r+ O6 J" V y- M% N* |, Z modelActions.createActionTo$message ( V1 r' W5 k/ H- T3 G4 Q
(heat, new Selector (heat.getClass (), "updateLattice", false));
! N# j. c# q: _7 z# ]8 U( F/ {' g } catch (Exception e) {9 ~+ v" K6 n- b! u g5 E) e* J
System.err.println("Exception updateLattice: " + e.getMessage ());6 ~6 W) m: y& Q U _
}
' e5 \7 |! N; V+ z# G" h
* Q5 G2 c8 A8 u2 h) m // Then we create a schedule that executes the
! @* x6 m$ }& N+ W // modelActions. modelActions is an ActionGroup, by itself it
: D* y' k% d( c* I: `- n4 s g* v // has no notion of time. In order to have it executed in
3 X( `) Y5 ]" @: P // time, we create a Schedule that says to use the
K c& m; J& J4 L8 p9 ~ // modelActions ActionGroup at particular times. This
1 T/ ^) i c2 e* I& l // schedule has a repeat interval of 1, it will loop every
1 X1 C# _2 R- w7 v! k0 U$ _ // time step. The action is executed at time 0 relative to
' F* K: D+ O, G) w* T, F // the beginning of the loop.
+ s: e" h; b) R% q5 `1 T2 C, W* P6 c: R
// This is a simple schedule, with only one action that is
% P; `9 P9 o! g, W // just repeated every time. See jmousetrap for more+ u- Z2 }! M9 W
// complicated schedules." |7 a+ w* p( p+ @
6 Y# v, J* ?% B* O: J modelSchedule = new ScheduleImpl (getZone (), 1);& I3 u5 w' V+ _2 ~1 |
modelSchedule.at$createAction (0, modelActions);; _; h% L7 ~+ u' c$ I
/ j# t7 K+ w8 F/ |6 b6 S# k
return this;; M+ M' j$ r0 |2 C1 p- t4 O) |6 P. x
} |