Пример #1
0
func newValueTable() valueTable {
	return valueTable{
		make(map[dagger.StreamID][]*dagger.Record),
		make(map[dagger.StreamID]int),
		dagger.Timestamp(0),
	}
}
Пример #2
0
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)
}