Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (47 sloc) 1.472 kb
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
1 // Copyright (c) Paulo Suzart. All rights reserved.
2 // The use and distribution terms for this software are covered by the
3 // Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 // which can be found in the file epl-v10.html at the root of this distribution.
5 // By using this software in any fashion, you are agreeing to be bound by
6 // the terms of this license.
7 // You must not remove this notice, or any other, from this software.
8
9b5050b Paulo Suzart first commit
authored
9 package main
10
7eb5afb Paulo Suzart after gofmt
authored
11 import (
12 "flag"
23186a8 Paulo Suzart Now gb support any number of workers
authored
13 "log"
49402bf Paulo Suzart timout added. many improvements
authored
14 "os"
4f90eb9 mattn go fmt
mattn authored
15 "time"
7eb5afb Paulo Suzart after gofmt
authored
16 )
9b5050b Paulo Suzart first commit
authored
17
1150114 Paulo Suzart autodetect host name
authored
18 var host, _ = os.Hostname()
23186a8 Paulo Suzart Now gb support any number of workers
authored
19 var (
b5523e2 Paulo Suzart now everythig resides on gb folder. http.go now uses only http.Transport...
authored
20 mode = flag.String("M", "standalone", "standalone, master, worker.")
21 maxTime = flag.Int64("T", -1, "Max time in milisecs. master and standalone modes only.")
22 hostAddr = flag.String("H", host+":1970", "The master Addr.")
23186a8 Paulo Suzart Now gb support any number of workers
authored
23 )
9b5050b Paulo Suzart first commit
authored
24
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
25 func init() {
9b5050b Paulo Suzart first commit
authored
26 flag.Parse()
1150114 Paulo Suzart autodetect host name
authored
27 log.Printf("Starting in %s mode - %s", *mode, *hostAddr)
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
28 }
29
30 func main() {
4f90eb9 mattn go fmt
mattn authored
31 log.SetPrefix("[" + *mode + "@" + *hostAddr + "]")
b5523e2 Paulo Suzart now everythig resides on gb folder. http.go now uses only http.Transport...
authored
32
33 ctrlChan := make(chan bool)
c6d5fab Paulo Suzart removing some ifs
authored
34 switch *mode {
03ca12e Paulo Suzart moved to 0.0.2 beta and constants
authored
35 case MASTER, STANDALONE:
bd730fe Paulo Suzart handled error div by 0
authored
36 m := NewMaster(mode, hostAddr, *maxTime*1000000)
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
37 m.BenchMark(ctrlChan)
49402bf Paulo Suzart timout added. many improvements
authored
38 if *maxTime != -1 {
39 go supervise(m, maxTime)
40 }
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
41 <-ctrlChan
42 log.Print(m.summary)
03ca12e Paulo Suzart moved to 0.0.2 beta and constants
authored
43 case WORKER:
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
44 NewLocalWorker(mode, hostAddr).Serve()
b5523e2 Paulo Suzart now everythig resides on gb folder. http.go now uses only http.Transport...
authored
45 <-ctrlChan //will wait forever.
3a68285 Paulo Suzart Distributed gb working
authored
46 }
47 }
49402bf Paulo Suzart timout added. many improvements
authored
48
49 func supervise(supervised Supervised, maxTime *int64) {
9681334 mattn Fix build
mattn authored
50 time.Sleep(time.Duration(*maxTime) * time.Millisecond)
49402bf Paulo Suzart timout added. many improvements
authored
51 log.Print("WARN! gb stopped due to timeout. Work lost.")
c76de9d Paulo Suzart Sessions for better netchan control, imported master channels cached
authored
52 supervised.Shutdown()
49402bf Paulo Suzart timout added. many improvements
authored
53 os.Exit(1)
54 }
Something went wrong with that request. Please try again.