Esempio n. 1
0
    def dispatcher(self, TimeOut=2.0):
        try:
            #event loop: listen and multiplex until server process killed
            Msg = "dispatcher server starting"
            PCA_GenLib.WriteLog(Msg, 9)

            while 1:
                Msg = "listener dispatcher server loop"
                PCA_GenLib.WriteLog(Msg, 9)

                Flag = PCA_ThreadLib.GetMainTerminateFlag()
                if Flag == "TRUE":
                    Msg = "end of dispatcher"
                    PCA_GenLib.WriteLog(Msg, 8)
                    break

                readables, writeables, exceptions = select(
                    self.ReadSet, [], [], TimeOut)
                for self.SocketConnection in readables:
                    ##################################
                    #### for ready input sockets #####
                    ##################################
                    if self.SocketConnection in self.SocketConnectionPool:
                        ####################################
                        ## port socket: accept new client ##
                        ## accept should not block	  ##
                        ####################################
                        self.connection, address = self.SocketConnection.accept(
                        )
                        Msg = 'Dispatcher New Connection <%s> from :%s' % (
                            id(self.connection), address
                        )  # connection is a new socket
                        PCA_GenLib.WriteLog(Msg, 1)
                        Msg = 'Create new thread'
                        PCA_GenLib.WriteLog(Msg, 1)
                        PCA_ThreadLib.SetTerminateFlag("FALSE")
                        thread.start_new(ServerThreads, (
                            self.connection,
                            self.XMLCFG,
                        ))

            PCA_ThreadLib.SetMainTerminateFlag("TRUE")
            time.sleep(2)
            PCA_ThreadLib.SetTerminateFlag("TRUE")
            time.sleep(2)
        except:
            Msg = "dispatcher error : <%s>,<%s> " % (sys.exc_type,
                                                     sys.exc_value)
            PCA_GenLib.WriteLog(Msg, 0)
            PCA_ThreadLib.SetMainTerminateFlag("TRUE")
            time.sleep(2)
            PCA_ThreadLib.SetTerminateFlag("TRUE")
            time.sleep(2)
            raise
Esempio n. 2
0
    def dispatcher(self, TimeOut=2.0):
        global ExitFlag
        try:

            Msg = "dispatcher server starting ........"
            PCA_GenLib.WriteLog(Msg, 1)

            while 1:
                Msg = "listener dispatcher server loop %s timeout" % TimeOut
                PCA_GenLib.WriteLog(Msg, 3)

                Flag = PCA_ThreadLib.GetMainTerminateFlag()
                SocketMutex.acquire()
                Flag = ExitFlag
                SocketMutex.release()

                if Flag == "TRUE":
                    Msg = "end of PSAAdapter dispatcher"
                    PCA_GenLib.WriteLog(Msg, 1)
                    break

                readables, writeables, exceptions = select.select(
                    self.ReadSet, [], [], TimeOut)
                for self.SocketConnection in readables:
                    ###################################################################
                    #
                    #  for ready input sockets
                    #
                    ###################################################################
                    if self.SocketConnection in self.SocketConnectionPool:
                        ########################################
                        ##
                        ##     port socket: accept new client
                        ##     accept should not block
                        ##
                        ########################################

                        self.connection, address = self.SocketConnection.accept(
                        )
                        Msg = 'Dispatcher New Connection <%s> from :%s' % (
                            id(self.connection), address
                        )  # connection is a new socket
                        PCA_GenLib.WriteLog(Msg, 1)

                        self.ReadSet.append(
                            self.connection)  # add to select list, wait
                        self.WriteSet.append(
                            self.connection)  # add to select list, wait

                        client_ip = address[0]
                        client_port = address[1]

                        SocketMutex.acquire()
                        ServerID = "active_client"
                        self.SocketBuffer[ServerID] = (self.connection)
                        SocketMutex.release()

                    else:
                        if not self.ConnectionLoginState.has_key(
                                id(self.SocketConnection)):
                            self.ConnectionLoginState[id(
                                self.SocketConnection)] = 'N'
                            Msg = "Set ConnectionLoginState <%s> to N " % id(
                                self.SocketConnection)
                            PCA_GenLib.WriteLog(Msg, 0)

                        SocketMutex.acquire()
                        ServerID = "active_client"
                        self.SocketBuffer[ServerID] = (self.SocketConnection)
                        SocketMutex.release()

                        self.handle_event(self.SocketConnection)

            Msg = "end of dispatcher"
            PCA_GenLib.WriteLog(Msg, 0)

            PCA_ThreadLib.SetMainTerminateFlag("TRUE")
            time.sleep(2)
            PCA_ThreadLib.SetTerminateFlag("TRUE")
            time.sleep(2)

            SocketMutex.acquire()
            ExitFlag = "TRUE"
            SocketMutex.release()
        except:
            Msg = "dispatcher error : <%s>,<%s> " % (sys.exc_type,
                                                     sys.exc_value)
            PCA_GenLib.WriteLog(Msg, 0)
            PCA_ThreadLib.SetMainTerminateFlag("TRUE")
            time.sleep(2)
            PCA_ThreadLib.SetTerminateFlag("TRUE")
            time.sleep(2)

            SocketMutex.acquire()
            ExitFlag = "TRUE"
            SocketMutex.release()
            raise
Esempio n. 3
0
    def __init__(self, XMLCFG, cfg_file_name):
        try:
            PCA_ThreadServer.ThreadAcceptor.__init__(self, XMLCFG)

            self.XMLCFG = XMLCFG
            self.cfg_file_name = cfg_file_name

            PCA_ThreadLib.SetMainTerminateFlag("FALSE")
            PCA_ThreadLib.SetTerminateFlag("FALSE")

            Tag = "APPCFG"
            StartTag = Tag

            StartTag = "<%s>" % Tag
            EndTag = "</%s>" % Tag

            Tag = "SYSTEM_ID"
            self.UID = PCA_XMLParser.GetXMLTagValue(XMLCFG, Tag)
            Msg = "SYSTEM_ID  = <%s>" % (self.UID)
            PCA_GenLib.WriteLog(Msg, 1)

            Tag = "SYSTEM_TYPE"
            self.TYPE = PCA_XMLParser.GetXMLTagValue(XMLCFG, Tag)
            Msg = "SYSTEM_TYPE  = <%s>" % (self.TYPE)
            PCA_GenLib.WriteLog(Msg, 1)

            Tag = "PASSWD"
            self.PASSWD = PCA_XMLParser.GetXMLTagValue(XMLCFG, Tag)
            Msg = "PASSWD  = <%s>" % (self.PASSWD)
            PCA_GenLib.WriteLog(Msg, 1)

            (APPCFG,
             XMLCFG) = PCA_XMLParser.GetTagSection(XMLCFG, StartTag, EndTag)

            TaskList = []
            XMLConfiguration = PCA_XMLConfiguration.File_Reader(APPCFG, "TASK")

            ###################################################################
            #
            #    Read Configuration File to Task List
            #
            ###################################################################

            while 1:

                Task = XMLConfiguration.GetXMLConfiguration()

                if (Task == None):
                    #Msg = "Your Task  = <%s>" % (Task)
                    #PCA_GenLib.WriteLog(Msg,1)
                    break
                else:
                    Msg = "Your Task  = <%s>" % (Task)
                    PCA_GenLib.WriteLog(Msg, 4)
                    ########################################################
                    #
                    #  Connect to Multi Server
                    #
                    ########################################################

                    Tag = "CLIENT_SOCKET"
                    dll_file_name = PCA_XMLParser.GetXMLTagValue(
                        self.XMLCFG, Tag)
                    Msg = "%s=%s" % (Tag, dll_file_name)
                    PCA_GenLib.WriteLog(Msg, 1)

                    Script_File = PCA_DLL.DLL(dll_file_name)
                    factory_function = "Connector"
                    factory_component = Script_File.symbol(factory_function)
                    self.ClientConnector = factory_component(Task)

                    self.ClientConnector.connect()

                    thread.start_new(ResponseThread, (
                        self.SocketBuffer,
                        self.ClientConnector,
                        self.XMLCFG,
                    ))
                    time.sleep(0.5)
                    Tag = "SOURCD_ID"

                    Source_id = PCA_XMLParser.GetXMLTagValue(Task, Tag)
                    Msg = "%s=%s" % (Tag, Source_id)
                    PCA_GenLib.WriteLog(Msg, 1)

                    self.ClientConnectorList.append(
                        (self.ClientConnector, Source_id))
                    self.number_of_server_connection = self.number_of_server_connection + 1

            XMLConfiguration.Close()

            self.parser = PCA_SMPPParser.Parser()
            self.handler = PCA_SMPPParser.Handler()
            self.parser.setContentHandler(self.handler)

        except:
            Msg = "Gateway ProxyAcceptor Initial error : <%s>,<%s> " % (
                sys.exc_type, sys.exc_value)
            PCA_GenLib.WriteLog(Msg, 0)
            raise