Beispiel #1
0
// TODO kill some servant if new conf turns it off
func (this *FunServantImpl) recreateServants(cf *config.ConfigServant) {
	log.Info("recreating servants...")

	if this.conf.IdgenWorkerId != cf.IdgenWorkerId {
		log.Debug("recreating servant: idgen")
		var err error
		this.idgen, err = idgen.NewIdGenerator(cf.IdgenWorkerId)
		if err != nil {
			panic(err)
		}
	}

	if cf.Lcache.Enabled() &&
		this.conf.Lcache.MaxItems != cf.Lcache.MaxItems {
		log.Debug("recreating servant: lcache")
		this.lc = cache.NewLruCache(cf.Lcache.MaxItems)
		this.lc.OnEvicted = this.onLcLruEvicted
	}

	if cf.Memcache.Enabled() &&
		!reflect.DeepEqual(*this.conf.Memcache, *cf.Memcache) {
		log.Debug("recreating servant: memcache")
		this.mc = memcache.New(cf.Memcache)
	}

	if cf.Redis.Enabled() &&
		!reflect.DeepEqual(*this.conf.Redis, *cf.Redis) {
		log.Debug("recreating servant: redis")
		this.rd = redis.New(cf.Redis)
	}

	if cf.Mysql.Enabled() &&
		!reflect.DeepEqual(*this.conf.Mysql, *cf.Mysql) {
		log.Debug("recreating servant: mysql")
		this.my = mysql.New(cf.Mysql)

		switch cf.Mysql.CacheStore {
		case "mem":
			this.dbCacheStore = store.NewMemStore(cf.Mysql.CacheStoreMemMaxItems)

		case "redis":
			this.dbCacheStore = store.NewRedisStore(cf.Mysql.CacheStoreRedisPool,
				cf.Redis)

		default:
			panic("unknown cache store")
		}
	}

	if cf.Mongodb.Enabled() &&
		!reflect.DeepEqual(*this.conf.Mongodb, *cf.Mongodb) {
		log.Debug("recreating servant: mongodb")
		this.mg = mongo.New(cf.Mongodb)
	}

	if cf.Couchbase.Enabled() &&
		!reflect.DeepEqual(*this.conf.Couchbase, *cf.Couchbase) {
		log.Debug("recreating servant: couchbase")

		var err error
		// pool is always 'default'
		this.cb, err = couch.New(cf.Couchbase.Servers, "default")
		if err != nil {
			log.Error("couchbase: %s", err)
		}
	}

	this.conf = cf

	log.Info("servants recreated")
}
Beispiel #2
0
func (this *FunServantImpl) createServants() {
	log.Info("creating servants...")

	// proxy can dynamically auto discover peers
	if this.conf.Proxy.Enabled() {
		log.Debug("creating servant: proxy")
		this.proxy = proxy.New(this.conf.Proxy)
	} else {
		panic("peers proxy required")
	}

	log.Debug("creating servant: idgen")
	var err error
	this.idgen, err = idgen.NewIdGenerator(this.conf.IdgenWorkerId)
	if err != nil {
		panic(err)
	}

	if this.conf.Lcache.Enabled() {
		log.Debug("creating servant: lcache")
		this.lc = cache.NewLruCache(this.conf.Lcache.MaxItems)
		this.lc.OnEvicted = this.onLcLruEvicted
	}

	if this.conf.Memcache.Enabled() {
		log.Debug("creating servant: memcache")
		this.mc = memcache.New(this.conf.Memcache)
	}

	if this.conf.Redis.Enabled() {
		log.Debug("creating servant: redis")
		this.rd = redis.New(this.conf.Redis)
	}

	if this.conf.Lock.Enabled() {
		log.Debug("creating servant: lock")
		this.lk = lock.New(this.conf.Lock)
	}

	if this.conf.Mysql.Enabled() {
		log.Debug("creating servant: mysql")
		this.my = mysql.New(this.conf.Mysql)

		switch this.conf.Mysql.CacheStore {
		case "mem":
			this.dbCacheStore = store.NewMemStore(this.conf.Mysql.CacheStoreMemMaxItems)

		case "redis":
			this.dbCacheStore = store.NewRedisStore(this.conf.Mysql.CacheStoreRedisPool,
				this.conf.Redis)

		default:
			panic("unknown mysql cache store")
		}
	}

	if this.conf.Mongodb.Enabled() {
		log.Debug("creating servant: mongodb")
		this.mg = mongo.New(this.conf.Mongodb)
		if this.conf.Mongodb.DebugProtocol ||
			this.conf.Mongodb.DebugHeartbeat {
			mgo.SetLogger(&mongoProtocolLogger{})
			mgo.SetDebug(this.conf.Mongodb.DebugProtocol)
		}
	}

	if this.conf.Couchbase.Enabled() {
		log.Debug("creating servant: couchbase")

		var err error
		// pool is always 'default'
		this.cb, err = couch.New(this.conf.Couchbase.Servers, "default")
		if err != nil {
			log.Error("couchbase: %s", err)
		}
	}

	log.Info("servants created")
}