예제 #1
0
    def config(self,
               config,
               servername=None,
               dbconfig=None,
               memconfig=None,
               masterconf=None):
        '''配置服务器
        '''
        GlobalObject().json_config = config
        GlobalObject().remote_connect = self.remote_connect
        netport = config.get('netport')  #客户端连接
        webport = config.get('webport')  #http连接
        rootport = config.get('rootport')  #root节点配置
        self.remoteportlist = config.get('remoteport', [])  #remote节点配置列表
        if not servername:
            servername = config.get('name')  #服务器名称
        logpath = config.get('log')  #日志
        hasdb = config.get('db')  #数据库连接
        hasmem = config.get('mem')  #memcached连接
        app = config.get('app')  #入口模块名称
        cpuid = config.get('cpu')  #绑定cpu
        mreload = config.get('reload')  #重新加载模块名称
        self.servername = servername

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = Flask("servername")
            GlobalObject().webroot = self.webroot
            reactor.listenWSGI(webport, self.webroot)

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername)

        if hasdb and dbconfig:
            if dbconfig.has_key("user") and dbconfig.has_key(
                    "host") and dbconfig.has_key("host"):
                dbpool.initPool({"default": dbconfig})
            else:
                dbpool.initPool(dbconfig)

        if hasmem and memconfig:
            urls = memconfig.get('urls')
            #             hostname = str(memconfig.get('hostname'))
            memcached_connect(urls)
            from gfirefly.dbentrust.util import M2DB_PORT, M2DB_HOST, ToDBAddress
            ToDBAddress().setToDBHost(memconfig.get("pubhost", M2DB_HOST))
            ToDBAddress().setToDBPort(memconfig.get("pubport", M2DB_PORT))

        if logpath:
            log.addObserver(loogoo(logpath))  #日志处理
        log.startLogging(sys.stdout)

        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)
        GlobalObject().config(netfactory=self.netfactory,
                              root=self.root,
                              remote=self.remote)

        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload,
                                                     fromlist=_path_list[:1])

        if masterconf:
            masterport = masterconf.get('rootport')
            masterhost = masterconf.get('roothost')
            self.master_remote = RemoteObject(servername)
            GlobalObject().masterremote = self.master_remote
            import admin
            addr = ('localhost',
                    masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
예제 #2
0
파일: server.py 프로젝트: 9miao/G-Firefly
    def config(self, config, servername=None, dbconfig=None,
                memconfig=None, masterconf=None):
        '''配置服务器
        '''
        GlobalObject().json_config = config
        GlobalObject().remote_connect = self.remote_connect
        netport = config.get('netport')#客户端连接
        webport = config.get('webport')#http连接
        rootport = config.get('rootport')#root节点配置
        self.remoteportlist = config.get('remoteport',[])#remote节点配置列表
        if not servername:
            servername = config.get('name')#服务器名称
        logpath = config.get('log')#日志
        hasdb = config.get('db')#数据库连接
        hasmem = config.get('mem')#memcached连接
        app = config.get('app')#入口模块名称
        cpuid = config.get('cpu')#绑定cpu
        mreload = config.get('reload')#重新加载模块名称
        self.servername = servername
            
        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport,self.netfactory)
            
        if webport:
            self.webroot = Flask("servername")
            GlobalObject().webroot = self.webroot
            reactor.listenWSGI(webport, self.webroot)
            
        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))
            
        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername)
            
        if hasdb and dbconfig:
            if dbconfig.has_key("user") and dbconfig.has_key("host") and dbconfig.has_key("host"):
                dbpool.initPool({"default":dbconfig})
            else:
                dbpool.initPool(dbconfig)
            
        if hasmem and memconfig:
            urls = memconfig.get('urls')
#             hostname = str(memconfig.get('hostname'))
            memcached_connect(urls)
            from gfirefly.dbentrust.util import M2DB_PORT,M2DB_HOST,ToDBAddress
            ToDBAddress().setToDBHost(memconfig.get("pubhost",M2DB_HOST))
            ToDBAddress().setToDBPort(memconfig.get("pubport",M2DB_PORT))
            
        if logpath:
            log.addObserver(loogoo(logpath))#日志处理
        log.startLogging(sys.stdout)
        
        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)
        GlobalObject().config(netfactory = self.netfactory, root=self.root,
                    remote = self.remote)
        
        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload,fromlist=_path_list[:1])
        
        if masterconf:
            masterport = masterconf.get('rootport')
            masterhost = masterconf.get('roothost')
            self.master_remote = RemoteObject(servername)
            GlobalObject().masterremote = self.master_remote
            import admin
            addr = ('localhost',masterport) if not masterhost else (masterhost,masterport)
            self.master_remote.connect(addr)        
예제 #3
0
#coding:utf8
'''
Created on 2015-1-8

@author: root
'''
from gfirefly.dbentrust.memclient import memcached_connect
memcached_connect(["127.0.0.1:11211"])
from gfirefly.dbentrust.memfields import MemObj, MemFields


class Mcharacter(MemObj):
    def __init__(self, name):
        MemObj.__init__(self, name)
        self.id = MemFields()
        self.level = MemFields()
        self.profession = MemFields()
        self.nickname = MemFields()
        self.guanqia = MemFields()
        self.initFields()


mcharacter = Mcharacter('character:1')
mcharacter.nickname = 'lanjinmin'
mc_other = Mcharacter('character:1')
mc_other2 = Mcharacter('character:2')
print "mcharacter.nickname", mcharacter.nickname
print "mc_other.nickname", mc_other.nickname
print "mc_other2.nickname", mc_other2.nickname
mcharacter.mdelete()
예제 #4
0
# coding:utf8
"""
Created on 2015-1-8

@author: root
"""
from gfirefly.dbentrust.dbpool import dbpool, RouterBase
from gfirefly.dbentrust.memclient import memcached_connect

memcached_connect(["127.0.0.1:11211"])
from gfirefly.dbentrust.memmodel import MemAdmin

aa = {
    "default": {"host": "localhost", "user": "******", "passwd": "111", "db": "legend", "port": 3306, "charset": "utf8"},
    "master": {"host": "localhost", "user": "******", "passwd": "111", "db": "test", "port": 3306, "charset": "utf8"},
}
dbpool.initPool(aa)


class router(RouterBase):
    def db_for_read(self, **kw):
        return "default"

    def db_for_write(self, **kw):
        return "master"


dbpool.bind_router(router)

ma = MemAdmin("tb_role_info", "id", incrkey="id")
mm = ma.getObj(1)