Beispiel #1
0
import os
from AORBT.scheduler import Synchronizer
from AORBT.headquarterdb import MySQLDatabase
from AORBT.inmemorydb import InMemoryDB

if  __name__ == '__main__':
    os.system('mysql --user=ccf --password=ccf3322 < teststatusread.sql')    
    mysqldb = MySQLDatabase()
    mysqldb.Connect()
    synch = Synchronizer(InMemoryDB(),mysqldb)
    synch.firstsynch()
    tbldefrid = InMemoryDB().GetTableDefRID()
    tblprofile = InMemoryDB().GetTableProfile()
    
    print tbldefrid.GetRID(1)
    print tbldefrid.GetRID(2)
    print 'max row=',tbldefrid.GetMaxNumberRow()
    listmdn = tblprofile.GetMDNLists()
    for mdn in listmdn:
        rid,channelid = tblprofile.GetProfileInfo(str(mdn))
        print '%s, %s, %s' % (mdn,rid,channelid)
Beispiel #2
0
def mainapp():
    """
    Main fungsi
    """
    try:
        # Mekanisme setup logger
        szformat = '%(asctime)-15s  %(levelname)-8s %(message)s'
        filename = 'aorbtlog.log'
        formater = logging.Formatter(szformat)
        handler = TimedRotatingFileHandler(filename, when='midnight')
        handler.setFormatter(formater)
        logging.getLogger().setLevel(logging.DEBUG)
        logging.getLogger().addHandler(handler)
        
        #Parsing command argument
        rbtadsconfig = ArgvParser('aorbtmain').Parse(sys.argv[1:])
        if (rbtadsconfig == None):
            logging.error('Failed to parse argument')
            return
        logging.info('RBT Ads Server starting at, host=%s, port=%d',
                     rbtadsconfig.GetHostAddress(),
                     rbtadsconfig.GetHostPort())
                     

        # Connect to MySQL database, "download" semua data di table dengan status READ 
        # ke dalam in memory database.
        # Hal ini dapat dilakukan dengan memanggil fungsi firstsynch() di object Synchronizer
        # Sinkronisasi ini kemudian dilanjutkan dengan sinkronisasi untuk flag
        # NEW,UPDATE,dan DELETE dengan memanggil fungsi startsynch
        mysqldb = MySQLDatabase()
        mysqldb.Connect()
        synch = Synchronizer(mysqldb)
        synch.firstsynch()
        synch.startsynch()

        # Start scheduler thread
        schedulerthread = SchedulerThread(synch)
        schedulerthread.setDaemon(True)
        schedulerthread.start()
        
        # Starting up scheduler
        s=sched.scheduler(time.time,time.sleep)
        
        # Start connector, yang berfungsi sebagai TCP/IP Gateway, Connector ini akan mencreate
        # sebuah thread pada setiap connection request dari TCP client
        server = connector.RBTAdsServer((config.GetHostAddress(),
                                         config.GetHostPort()),
                                         connector.RBTAdsRequestHandler)
        serverthread = threading.Thread(target=server.serve_forever)
        logging.info('Set daemon mode to False')
        serverthread.setDaemon(False)
        logging.info('Server thread is starting up')
        serverthread.start()
        logging.info('RBT Ads Scheduler is running, threadname=%s',schedulerthread.getName())
        logging.info('RBT Ads TCP Server is running, threadname=%s',serverthread.getName())
        schedulerthread.join()
        serverthread.join()            
    except:
        print "Trigger Exception, traceback info forward to log file."
        traceback.print_exc(file=open("errlog.txt","a"))
        sys.exit(1)