HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
+ t r# a5 p' }5 D) }/ z" K$ Q$ E3 |3 @- d& J
public Object buildActions () {6 w; a% q: t% p8 U5 J
super.buildActions();& W4 y8 X+ T/ T2 j0 L8 y
, y" Q( |; ]% a
// Create the list of simulation actions. We put these in$ Y. A/ q2 r1 Q; c
// an action group, because we want these actions to be; I5 E6 z6 y, j' P" I* r1 P
// executed in a specific order, but these steps should0 N0 M8 a1 ~) d% o
// take no (simulated) time. The M(foo) means "The message
. S* S! a# w5 y0 s+ [( `5 l // called <foo>". You can send a message To a particular9 W5 C/ G$ {0 Q
// object, or ForEach object in a collection.
8 Q% ^' | [9 |3 i5 N) D + s1 @/ }0 {1 l/ u! C% ^' U
// Note we update the heatspace in two phases: first run, S# I; i6 E# m- \+ z3 p
// diffusion, then run "updateWorld" to actually enact the
# ~( }; P$ s. k7 g" X: P% Y: I // changes the heatbugs have made. The ordering here is; n4 i! z9 ]9 H% {* _" [
// significant!
# T1 O9 C1 t4 q$ _. P: d 2 i: D1 U- V6 w( N! ] p
// Note also, that with the additional' ^- n3 q; u- I. A6 _8 ^
// `randomizeHeatbugUpdateOrder' Boolean flag we can8 Q# @; y. ?3 K: }
// randomize the order in which the bugs actually run' g. A- u2 r3 V0 s5 D+ r) H, t
// their step rule. This has the effect of removing any
. X! @1 T' ^& I" O9 w9 l" |. W6 _ d // systematic bias in the iteration throught the heatbug
7 s0 _, D E% s // list from timestep to timestep
8 i3 P0 p& `9 N, c# b; F
/ a; \7 z3 u1 H# Q$ ]( D: P) u- T! } // By default, all `createActionForEach' modelActions have
2 o; [& s* L7 ~; p // a default order of `Sequential', which means that the$ m0 v: x# [8 Z8 e" Y) l
// order of iteration through the `heatbugList' will be
( F2 A' D2 P9 {$ a% P4 f! T // identical (assuming the list order is not changed
* J' v9 y9 k z; {2 P. | // indirectly by some other process).
0 T, d* m' E( x5 j& c3 w , R6 ?% H: B6 `( l# w( B
modelActions = new ActionGroupImpl (getZone ());- V+ f0 B* f' S1 R6 |4 O( S+ @
7 C) I$ S" g. y
try {
- z* ^+ a/ p1 w$ B1 Q+ }1 r) g8 C modelActions.createActionTo$message
+ C5 O! Q$ y g' w3 r" q/ j2 p (heat, new Selector (heat.getClass (), "stepRule", false));: M2 x/ T6 Z3 f# k
} catch (Exception e) {" V9 d3 P! u- C0 T, n8 D
System.err.println ("Exception stepRule: " + e.getMessage ());
) `8 J6 D3 O$ y. ^ }) D" I0 p/ L! M# t! E% j
5 I; ?: `4 n5 q L
try {; {# Q# f, l; f1 i& @- Q
Heatbug proto = (Heatbug) heatbugList.get (0);
: W( w1 n+ r/ l9 d9 C Selector sel =
5 Z' J/ E; C2 [( M- a new Selector (proto.getClass (), "heatbugStep", false);
# q3 y5 h+ T& W actionForEach =! n* W& N, l- e3 O2 E$ v# m: Z8 g
modelActions.createFActionForEachHomogeneous$call2 ` ^: r$ a2 F2 O+ K
(heatbugList, y c' R c5 R
new FCallImpl (this, proto, sel,% q. p. a& N) w; E
new FArgumentsImpl (this, sel)));5 {0 N$ w# p7 h( \- q. B
} catch (Exception e) {8 M, Q, `$ c) s5 t# Z0 ^) p
e.printStackTrace (System.err);
" q& F% e/ c7 B; r" T }
9 A" C- k$ n9 W
% g$ i2 j4 g" b+ f$ U syncUpdateOrder ();" d$ F4 x4 m( B/ v Z+ C# ^
8 ~8 `9 C; `1 P7 y' Y7 V" N
try {& G* E- L& Y! F
modelActions.createActionTo$message / s( c; z, ?5 O4 D3 z- q
(heat, new Selector (heat.getClass (), "updateLattice", false));
" S' `4 v$ f6 w. H7 q } catch (Exception e) {
8 |! J5 ?4 X0 S) R$ l( T- ^; A0 D& f System.err.println("Exception updateLattice: " + e.getMessage ());5 f* m" R# P# ?8 ~ u7 o5 {
}
3 T( a1 d9 N* p9 K; T) Z
" g$ C; L0 Z$ t // Then we create a schedule that executes the- R+ Y7 }$ Z! a9 }6 x# @5 k; e
// modelActions. modelActions is an ActionGroup, by itself it
( V9 i- S4 B' Y8 L( M! m/ c. _ // has no notion of time. In order to have it executed in
: B9 Q N: s1 o* Q // time, we create a Schedule that says to use the
. ~8 e, J0 t* }) S* ?/ F // modelActions ActionGroup at particular times. This7 x9 w; y: n8 |% G- X. p
// schedule has a repeat interval of 1, it will loop every
# a1 @9 r4 O+ |7 u9 H, t5 x; T // time step. The action is executed at time 0 relative to+ D+ v# }& Q- R8 x' q
// the beginning of the loop.
9 v1 I+ O) |6 W+ S" B# K; @; V$ V2 |7 J3 [
// This is a simple schedule, with only one action that is
4 F, n2 w. I( _1 }0 ?4 R) b // just repeated every time. See jmousetrap for more# l/ }1 \9 K) B* l7 \; l
// complicated schedules.1 u/ U6 I4 N/ ?7 s; m/ x
, q+ K2 B- u" m) o$ v/ V
modelSchedule = new ScheduleImpl (getZone (), 1);6 \+ f6 A$ A# J% c& ?8 ~
modelSchedule.at$createAction (0, modelActions);4 L( B$ ?5 j. |
/ x$ e _4 D( w% i1 }' V
return this;: \! t) Z% @$ N6 l9 G7 o2 i! P6 ^0 x8 k
} |