HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:0 h/ _2 H. J! h
0 k, J+ B, H7 F: |0 v
public Object buildActions () {! |' G! p) X5 K$ d0 b
super.buildActions();& S, a# t' S) @( b8 ~, Y
, m- u2 q! Q$ j& c7 D/ H
// Create the list of simulation actions. We put these in
2 v6 ]) Y; ~/ B, u8 y: u/ E // an action group, because we want these actions to be
; _/ F- e A1 Z // executed in a specific order, but these steps should7 w2 r! J& L) a6 ^9 m5 X j
// take no (simulated) time. The M(foo) means "The message
; E& f% e1 w* F // called <foo>". You can send a message To a particular- Y; w4 a( B1 z7 q* p
// object, or ForEach object in a collection.
. B6 I6 [' N! z' W* i8 g' E 5 ?4 T0 }) _& P% g; B$ y" v
// Note we update the heatspace in two phases: first run
: D* w8 N! }* R // diffusion, then run "updateWorld" to actually enact the$ d% H. K0 E' h G6 D; I
// changes the heatbugs have made. The ordering here is
O: U. X% q0 @/ x& c // significant!6 M$ V" P+ ?6 D: |
4 X5 N( N: F- \1 j
// Note also, that with the additional
4 W+ Z" | t& O // `randomizeHeatbugUpdateOrder' Boolean flag we can9 W6 U$ W1 D* C* e/ p! [
// randomize the order in which the bugs actually run! H' s1 u. d. K$ M
// their step rule. This has the effect of removing any- S+ D( O' k6 s0 ?8 x0 }: r
// systematic bias in the iteration throught the heatbug
3 B7 E7 g7 k) d, ~5 O // list from timestep to timestep
! }# J4 @8 Z. B, d9 f/ j 1 \9 \1 I- {7 H! d! y) g5 o
// By default, all `createActionForEach' modelActions have! a% I% ?$ R- Q8 ?4 ?6 G4 w
// a default order of `Sequential', which means that the% g: u1 m$ d& [5 D* ^% j
// order of iteration through the `heatbugList' will be
$ `* ?; L1 a& ]0 ` // identical (assuming the list order is not changed6 j8 o F, U$ s: }0 A
// indirectly by some other process).+ |. d% _9 g# w; S2 _
0 N7 r7 u w( p8 z3 k! @
modelActions = new ActionGroupImpl (getZone ());9 [, @/ b" M& f; g
3 e, f9 y* V" i* A. E
try {
+ v/ F, J6 c; G! i) L4 M8 w modelActions.createActionTo$message3 h$ r- o D2 S ~% [
(heat, new Selector (heat.getClass (), "stepRule", false));# F# u) q5 v/ J( \
} catch (Exception e) {3 R3 \ N$ }4 w9 x6 T( w" B/ g/ E
System.err.println ("Exception stepRule: " + e.getMessage ());
g* n6 G! T/ l" ] }
( B- H" U* {( ~" b) B9 X( K8 J( B. z }% @; e$ z3 L
try {) I, [+ e" B" q' E. J3 z
Heatbug proto = (Heatbug) heatbugList.get (0);
! h; N: C3 Z" y* x7 p$ g Selector sel = ( x' q, F# Y3 ~
new Selector (proto.getClass (), "heatbugStep", false);3 P5 H/ | Y* p3 ^
actionForEach =& e' k# w4 U# ^0 U
modelActions.createFActionForEachHomogeneous$call
9 U2 Y0 k+ M3 U6 `" \. B% U (heatbugList,
6 ]: i( H4 z- j+ q8 Q+ l- P new FCallImpl (this, proto, sel,& L q( n) |# l) S6 p9 ~; r
new FArgumentsImpl (this, sel)));% H6 Z% g9 h' ~+ x+ @) \
} catch (Exception e) {$ ]- b5 d) h } @# o' f/ }$ _
e.printStackTrace (System.err);
- e4 | L3 l- ~. q% o }, B& P+ g1 Q, ]# J8 ?' |$ W7 P
% w. Z7 N9 G/ C9 J syncUpdateOrder ();
( e# @1 S7 V8 Q# G: D* G ^; P7 `; F1 K. \- x2 y, R
try {' b t+ A1 `, i
modelActions.createActionTo$message ! g3 }: N0 @5 J2 E
(heat, new Selector (heat.getClass (), "updateLattice", false));! O# G8 G8 n) B, j
} catch (Exception e) {, w( ?6 X. [& n8 v$ G
System.err.println("Exception updateLattice: " + e.getMessage ());
% i! F, Y2 l( g0 S }8 c5 a) C. s) e8 }' k8 D' ^
; I z- \ V. z5 {' K. T
// Then we create a schedule that executes the
9 T: B* _6 }6 a // modelActions. modelActions is an ActionGroup, by itself it
' L6 y; g, ^) d. B+ ~" O" N // has no notion of time. In order to have it executed in: e" p6 n, ]. D1 \; ~6 S
// time, we create a Schedule that says to use the
]4 Z8 |: P p3 i/ ~5 w1 I3 i // modelActions ActionGroup at particular times. This
/ k& h( F6 q; ?0 o! l // schedule has a repeat interval of 1, it will loop every
. R- W$ G% F" C# z1 j // time step. The action is executed at time 0 relative to
2 k1 d. i! |3 W // the beginning of the loop.( v" {" {# W: }& B6 L8 n9 B
: C' O6 C* g: e+ u ~ // This is a simple schedule, with only one action that is0 V9 H7 {+ p7 }5 C$ a' A
// just repeated every time. See jmousetrap for more
9 Y' T' ^ s+ V1 z, R" } // complicated schedules.+ p, c( S j3 P
1 |, g* B1 U/ L+ c5 i
modelSchedule = new ScheduleImpl (getZone (), 1);! v$ _1 ? p( L' e9 q; y: }* X4 U( x% d
modelSchedule.at$createAction (0, modelActions);
+ x- x2 C d8 V9 n 1 D- X. d' g; x5 l. \2 C. M
return this;! j) h- D4 U! P; ~
} |