Exemplo n.º 1
0
// RegisterTaskQ registers the TaskQ application and all its handler in the
// hive.
func RegisterTaskQ(h beehive.Hive, opts ...Option) error {
	if !flag.Parsed() {
		flag.Parse()
	}

	proto, err := NewProtoHandler(addr.Get(opts))
	if err != nil {
		return err
	}

	r := rate.Get(opts)
	taskq := h.NewApp("taskq", beehive.Persistent(repl.Get(opts)),
		beehive.OutRate(bucket.Rate(r), 2*r))
	taskq.Handle(Enque{}, EnQHandler{})
	taskq.Handle(Deque{}, DeQHandler{})
	taskq.Handle(Ack{}, AckHandler{})
	taskq.Handle(Timeout{}, TimeoutHandler{
		ExpDur: 60 * time.Second,
	})

	ah := &AckHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks/{id:[0-9]+}", ah).Methods("DELETE")
	dh := &DeQHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks/deque", dh).Methods("POST")
	eh := &EnQHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks", eh).Methods("POST")

	taskq.Detached(beehive.NewTimer(30*time.Second, func() {
		h.Emit(Timeout(time.Now()))
	}))
	taskq.Detached(proto)

	return nil
}
Exemplo n.º 2
0
// StartOpenFlow starts the OpenFlow driver on the given hive using the default
// OpenFlow configuration that can be set through command line arguments.
func StartOpenFlow(hive bh.Hive, options ...Option) error {
	app := hive.NewApp("OFDriver",
		bh.OutRate(bucket.Rate(*maxConnRate), 10*uint64(*maxConnRate)))
	l := &ofListener{
		proto:      *proto,
		addr:       *addr,
		readBufLen: *readBufLen,
	}

	for _, opt := range options {
		opt(l)
	}

	app.Detached(l)
	glog.V(2).Infof("OpenFlow driver registered on %s:%s", l.proto, l.addr)

	return nil
}