示例#1
0
    def handleOperationAndAcknowledgeTheCoordinator(self):
        messageType = None

        if self.Operation.Type == DSMessageType.SetNewValue:
            self.temporarilySetNewValueHandler()
            messageType = DSMessageType.VoteCommit

        elif self.Operation.Type == DSMessageType.RollbackValues:
            self.temporarilyRollbackValuesHandler()
            messageType = DSMessageType.VoteCommit

        if self.flipParticipantAcknowledge == True:
            if messageType == DSMessageType.VoteCommit:
                messageType = DSMessageType.VoteAbort
            else:
                messageType = DSMessageType.VoteCommit

        if messageType == DSMessageType.VoteCommit:
            self.State = DSParticipantOperationStatus.READY
        else:
            self.Abort()

        coordinatorProcess = dsProcessManager.GetCoordinator()
        coordinatorProcess.DSSocket.SendMessage(
            DSMessage(messageType, self.CoordinatorTransactionId))

        if messageType == DSMessageType.VoteCommit:
            #if we are sending VoteCommit, means that the participant in the ready state
            # and should wait specific amount of time for the response from coordinatory
            self.dsTimeout.Run(self.onReadyTimeout)
def setNewValue(value):
    coordinator = dsProcessManager.GetCoordinator()
    if coordinator == None:
        return 'coordinator is not available'

    val = coordinator.DSSocket.SendMessage(
        DSMessage(DSMessageType.SetNewValue, value))
    if val == 'timeout':
        val = 'timeout: coordinator is not responding'
    return val
def rollbackFromPosition(position):
    coordinator = dsProcessManager.GetCoordinator()
    if coordinator == None:
        return 'coordinator is not available'

    val = coordinator.DSSocket.SendMessage(
        DSMessage(DSMessageType.RollbackValues, position))
    if val == 'timeout':
        val = 'timeout: coordinator is not responding'
    return val
def addProcess(pid):
    coordinator = dsProcessManager.GetCoordinator()
    if coordinator == None:
        return 'coordinator is not available'

    newProcess = dsProcessManager.GetProcessByID(pid)
    if newProcess != None:
        return 'the process id is duplicate'

    newProcess = DSProcess(pid, False)
    val = coordinator.DSSocket.SendMessage(
        DSMessage(DSMessageType.SyncNewProcess, newProcess))
    if val == 'timeout':
        return 'timeout: coordinator is not responding'

    newProcess.Run()
    dsProcessManager.AddProcesses([newProcess])
    dataStr = newProcess.DSSocket.SendMessage(DSMessage(DSMessageType.GetData))
    return 'the process with the id \'' + pid + '\' is added and its data is [' + dataStr + ']'
示例#5
0
 def PreCommit(self):
     self.State = DSParticipantOperationStatus.PRECOMMIT
     coordinatorProcess = dsProcessManager.GetCoordinator()
     coordinatorProcess.DSSocket.SendMessage(DSMessage(DSMessageType.PreCommitAcknowledge, self.CoordinatorTransactionId))