HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
/ q# \4 U: |4 S/ ?6 q+ |; H! q" T4 K8 P+ u
public Object buildActions () {
5 { G; W q+ _% X& |' n super.buildActions();
/ p$ x* G# e1 _& R( T / \# U- J# y i! |
// Create the list of simulation actions. We put these in% I4 I( u- ~8 O3 F6 P
// an action group, because we want these actions to be4 @" _" P# k. ]7 P
// executed in a specific order, but these steps should
" S& {! c7 Y9 d% N6 l // take no (simulated) time. The M(foo) means "The message2 M% E! b$ e- N; c7 j2 ^8 T
// called <foo>". You can send a message To a particular$ V8 r/ J3 ]. b. K
// object, or ForEach object in a collection.
x6 |1 w- @% o3 c! {% G0 |
& I' @& Z3 i# O" S/ t // Note we update the heatspace in two phases: first run) B& f7 q; j+ e( Z
// diffusion, then run "updateWorld" to actually enact the
: _6 x8 H, u4 k; k // changes the heatbugs have made. The ordering here is5 Z) a% Z7 d1 _# W7 N4 M9 x
// significant!
% J3 L- c' r- { 5 `6 b% N% ^4 P1 J
// Note also, that with the additional5 V0 l* ?1 w4 V8 O
// `randomizeHeatbugUpdateOrder' Boolean flag we can
2 F6 n8 f! ^: C, c: b // randomize the order in which the bugs actually run
$ _# V/ W1 A/ K8 Y2 q // their step rule. This has the effect of removing any
/ P* K" ~9 f4 y& T$ U' B // systematic bias in the iteration throught the heatbug
4 w, t/ y5 x* Y# T: f# f% t" t // list from timestep to timestep
8 c; ~3 G: x0 P5 `4 W! z
% `7 A+ X6 \* w1 m // By default, all `createActionForEach' modelActions have x1 ?, a+ E( V8 b8 v
// a default order of `Sequential', which means that the
b; ]) B' j+ e* @! v5 c- z0 | // order of iteration through the `heatbugList' will be
$ v) t7 m& ]- L- X( h // identical (assuming the list order is not changed
; t6 r5 j4 T2 b4 p // indirectly by some other process).
% ^1 A- V7 i* e
' I. j# l9 W* R) x: D3 t: c modelActions = new ActionGroupImpl (getZone ());
$ v' Z3 p8 A* B# G# I, O7 Y0 G0 O, h- [
try {
3 s/ |# l+ u9 h! Z modelActions.createActionTo$message5 p$ J; h6 e% ]3 s7 S$ n' H$ f
(heat, new Selector (heat.getClass (), "stepRule", false));. V; H# N- a9 h Z- f7 @
} catch (Exception e) {
4 B& `- C( ~4 d4 F N) a% U System.err.println ("Exception stepRule: " + e.getMessage ());
' `) C1 m* p0 p" F$ L }* {- F2 x5 {# W. h' H0 k& R0 a
7 z1 r: I& J: W0 x6 \1 x try {
- J5 _5 z; V3 G* R: a Heatbug proto = (Heatbug) heatbugList.get (0);! V( x0 g# Z! V- l
Selector sel = 0 T1 g: l M! E7 A; N. M
new Selector (proto.getClass (), "heatbugStep", false);
7 B9 Z! O1 ~9 Z actionForEach =
3 \* s* k! H: t+ B modelActions.createFActionForEachHomogeneous$call
" |2 @& E- D4 L! V; H (heatbugList,
2 ~) ^( O* j" W2 R5 _& M; t* J new FCallImpl (this, proto, sel,2 ^" @" U/ m+ Q: ?7 t
new FArgumentsImpl (this, sel)));
. v7 d' L0 A8 P$ z9 j$ O" f' Z( I& c } catch (Exception e) {
) Y, o0 H/ i5 J) |9 Z; t- f& E e.printStackTrace (System.err);& z& A" ^9 E$ v% r, q
}
. g' k" i: X+ V( z- U) B# _5 V9 _ ) a8 ~, @& E. [4 `" t4 @ G
syncUpdateOrder ();
6 v" P, T" v( d; n6 b9 \. d. S% I; @; R* W2 j; J. M% B
try {7 i5 h; ~. t8 r4 o( |/ L
modelActions.createActionTo$message
+ o* X; D+ Z" Z, m9 S (heat, new Selector (heat.getClass (), "updateLattice", false));
( U9 O$ o) B3 `7 P: H( s } catch (Exception e) {: m8 w7 H5 F; {: z5 h
System.err.println("Exception updateLattice: " + e.getMessage ());( l( g7 F: r- I" \- {3 I! D' t
}8 A Y; k; m' [* Z8 L
$ D% l. W7 g5 V6 Q& W( C; Y
// Then we create a schedule that executes the
4 [' t, I5 D( u. D7 f // modelActions. modelActions is an ActionGroup, by itself it
; [' }: S7 z% d; B5 H- ^ // has no notion of time. In order to have it executed in* P. C4 ]: T, {
// time, we create a Schedule that says to use the
7 B1 Z2 Q+ Z7 H1 h // modelActions ActionGroup at particular times. This) H$ [7 b! ?* B8 E7 l3 a
// schedule has a repeat interval of 1, it will loop every! A; @* }1 k- i, W) m! T
// time step. The action is executed at time 0 relative to
+ n1 i) ?- e. W // the beginning of the loop.9 J. c7 I6 B* Q
( J8 M# `& o& p Z // This is a simple schedule, with only one action that is9 X9 D7 J9 Q! ~
// just repeated every time. See jmousetrap for more. ^7 Y: T& W8 @% U3 T
// complicated schedules.3 e, V' E4 _# q- [! p& n
F `3 q9 E( g; V5 M# a X% M modelSchedule = new ScheduleImpl (getZone (), 1);
K. S: |1 {8 p! a modelSchedule.at$createAction (0, modelActions);$ B# ~/ X4 b, r$ ~- c' g
5 s f$ w( @: H" O6 I
return this;
9 V* Q! R6 k/ g- Q7 _% e3 M } |