Exemplo n.º 1
0
	<-h.done
}

func (h *ConnHandler) Rcv(msg beehive.Msg, ctx beehive.RcvContext) error {
	res := msg.Data().(writerTo)
	if err := res.writeTo(h.w); err != nil {
		return err
	}
	return h.w.Flush()
}

var repl = args.NewInt(args.Flag("taskq.repl", 3,
	"replication factor of taskq"))
var addr = args.NewString(args.Flag("taskq.addr", ":7979",
	"listening address of taskq server"))
var rate = args.NewUint64(args.Flag("taskq.maxrate", uint64(bucket.Unlimited),
	"maximum message rate of each client"))

// Option represents TaskQ server options.
type Option args.V

// ReplicationFactor is an option represeting the replication factor of TaskQ.
func ReplicationFactor(f int) Option { return Option(repl(f)) }

// Address is an option representing a TaskQ address.
func Address(a string) Option { return Option(addr(a)) }

// MaxRate is an option represeting the maximum rate of messages a client
// can send per second.
func MaxRate(r uint64) Option { return Option(rate(r)) }

// RegisterTaskQ registers the TaskQ application and all its handler in the
Exemplo n.º 2
0
package args_test

import (
	"fmt"

	"github.com/kandoo/beehive/Godeps/_workspace/src/github.com/soheilhy/args"
)

var ListenOn = args.NewInt(args.Default(8080))
var BufferSize = args.NewUint64(args.Default(uint64(1024 * 1024)))
var StateDir = args.NewString(args.Flag("test.state.dir", "/tmp", "state dir"))

func Server(opts ...args.V) {
	port := ListenOn.Get(opts)
	bufs := BufferSize.Get(opts)
	sdir := StateDir.Get(opts)

	fmt.Printf("port=%d buf=%d state=%s\n", port, bufs, sdir)
}

func Example() {
	Server()
	Server(ListenOn(80), BufferSize(2048*1024), StateDir("/tmp2"))
	// Output:
	//port=8080 buf=1048576 state=/tmp
	//port=80 buf=2097152 state=/tmp2
}
Exemplo n.º 3
0
func RaftElectTicks(e int) HiveOption { return HiveOption(raftElectTicks(e)) }

var raftHbeatTicks = args.NewInt(args.Flag("rafthbticks", 1,
	"number of raft ticks to fire a heartbeat (ie, heartbeat timeout)"))

// RaftHbeatTicks represents the number of ticks to send a new raft heartbeat.
func RaftHbeatTicks(h int) HiveOption { return HiveOption(raftHbeatTicks(h)) }

// TODO(soheil): use a better set of default values.
var raftInFlights = args.NewInt(args.Flag("raftmaxinflights", 4096/8,
	"maximum number of inflight raft append messages"))

// RaftInFlights represents the maximum number of raft messages in flight.
func RaftInFlights(f int) HiveOption { return HiveOption(raftInFlights(f)) }

var raftMaxMsgSize = args.NewUint64(args.Flag("raftmaxmsgsize",
	uint64(1*1024*1024), "maximum number of a raft append message"))

// RaftMaxMsgSize represents the maximum number of entries in a raft message.
func RaftMaxMsgSize(s uint64) HiveOption {
	return HiveOption(raftMaxMsgSize(s))
}

var connTimeout = args.NewDuration(args.Flag("conntimeout", 60*time.Second,
	"timeout for trying to connect to other hives"))

// ConnTimeout represents the connection timeout for RPC connections.
func ConnTimeout(t time.Duration) HiveOption {
	return HiveOption(connTimeout(t))
}

func hiveConfig(opts ...HiveOption) (cfg HiveConfig) {