예제 #1
0
파일: alarm.go 프로젝트: nsaje/dagger
func newValueTable() valueTable {
	return valueTable{
		make(map[dagger.StreamID][]*dagger.Record),
		make(map[dagger.StreamID]int),
		dagger.Timestamp(0),
	}
}
예제 #2
0
파일: subscriber.go 프로젝트: nsaje/dagger
func subscriberAction(c *cli.Context) {
	initLogging(c)
	fmt.Println(c.Args())
	errc := make(chan error)
	persister, err := dagger.NewPersister(persisterConfFromFlags(c))
	if err != nil {
		log.Fatalf("error opening database")
	}
	defer persister.Close()

	prnter := &printer{dataonly: c.Bool("dataonly")}

	coordinator := dagger.NewConsulCoordinator(consulConfFromFlags(c))
	receiver := dagger.NewReceiver(coordinator, receiverConfFromFlags(c))
	go receiver.Listen(errc)

	advertiseAddr := getAdvertiseAddr(c, receiver)
	err = coordinator.Start(advertiseAddr, errc)
	defer coordinator.Stop()
	if err != nil {
		log.Fatalf("Error starting coordinator %s", err)
	}

	topicGlob := dagger.StreamID(c.Args().First())
	lwmTracker := dagger.NewLWMTracker()
	linearizer := dagger.NewLinearizer("test", persister, lwmTracker)
	linearizer.SetProcessor(prnter)
	go linearizer.Run(errc)
	from, err := strconv.ParseInt(c.String("from"), 10, 64)
	if err != nil {
		panic(err)
	}

	if !c.IsSet("groupby") {
		receiver.SubscribeTo(topicGlob, dagger.Timestamp(from), linearizer)
		log.Printf("Subscribed to %s", topicGlob)
	} else {
		matchers := strings.Split(c.String("groupby"), ",")
		varargs := make([]interface{}, len(matchers))
		for i := range matchers {
			matchers[i] = strings.TrimSpace(matchers[i])
			varargs[i] = matchers[i]
		}
		testString := fmt.Sprintf(string(topicGlob), varargs...)
		if strings.Contains(testString, "%!") {
			log.Printf("Group by parameter has too few or too many values")
			return
		}
		// go match(topicGlob, matchers, errc)
	}

	handleSignals(errc)
}