Example #1
0
	"net/http"
	"time"

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

// port is an integer argument that its default value is read from
// the "-example.typed.port" flag.
var port = args.NewInt(args.Flag("example.typed.port", 1234, "the port"))

// roundTripper is a generic argument that its default value is
// http.DefaultTransport.
var roundTripper = args.New(args.Default(http.DefaultTransport))

// timeout is a duration argument.
var timeout = args.NewDuration()

type ServerOpt args.V

// Port, RoundTripper, and Timeout respectively wrap port, roundTripper,
// and timeout to return ServerOpt instead of args.V.
func Port(p int) ServerOpt                       { return ServerOpt(port(p)) }
func RoundTripper(r http.RoundTripper) ServerOpt { return ServerOpt(roundTripper(r)) }
func Timeout(d time.Duration) ServerOpt          { return ServerOpt(timeout(d)) }

func MyServer(opts ...ServerOpt) {
	port := port.Get(opts)
	fmt.Printf("listening on port %v\n", port)

	rt := roundTripper.Get(opts).(http.RoundTripper)
	if rt == http.DefaultTransport {
Example #2
0
func InstrumentOptimize(i bool) HiveOption { return HiveOption(instrument(i)) }

var optimizeThresh = args.NewUint(args.Flag("optthresh", uint(10),
	"when the local stat collector should notify the optimizer (in msg/s)."))

// OptimizeThresh represents the minimum message rate (i.e., the number of
// messages per second) after which we notify the optimizer.
func OptimizeThresh(t uint) HiveOption { return HiveOption(optimizeThresh(t)) }

var statePath = args.NewString(args.Flag("statepath", "/tmp/beehive",
	"where to store persistent state data"))

// StatePath represents where the hive should save its state.
func StatePath(p string) HiveOption { return HiveOption(statePath(p)) }

var raftTick = args.NewDuration(args.Flag("rafttick", 100*time.Millisecond,
	"raft tick period"))

// RaftTick represents the raft tick.
func RaftTick(t time.Duration) HiveOption { return HiveOption(raftTick(t)) }

var raftTickDelta = args.NewDuration(args.Flag("deltarafttick",
	0*time.Millisecond, "max random duration added to the raft tick per tick"))

// RaftTickDelta represents the random tick to add to the main raft tick.
func RaftTickDelta(d time.Duration) HiveOption {
	return HiveOption(raftTickDelta(d))
}

var raftFsyncTick = args.NewDuration(args.Flag("raftfsync", 1*time.Second,
	"the frequency of raft fsync. 0 means always sync immidiately"))