|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 03/59] controller: Initial attempt to generalize process / vm creation
From: George Dunlap <george.dunlap@xxxxxxxxxx>
Create a "Worker" interface, and have ProcessWorker implement that
interface.
Rename "Worker" to "WorkerReport" to make room for the interface.
Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
main.go | 45 +++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/main.go b/main.go
index 0cb9f51..034e2f2 100644
--- a/main.go
+++ b/main.go
@@ -11,24 +11,32 @@ import (
)
-type Worker struct {
+type WorkerReport struct {
Id int
-
- c *exec.Cmd
+ Now int
+ Mops int
+ MaxDelta int
+}
+
+type Worker interface {
+ SetId(int)
+ Init() error
+ Shutdown()
+ Process(chan WorkerReport, chan bool)
+}
+type ProcessWorker struct {
+ id int
+ c *exec.Cmd
stdout io.ReadCloser
-
jsonStarted bool
}
-type WorkerReport struct {
- Id int
- Now int
- Mops int
- MaxDelta int
+func (w *ProcessWorker) SetId(i int) {
+ w.id = i
}
-func (w *Worker) Init() (err error) {
+func (w *ProcessWorker) Init() (err error) {
w.c = exec.Command("../worker/worker-proc", "burnwait", "20",
"20000000")
w.stdout, err = w.c.StdoutPipe()
@@ -40,11 +48,11 @@ func (w *Worker) Init() (err error) {
return
}
-func (w *Worker) Shutdown() {
+func (w *ProcessWorker) Shutdown() {
w.c.Process.Kill()
}
-func (w *Worker) Process(report chan WorkerReport, done chan bool) {
+func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) {
w.c.Start()
scanner := bufio.NewScanner(w.stdout)
@@ -57,7 +65,7 @@ func (w *Worker) Process(report chan WorkerReport, done chan
bool) {
if w.jsonStarted {
var r WorkerReport
json.Unmarshal([]byte(s), &r)
- r.Id = w.Id
+ r.Id = w.id
report <- r
} else {
if s == "START JSON" {
@@ -79,7 +87,7 @@ const (
)
type WorkerState struct {
- Worker
+ w Worker
LastReport WorkerReport
}
@@ -114,11 +122,12 @@ func main() {
Workers := make([]WorkerState, count)
for i = 0; i< count; i++ {
- Workers[i].Id = i
+ Workers[i].w = &ProcessWorker{}
+ Workers[i].w.SetId(i)
- Workers[i].Init()
+ Workers[i].w.Init()
- go Workers[i].Process(report, done)
+ go Workers[i].w.Process(report, done)
}
for i > 0 {
@@ -131,7 +140,7 @@ func main() {
case <-signals:
fmt.Println("SIGINT receieved, shutting down workers")
for j := range Workers {
- Workers[j].Shutdown()
+ Workers[j].w.Shutdown()
}
}
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |