Ejemplo n.º 1
0
 def sync(self):
     println(bp.getProtocolString(bp.SYNC))
     # this should block now until we get a response
     line = readLine()
     if line != (bp.getProtocolString(bp.SYNC) + "_SUCCESS"):
         raise RuntimeError(
             "Barrier sync failed!")
Ejemplo n.º 2
0
    def initialize(self):
        """
        INIT protocol works as follows:
        START OP_CODE
        PROTOCOL_NUMBER
        SET_BSPJOB_CONF OP_CODE
        NUMBER OF CONF ITEMS (#KEY + #VALUES)
        N-LINES, where line is key and the following the value
        """
        # parse our initial values
        line = readLine()
        # start code is the first
        if line == bp.getProtocolString(bp.START):
            # check the protocol compatibility
            protocolNumber = int(readLine())
            if protocolNumber != self.PROTOCOL_VERSION:
                raise RuntimeError(
                    "Protocol version mismatch: Expected: " + str(self.PROTOCOL_VERSION) +
                    " but got: " + str(protocolNumber))
        line = readLine()
        # parse the configurations
        if line == bp.getProtocolString(bp.SET_BSPJOB_CONF):
            numberOfItems = readLine()
            key = None
            value = None
            for i in range(0, int(numberOfItems), 2):
                key = readLine()
                value = readLine()
                self.config.put(key, value)

        self.ack(bp.START)
Ejemplo n.º 3
0
    def initialize(self):
        """
        INIT protocol works as follows:
        START OP_CODE
        PROTOCOL_NUMBER
        SET_BSPJOB_CONF OP_CODE
        NUMBER OF CONF ITEMS (#KEY + #VALUES)
        N-LINES, where line is key and the following the value
        """
        # parse our initial values
        line = readLine()
        # start code is the first
        if line == bp.getProtocolString(bp.START):
            # check the protocol compatibility
            protocolNumber = int(readLine())
            if protocolNumber != self.PROTOCOL_VERSION:
                raise RuntimeError("Protocol version mismatch: Expected: " +
                                   str(self.PROTOCOL_VERSION) + " but got: " +
                                   str(protocolNumber))
        line = readLine()
        # parse the configurations
        if line == bp.getProtocolString(bp.SET_BSPJOB_CONF):
            numberOfItems = readLine()
            key = None
            value = None
            for i in range(0, int(numberOfItems), 2):
                key = readLine()
                value = readLine()
                self.config.put(key, value)

        self.ack(bp.START)
Ejemplo n.º 4
0
    def getCurrentMessage(self):
        println(bp.getProtocolString(bp.GET_MSG))
        line = readLine()
        # if no message is send it will send %%-1%%
        if line == "%%-1%%":
            return False

        return line;
Ejemplo n.º 5
0
 def readNext(self):
     println(bp.getProtocolString(bp.READ_KEYVALUE))
     line = readLine()
     secondLine = readLine()
     # if no message is send it will send %%-1%%
     if line == "%%-1%%" and secondLine == "%%-1%%":
         return False
     return [line, secondLine]
Ejemplo n.º 6
0
 def getAllPeerNames(self):
     println(bp.getProtocolString(bp.GET_ALL_PEERNAME))
     ln = readLine()
     names = []
     for i in range(int(ln)):
         peerName = readLine()
         names.append(peerName)
     return names
Ejemplo n.º 7
0
 def readNext(self):
     println(bp.getProtocolString(bp.READ_KEYVALUE))
     line = readLine()
     secondLine = readLine()
     # if no message is send it will send %%-1%%
     if line == "%%-1%%" and secondLine == "%%-1%%":
         return False
     return [line, secondLine]
Ejemplo n.º 8
0
 def getAllPeerNames(self):
     println(bp.getProtocolString(bp.GET_ALL_PEERNAME))
     ln = readLine()
     names = []
     for i in range(int(ln)):
         peerName = readLine()
         names.append(peerName)
     return names
Ejemplo n.º 9
0
    def getCurrentMessage(self):
        println(bp.getProtocolString(bp.GET_MSG))
        line = readLine()
        # if no message is send it will send %%-1%%
        if line == "%%-1%%":
            return False

        return line
Ejemplo n.º 10
0
    def getCurrentMessage(self):
        println(bp.getProtocolString(bp.GET_MSG))
        line = readLine()
        # if no message is send it will send %%-1%%
        if line == "%%-1%%":
            return False

        # TODO
        # Problem reported by Roman:
        # If I send any message of the length L, I receive the message with
        # additional (L-1)/2 '^@' symbols after it.

        # return line;
        return line[:len(line)-len(line)//3]
Ejemplo n.º 11
0
def threaded_client(conn):
    try:
        while True:
            data = conn.recv()
            data = data[0] * 256 + data[1]
            data = BP.decode(data)
            print('Received data:', data)
            send_command(conn, data)
    except RuntimeError as e:
        print(e)
    #except Exception as e:
    #print('Exception caught')
    #print(e)
    finally:
        conn.close()
Ejemplo n.º 12
0
 def clear(self):
     println(bp.getProtocolString(bp.CLEAR))
Ejemplo n.º 13
0
 def getPeerIndex(self):
     println(bp.getProtocolString(bp.GET_PEER_INDEX))
     return readLine()
Ejemplo n.º 14
0
 def getPeerNameForIndex(self, index):
     println(bp.getProtocolString(bp.GET_PEERNAME))
     println(str(index));
     return readLine()
Ejemplo n.º 15
0
 def reopenInput(self):
     println(bp.getProtocolString(bp.REOPEN_INPUT))
Ejemplo n.º 16
0
 def done(self):
     println(bp.getProtocolString(bp.TASK_DONE))
     println(bp.getProtocolString(bp.DONE))
Ejemplo n.º 17
0
 def runBSP(self):
     line = readLine()
     # start code is the first
     if line.startswith(bp.getProtocolString(bp.RUN_BSP)):
         self.bspClass.bsp(self)
         self.ack(bp.RUN_BSP)
Ejemplo n.º 18
0
 def write(self, key, value):
     println(bp.getProtocolString(bp.WRITE_KEYVALUE))
     println(key)
     println(value)
Ejemplo n.º 19
0
 def runCleanup(self):
     line = readLine()
     # start code is the first
     if line.startswith(bp.getProtocolString(bp.RUN_CLEANUP)):
         self.bspClass.cleanup(self);
         self.ack(bp.RUN_CLEANUP)
Ejemplo n.º 20
0
 def done(self):
     println(bp.getProtocolString(bp.TASK_DONE))
     println(bp.getProtocolString(bp.DONE))
Ejemplo n.º 21
0
 def send(self, peer, msg):
     println(bp.getProtocolString(bp.SEND_MSG))
     println(peer)
     println(msg)
Ejemplo n.º 22
0
 def runCleanup(self):
     line = readLine()
     # start code is the first
     if line.startswith(bp.getProtocolString(bp.RUN_CLEANUP)):
         self.bspClass.cleanup(self)
         self.ack(bp.RUN_CLEANUP)
Ejemplo n.º 23
0
 def log(self, msg):
     println(bp.getProtocolString(bp.LOG) + msg)
Ejemplo n.º 24
0
 def getNumPeers(self):
     println(bp.getProtocolString(bp.GET_PEER_COUNT))
     return readLine()
Ejemplo n.º 25
0
 def reopenInput(self):
     println(bp.getProtocolString(bp.REOPEN_INPUT))
Ejemplo n.º 26
0
 def clear(self):
     println(bp.getProtocolString(bp.CLEAR))
Ejemplo n.º 27
0
 def write(self, key, value):
     println(bp.getProtocolString(bp.WRITE_KEYVALUE))
     println(key)
     println(value)
Ejemplo n.º 28
0
 def getNumPeers(self):
     println(bp.getProtocolString(bp.GET_PEER_COUNT))
     return readLine()
Ejemplo n.º 29
0
 def getPeerIndex(self):
     println(bp.getProtocolString(bp.GET_PEER_INDEX))
     return readLine()
Ejemplo n.º 30
0
 def runBSP(self):
     line = readLine()
     # start code is the first
     if line.startswith(bp.getProtocolString(bp.RUN_BSP)):
         self.bspClass.bsp(self);
         self.ack(bp.RUN_BSP)
Ejemplo n.º 31
0
 def ack(self, code):
     println(bp.getAckProtocolString(code))
Ejemplo n.º 32
0
 def ack(self, code):
     println(bp.getAckProtocolString(code))
Ejemplo n.º 33
0
 def getNumCurrentMessages(self):
     println(bp.getProtocolString(bp.GET_MSG_COUNT))
     return readLine()
Ejemplo n.º 34
0
 def log(self, msg):
     println(bp.getProtocolString(bp.LOG) + msg)
Ejemplo n.º 35
0
 def sync(self):
     println(bp.getProtocolString(bp.SYNC))
     # this should block now until we get a response
     line = readLine()
     if line != (bp.getProtocolString(bp.SYNC) + "_SUCCESS"):
         raise RuntimeError("Barrier sync failed!")
Ejemplo n.º 36
0
 def send(self, peer, msg):
     println(bp.getProtocolString(bp.SEND_MSG))
     println(peer)
     println(msg)
Ejemplo n.º 37
0
 def getSuperstepCount(self):
     println(bp.getProtocolString(bp.GET_SUPERSTEP_COUNT))
     return readLine()
Ejemplo n.º 38
0
 def getNumCurrentMessages(self):
     println(bp.getProtocolString(bp.GET_MSG_COUNT))
     return readLine()
Ejemplo n.º 39
0
def send_passer_name(conn, message):
    message = message.encode('utf-8')
    for i in range(len(message)):
        conn.send(bytes(divmod(BP.passing(message[i]), 256)))
    conn.send(bytes(divmod(BP.passing(0), 256)))
Ejemplo n.º 40
0
 def getSuperstepCount(self):
     println(bp.getProtocolString(bp.GET_SUPERSTEP_COUNT))
     return readLine()
Ejemplo n.º 41
0
 def getPeerNameForIndex(self, index):
     println(bp.getProtocolString(bp.GET_PEERNAME))
     println(str(index))
     return readLine()