예제 #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
}
예제 #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
}
예제 #3
0
// NewReplicator returns a new Replicator instance that makes calls with the given
// SubChannel to the service defined by SubChannel.GetServiceName(). The given n/w/r
// values will be used as defaults for the replicator when none are provided
// Deprecation: logger is no longer used.
func NewReplicator(s Sender, channel shared.SubChannel, logger log.Logger,
	opts *Options) *Replicator {

	f := forward.NewForwarder(s, channel)

	opts = mergeDefaultOptions(opts, &Options{3, 1, 3, Parallel})
	logger = logging.Logger("replicator")
	if identity, err := s.WhoAmI(); err == nil {
		logger = logger.WithField("local", identity)
	}
	return &Replicator{s, channel, f, logger, opts}
}
예제 #4
0
// NewReplicator returns a new Replicator instance that makes calls with the given
// SubChannel to the service defined by SubChannel.GetServiceName(). The given n/w/r
// values will be used as defaults for the replicator when none are provided
func NewReplicator(s Sender, channel tchannel.Registrar, logger log.Logger,
	opts *Options) *Replicator {

	if logger == nil {
		logger = log.NewLoggerFromLogrus(&logrus.Logger{
			Out: ioutil.Discard,
		})
	}

	f := forward.NewForwarder(s, channel, logger)

	opts = mergeDefaultOptions(opts, &Options{3, 1, 3, Parallel})
	return &Replicator{s, channel, f, logger, opts}
}