示例#1
0
文件: server.go 项目: jyzhe/beehive
func (h *ConnHandler) Stop(ctx beehive.RcvContext) {
	h.conn.Close()
	<-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)) }
示例#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
}
示例#3
0
文件: hive.go 项目: jyzhe/beehive
// RaftTick*RaftElectTicks.
func (c HiveConfig) RaftElectTimeout() time.Duration {
	return time.Duration(c.RaftElectTicks) * (c.RaftTick + c.RaftTickDelta)
}

// RaftHBTimeout returns the raft heartbeat timeout as RaftTick*RaftHBTicks.
func (c HiveConfig) RaftHBTimeout() time.Duration {
	return time.Duration(c.RaftHBTicks) * (c.RaftTick + c.RaftTickDelta)
}

var raftLogOnce sync.Once

// HiveOption represents a configuration option of a hive.
type HiveOption args.V

var addr = args.NewString(args.Flag("addr", "localhost:7677",
	"the server listening address used for both RPC and HTTP"))

// Addr represents the listening address of the hive used for both inter-hive
// RPC and its HTTP/web interface.
func Addr(a string) HiveOption { return HiveOption(addr(a)) }

var paddrs = args.NewString(args.Flag("paddrs", "",
	"address of peers. Seperate entries with a comma"))

// PeerAddrs represents the peer addresses of hive.
func PeerAddrs(pa ...string) HiveOption {
	return HiveOption(paddrs(strings.Join(pa, ",")))
}

var dataChBufSize = args.NewUint(args.Flag("chsize", uint(1024),
	"buffer size of data channels"))