Esempio n. 1
0
func newOS(opts ...Option) KV {
	options := Options{
		Internal: true,
	}
	for _, o := range opts {
		o(&options)
	}

	if options.Client == nil {
		options.Client = client.DefaultClient
	}

	if options.Server == nil {
		options.Server = server.DefaultServer
	}

	if options.Replicas == 0 {
		options.Replicas = 1
	}

	o := &os{
		exit:   make(chan bool),
		opts:   options,
		hash:   consistent.New(),
		nodes:  make(map[string]int64),
		client: store.NewStoreClient(serviceName, options.Client),
	}

	// If using gossip then add the handlers and run the broadcaster
	if !o.opts.Service {
		options.Server.Subscribe(
			options.Server.NewSubscriber(
				GossipTopic,
				o.subscriber,
				server.InternalSubscriber(options.Internal),
			),
		)

		options.Server.Handle(
			options.Server.NewHandler(
				&proto.KV{new(kv)},
				server.InternalHandler(options.Internal),
			),
		)

		go o.run()
	}

	return o
}
Esempio n. 2
0
func registerDebugHandler(s server.Server) {
	s.Handle(s.NewHandler(&Debug{s.Options().DebugHandler}, server.InternalHandler(true)))
}