Exemple #1
0
func main() {
	switch kingpin.MustParse(app.Parse(os.Args[1:])) {
	case leader.FullCommand():
		println("listening on", (*leaderIp)+":"+strconv.Itoa(*leaderPort))
		l.RunLeader((*leaderIp) + ":" + strconv.Itoa(*leaderPort))
	case sender.FullCommand():
		var wg sync.WaitGroup
		sendChan, err := s.NewChannel(*sendToChanName, *senderAgentPort, &wg)
		if err != nil {
			panic(err)
		}

		file := os.Stdin
		if *sendFile != "" {
			file, err = os.Open(*sendFile)
			if err != nil {
				log.Fatal(err)
			}
			defer file.Close()
		}

		counter := 0
		scanner := bufio.NewScanner(file)
		for scanner.Scan() {
			sendChan <- scanner.Bytes()
			counter++
		}
		if err := scanner.Err(); err != nil {
			log.Fatal(err)
		}
		close(sendChan)
		wg.Wait()

	case receiver.FullCommand():
		rc := r.NewReceiveChannel(*receiveFromChanName, *receiverLeader, 0)
		recvChan, err := rc.GetChannel()
		if err != nil {
			panic(err)
		}
		for m := range recvChan {
			println(string(m))
		}

	case agent.FullCommand():
		agentServer := a.NewAgentServer(*agentDir, *agentPort, *agentLeaderServer)
		agentServer.Run()
	}
}
Exemple #2
0
func GetReadChannel(name string) (chan []byte, error) {
	rc := receiver.NewReceiveChannel(name, networkContext.LeaderAddress, 0)
	return rc.GetChannel()
}