Exemplo n.º 1
0
    def startNetwork(self ):
        print "Starting network ..."
        print "Starting p2p server ..."
        self.p2pservice = P2PService( self.hostAddress, self.configDesc )

        time.sleep( 1.0 )

        print "Starting task server ..."
        self.taskServer = TaskServer( self.hostAddress, self.configDesc )

        self.p2pservice.setTaskServer( self.taskServer )

        time.sleep( 0.5 )

        print "Starting nodes manager client ..."
        self.nodesManagerClient = NodesManagerClient( self.configDesc.clientUid, "127.0.0.1", self.configDesc.managerPort, self.taskServer.taskManager )
        self.nodesManagerClient.start()
Exemplo n.º 2
0
class RpycHost(ControlSurface):

    suggested_update_time_in_ms = int(RPYC_SUGGESTED_UPDATE_TIME * 1000)

    def __init__(self, c_instance):
        super(RpycHost, self).__init__(c_instance)

        with self._control_surface_injector:
            with self.component_guard():
                self._rpyc_server = TaskServer(
                    LiveApiService,
                    port = RPYC_PORT,
                    protocol_config = dict(
                       allow_all_attrs = True,
                       allow_setattr = True))
                self._rpyc_server.start()

    def disconnect(self):
        self._rpyc_server.close()
        super(RpycHost, self).disconnect()

    @contextlib.contextmanager
    def component_guard(self):
        # [jbo] We do not need all the other shit
        with self.setting_listener_caller():
            yield

    def _call_guarded_listener(self, listener):
        try:
            # [jbo] Ideally we would use rpyc.async() here but we do
            # not have listener_func available.
            self._tasks.add(Task.run(listener))
        except:
            self.log_message("Disconnecting broken listener")
            if traceback != None:
                traceback.print_exc()
            # [jbo] Disconnect listeners potentially leaked by Rpyc
            # broken connections.  Note that because of the ==
            # comparison problem for listeners these listeners might
            # leak still...
            listener.disconnect()
Exemplo n.º 3
0
    def __init__(self, c_instance):
        super(RpycHost, self).__init__(c_instance)

        with self._control_surface_injector:
            with self.component_guard():
                self._rpyc_server = TaskServer(
                    LiveApiService,
                    port = RPYC_PORT,
                    protocol_config = dict(
                       allow_all_attrs = True,
                       allow_setattr = True))
                self._rpyc_server.start()
Exemplo n.º 4
0
class Client:

    ############################
    def __init__(self, configDesc ):

        self.configDesc     = configDesc

        self.lastPingTime   = 0.0
        self.p2service      = None
        self.taskServer     = None
        self.lastPingTime   = time.time()
        self.lastNSSTime    = time.time()

        self.lastNodeStateSnapshot = None

        self.hostAddress    = getHostAddress()

        self.nodesManagerClient = None

        self.doWorkTask     = task.LoopingCall(self.__doWork)
        self.doWorkTask.start(0.1, False)
       
    ############################
    def startNetwork(self ):
        print "Starting network ..."
        print "Starting p2p server ..."
        self.p2pservice = P2PService( self.hostAddress, self.configDesc )

        time.sleep( 1.0 )

        print "Starting task server ..."
        self.taskServer = TaskServer( self.hostAddress, self.configDesc )

        self.p2pservice.setTaskServer( self.taskServer )

        time.sleep( 0.5 )

        print "Starting nodes manager client ..."
        self.nodesManagerClient = NodesManagerClient( self.configDesc.clientUid, "127.0.0.1", self.configDesc.managerPort, self.taskServer.taskManager )
        self.nodesManagerClient.start()

        #self.taskServer.taskManager.addNewTask( )

    ############################
    def stopNetwork(self):
        #FIXME: Pewnie cos tu trzeba jeszcze dodac. Zamykanie serwera i wysylanie DisconnectPackege
        self.p2pservice         = None
        self.taskServer         = None
        self.nodesManagerClient = None

    ############################
    def __doWork(self):
        if self.p2pservice:
            if self.configDesc.sendPings:
                self.p2pservice.pingPeers( self.pingsInterval )

            self.p2pservice.syncNetwork()
            self.taskServer.syncNetwork()

            if time.time() - self.lastNSSTime > self.configDesc.nodeSnapshotInterval:
                self.__makeNodeStateSnapshot()
                self.lastNSSTime = time.time()

                #self.managerServer.sendStateMessage( self.lastNodeStateSnapshot )

    ############################
    def __makeNodeStateSnapshot( self, isRunning = True ):

        peersNum            = len( self.p2pservice.peers )
        lastNetworkMessages = self.p2pservice.getLastMessages()

        if self.taskServer:
            tasksNum                = len( self.taskServer.taskHeaders )
            remoteTasksProgresses   = self.taskServer.taskComputer.getProgresses()
            localTasksProgresses    = self.taskServer.taskManager.getProgresses()
            lastTaskMessages        = self.taskServer.getLastMessages()
            self.lastNodeStateSnapshot = NodeStateSnapshot(     isRunning
                                                           ,    self.configDesc.clientUid
                                                           ,    peersNum
                                                           ,    tasksNum
                                                           ,    self.p2pservice.hostAddress
                                                           ,    self.p2pservice.p2pServer.curPort
                                                           ,    lastNetworkMessages
                                                           ,    lastTaskMessages
                                                           ,    remoteTasksProgresses  
                                                           ,    localTasksProgresses )
        else:
            self.lastNodeStateSnapshot = NodeStateSnapshot( self.configDesc.clientUid, peersNum )

        if self.nodesManagerClient:
            self.nodesManagerClient.sendClientStateSnapshot( self.lastNodeStateSnapshot )