Esempio n. 1
0
// init configures a Ringpop instance and makes it ready to do comms.
func (rp *Ringpop) init() error {
	if rp.channel == nil {
		return errors.New("Missing channel")
	}

	address, err := rp.identity()
	if err != nil {
		return err
	}

	rp.subChannel = rp.channel.GetSubChannel("ringpop", tchannel.Isolated)
	rp.registerHandlers()

	rp.node = swim.NewNode(rp.config.App, address, rp.subChannel, &swim.Options{
		Clock: rp.clock,
	})
	rp.node.RegisterListener(rp)

	rp.ring = hashring.New(farm.Fingerprint32, rp.configHashRing.ReplicaPoints)
	rp.ring.RegisterListener(rp)

	rp.stats.hostport = genStatsHostport(address)
	rp.stats.prefix = fmt.Sprintf("ringpop.%s", rp.stats.hostport)
	rp.stats.keys = make(map[string]string)

	rp.forwarder = forward.NewForwarder(rp, rp.subChannel)
	rp.forwarder.RegisterListener(rp)

	rp.startTimers()
	rp.setState(initialized)

	return nil
}
Esempio n. 2
0
// NewRingpop returns a new Ringpop instance
func NewRingpop(app, address string, channel *tchannel.Channel, opts *Options) *Ringpop {
	opts = mergeDefault(opts)

	ringpop := &Ringpop{
		app:     app,
		address: address,
		logger:  opts.Logger,
		log:     opts.Logger.WithField("local", address),
		statter: opts.Statter,
	}

	if channel != nil {
		ringpop.channel = channel.GetSubChannel("ringpop", tchannel.Isolated)
		ringpop.registerHandlers()
	}

	ringpop.node = swim.NewNode(app, address, ringpop.channel, &swim.Options{
		Logger: ringpop.logger,
	})
	ringpop.node.RegisterListener(ringpop)

	ringpop.ring = newHashRing(ringpop, farm.Fingerprint32, opts.ReplicaPoints)

	ringpop.stats.hostport = genStatsHostport(ringpop.address)
	ringpop.stats.prefix = fmt.Sprintf("ringpop.%s", ringpop.stats.hostport)
	ringpop.stats.keys = make(map[string]string)

	ringpop.forwarder = forward.NewForwarder(ringpop, ringpop.channel, ringpop.logger)

	return ringpop
}