core: Change runtime.AppCycle to veyron2.GetAppCycle(ctx).
Change-Id: Ib306d2ad740f390c56fd32324ac618bcf3cab5df
MultiPart: 1/4
diff --git a/lib/signals/signals.go b/lib/signals/signals.go
index 7a09601..e2d64a6 100644
--- a/lib/signals/signals.go
+++ b/lib/signals/signals.go
@@ -6,6 +6,7 @@
"syscall"
"v.io/core/veyron2"
+ "v.io/core/veyron2/context"
)
type stopSignal string
@@ -31,7 +32,7 @@
// none are specified, the default signals. The first signal received will be
// made available on the returned channel; upon receiving a second signal, the
// process will exit.
-func ShutdownOnSignals(runtime veyron2.Runtime, signals ...os.Signal) <-chan os.Signal {
+func ShutdownOnSignals(ctx *context.T, signals ...os.Signal) <-chan os.Signal {
if len(signals) == 0 {
signals = defaultSignals()
}
@@ -45,9 +46,9 @@
case STOP:
if !sawStop {
sawStop = true
- if runtime != nil {
+ if ctx != nil {
stopWaiter := make(chan string, 1)
- runtime.AppCycle().WaitForStop(stopWaiter)
+ veyron2.GetAppCycle(ctx).WaitForStop(stopWaiter)
go func() {
for {
ch <- stopSignal(<-stopWaiter)
diff --git a/lib/signals/signals_test.go b/lib/signals/signals_test.go
index 387e6fe..1d7b7f4 100644
--- a/lib/signals/signals_test.go
+++ b/lib/signals/signals_test.go
@@ -12,6 +12,7 @@
"time"
"v.io/core/veyron2"
+ "v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/mgmt"
"v.io/core/veyron2/naming"
@@ -41,7 +42,7 @@
modules.RegisterChild("handleDefaultsIgnoreChan", "", handleDefaultsIgnoreChan)
}
-func stopLoop(runtime veyron2.Runtime, stdin io.Reader, ch chan<- struct{}) {
+func stopLoop(ctx *context.T, stdin io.Reader, ch chan<- struct{}) {
scanner := bufio.NewScanner(stdin)
for scanner.Scan() {
switch scanner.Text() {
@@ -49,7 +50,7 @@
close(ch)
return
case "stop":
- runtime.AppCycle().Stop()
+ veyron2.GetAppCycle(ctx).Stop()
}
}
}
@@ -60,9 +61,11 @@
panic(err)
}
+ ctx := runtime.NewContext()
+
closeStopLoop := make(chan struct{})
- go stopLoop(runtime, stdin, closeStopLoop)
- wait := ShutdownOnSignals(runtime, signals...)
+ go stopLoop(ctx, stdin, closeStopLoop)
+ wait := ShutdownOnSignals(ctx, signals...)
fmt.Fprintf(stdout, "ready\n")
fmt.Fprintf(stdout, "received signal %s\n", <-wait)
runtime.Cleanup()
@@ -90,9 +93,12 @@
panic(err)
}
defer runtime.Cleanup()
+
+ ctx := runtime.NewContext()
+
closeStopLoop := make(chan struct{})
- go stopLoop(runtime, stdin, closeStopLoop)
- ShutdownOnSignals(runtime)
+ go stopLoop(ctx, stdin, closeStopLoop)
+ ShutdownOnSignals(ctx)
fmt.Fprintf(stdout, "ready\n")
<-closeStopLoop
return nil