@@ -5,9 +5,6 @@ extern crate interactive;
55use timely:: synchronization:: Sequencer ;
66use interactive:: { Manager , Command , Value } ;
77
8- use timely:: logging:: TimelyEvent ;
9- use differential_dataflow:: logging:: DifferentialEvent ;
10-
118fn main ( ) {
129
1310 let mut args = std:: env:: args ( ) ;
@@ -19,77 +16,6 @@ fn main() {
1916 let command_queue = Arc :: new ( Mutex :: new ( VecDeque :: < Command < Value > > :: new ( ) ) ) ;
2017 let command_queue2 = command_queue. clone ( ) ;
2118
22- let guards =
23- timely:: execute_from_args ( args, move |worker| {
24-
25- let timer = :: std:: time:: Instant :: now ( ) ;
26- let mut manager = Manager :: < Value > :: new ( ) ;
27-
28- let recv = command_queue. clone ( ) ;
29-
30- use std:: rc:: Rc ;
31- use timely:: dataflow:: operators:: capture:: event:: link:: EventLink ;
32- use timely:: logging:: BatchLogger ;
33-
34- let timely_events = Rc :: new ( EventLink :: new ( ) ) ;
35- let differential_events = Rc :: new ( EventLink :: new ( ) ) ;
36-
37- manager. publish_timely_logging ( worker, Some ( timely_events. clone ( ) ) ) ;
38- manager. publish_differential_logging ( worker, Some ( differential_events. clone ( ) ) ) ;
39-
40- let mut timely_logger = BatchLogger :: new ( timely_events. clone ( ) ) ;
41- worker
42- . log_register ( )
43- . insert :: < TimelyEvent , _ > ( "timely" , move |time, data| timely_logger. publish_batch ( time, data) ) ;
44-
45- let mut differential_logger = BatchLogger :: new ( differential_events. clone ( ) ) ;
46- worker
47- . log_register ( )
48- . insert :: < DifferentialEvent , _ > ( "differential/arrange" , move |time, data| differential_logger. publish_batch ( time, data) ) ;
49-
50- let mut sequencer = Sequencer :: new ( worker, timer) ;
51-
52- let mut done = false ;
53- while !done {
54-
55- { // Check out channel status.
56- let mut lock = recv. lock ( ) . expect ( "Mutex poisoned" ) ;
57- while let Some ( command) = lock. pop_front ( ) {
58- sequencer. push ( command) ;
59- }
60- }
61-
62- // Dequeue and act on commands.
63- // One at a time, so that Shutdown works.
64- if let Some ( command) = sequencer. next ( ) {
65- println ! ( "{:?}\t Executing {:?}" , timer. elapsed( ) , command) ;
66- if command == Command :: Shutdown {
67- done = true ;
68- }
69- command. execute ( & mut manager, worker) ;
70- }
71-
72- worker. step ( ) ;
73- }
74-
75- println ! ( "Shutting down" ) ;
76-
77- // Disable sequencer for shut down.
78- drop ( sequencer) ;
79-
80- // Deregister loggers, so that the logging dataflows can shut down.
81- worker
82- . log_register ( )
83- . insert :: < TimelyEvent , _ > ( "timely" , move |_time, _data| { } ) ;
84-
85- worker
86- . log_register ( )
87- . insert :: < DifferentialEvent , _ > ( "differential/arrange" , move |_time, _data| { } ) ;
88-
89- } ) . expect ( "Timely computation did not initialize cleanly" ) ;
90-
91- println ! ( "Now accepting commands" ) ;
92-
9319 // Detached thread for client connections.
9420 std:: thread:: Builder :: new ( )
9521 . name ( "Listener" . to_string ( ) )
@@ -111,7 +37,41 @@ fn main() {
11137 } )
11238 . expect ( "failed to create thread" ) ;
11339 }
114-
11540 } )
11641 . expect ( "Failed to spawn listen thread" ) ;
42+
43+ // Initiate timely computation.
44+ timely:: execute_from_args ( args, move |worker| {
45+
46+ let timer = :: std:: time:: Instant :: now ( ) ;
47+ let recv = command_queue. clone ( ) ;
48+
49+ let mut manager = Manager :: < Value > :: new ( ) ;
50+ let mut sequencer = Some ( Sequencer :: new ( worker, timer) ) ;
51+
52+ while sequencer. is_some ( ) {
53+
54+ // Check out channel status.
55+ while let Some ( command) = recv. lock ( ) . expect ( "Mutex poisoned" ) . pop_front ( ) {
56+ sequencer
57+ . as_mut ( )
58+ . map ( |s| s. push ( command) ) ;
59+ }
60+
61+ // Dequeue and act on commands.
62+ // Once per iteration, so that Shutdown works "immediately".
63+ if let Some ( command) = sequencer. as_mut ( ) . and_then ( |s| s. next ( ) ) {
64+ println ! ( "{:?}\t Executing {:?}" , timer. elapsed( ) , command) ;
65+ if command == Command :: Shutdown {
66+ sequencer = None ;
67+ }
68+ command. execute ( & mut manager, worker) ;
69+ }
70+
71+ worker. step ( ) ;
72+ }
73+
74+ println ! ( "Shutting down" ) ;
75+
76+ } ) . expect ( "Timely computation did not initialize cleanly" ) ;
11777}
0 commit comments