// Main is the body of the Go program that starts the trending circuit func Main() { // Start the aggregator worker. // Once started, it looks for reducers in the given anchor directory. // If no such reducers exits, it waits and retries. It is thus not a // problem that the reducers have not been started already. println("Kicking aggregator") _, addr, err := circuit.Spawn(aggregatorHost, []string{"/tutorial/aggregator"}, StartAggregator{}, "/tutorial/reducer") if err != nil { panic(err) } println(addr.String()) // Start the reducers println("Kicking reducers") reducer := make([]circuit.X, len(reducerHost)) for i, h := range reducerHost { retrn, addr, err := circuit.Spawn(h, []string{"/tutorial/reducer"}, StartReducer{}) if err != nil { panic(err) } reducer[i] = retrn[0].(circuit.X) println(addr.String()) } // Start the mappers and give them cross-runtime pointers to the already-started reducers. println("Kicking mappers") for _, h := range mapperHost { _, addr, err := circuit.Spawn(h, []string{"/tutorial/mapper"}, StartMapper{}, testFirehose, reducer) if err != nil { panic(err) } println(addr.String()) } }
func Main() { println("Kicking aggregator") _, addr, err := circuit.Spawn(config.AggregatorHost, []string{"/tutorial/aggregator"}, StartAggregator{}, "/tutorial/reducer") if err != nil { panic(err) } println(addr.String()) println("Kicking reducers") reducer := make([]circuit.X, len(config.ReducerHost)) for i, h := range config.ReducerHost { retrn, addr, err := circuit.Spawn(h, []string{"/tutorial/reducer"}, StartReducer{}) if err != nil { panic(err) } reducer[i] = retrn[0].(circuit.X) println(addr.String()) } println("Kicking mappers") for _, h := range config.MapperHost { _, addr, err := circuit.Spawn(h, []string{"/tutorial/mapper"}, StartMapper{}, testFirehose, reducer) if err != nil { panic(err) } println(addr.String()) } }
func main() { println("Starting ...") // Spawn starts a circuit worker on a remote host and runs a given goroutine with given arguments // The first argument to Spawn is the host where the worker shall be started. // The second is a string slice of anchors under which the new spawned worker should register in the anchor file system. // The third argument is the type whose only method is the function that will execute on the spawned worker. // Any subsequent arguments are passed to that function. // // Spawn returns three values. // The first holds all return values of the executed function, packed in a slice of interfaces. // The second holds an address to the worker where the function is executing. // The third, if non-nil, describes an error condition that prevented the operations. retrn, addr, err := circuit.Spawn("localhost", []string{"/hello"}, x.App{}, "world!") if err != nil { println("Oh oh", err.Error()) return } // On successful spawning, we print out the address of the spawned worker, println("Spawned", addr.String()) // and the time of spawning at the remote host. remoteTime := retrn[0].(time.Time) println("Time at remote on spawn:", remoteTime.Format(time.Kitchen)) }
func replenishWorker(durableFile string, c *Config, i int) (replenished bool, addr circuit.Addr, err error) { // Check if worker already running anchor := path.Join(c.Anchor, strconv.Itoa(i)) dir, e := anchorfs.OpenDir(anchor) if e != nil { return false, nil, e } _, files, err := dir.Files() if e != nil { return false, nil, e } if len(files) > 0 { return false, nil, nil } // If not, start a new worker retrn, addr, err := circuit.Spawn(c.Workers[i].Host, []string{anchor}, start{}, durableFile, c.Workers[i].Port, c.ReadOnly) if err != nil { return false, nil, err } if retrn[1] != nil { err = retrn[1].(error) return false, addr, err } return true, addr, nil }
func spawn(config *vena.ShardConfig, anchor string) { _, addr, err := circuit.Spawn(config.Host, []string{anchor}, start{}, config.Dir, config.Cache) if err != nil { panic(err) } println("Shard started", addr.String()) }
func main() { println("Starting") r, _, err := circuit.Spawn("localhost", []string{"/telefile"}, srv.App{}, "/tmp/telehelo") if err != nil { println("Oh oh", err.Error()) return } fcli := file.NewFileClient(r[0].(circuit.X)) defer func() { recover() }() io.Copy(os.Stdout, fcli) }
func spark(ch chan int) { d := &worker.Dummy{} runtime.SetFinalizer(d, func(h *worker.Dummy) { println("finalizing dummy") close(ch) }) defer runtime.GC() // Test: // Spawn a worker and pass an x-pointer to it; // Worker proceeds to die right away; // Check that finalizer of local dummy called when local runtime notices remote is dead _, addr, err := circuit.Spawn("localhost", []string{"/xgc"}, worker.Start{}, circuit.Ref(d)) if err != nil { panic(err) } println(addr.String()) }
func replenish(c *vena.Config, w *WorkerConfig, anchor string) (re bool, addr circuit.Addr, err error) { // Check if worker already running dir, e := anchorfs.OpenDir(anchor) if e != nil { return false, nil, e } _, files, err := dir.Files() if e != nil { return false, nil, e } if len(files) > 0 { return false, nil, nil } // If not, start a new worker if _, addr, err = circuit.Spawn(w.Host, []string{anchor}, start{}, c, w.HTTPPort, w.TSDBPort); err != nil { return false, nil, err } return true, addr, nil }