コード例 #1
0
        public IObserveOperationResult ExecuteObserveOperation(IObserveOperation op)
        {
            var readResult = new ObserveOperationResult();
            var result     = this.Acquire();

            if (result.Success && result.HasValue)
            {
                try
                {
                    var socket = result.Value;
                    var b      = op.GetBuffer();

                    socket.Write(b);

                    readResult = op.ReadResponse(socket) as ObserveOperationResult;
                    if (readResult.Success)
                    {
                        readResult.Pass();
                    }
                    else
                    {
                        readResult.InnerResult = result;
                        readResult.Fail("Failed to read response, see inner result for details");
                    }
                    return(readResult);
                }
                catch (IOException e)
                {
                    log.Error(e);

                    readResult.Fail("Exception reading response", e);
                    return(readResult);
                }
                finally
                {
                    ((IDisposable)result.Value).Dispose();
                }
            }
            else
            {
                readResult.Fail("Failed to obtain socket from pool");
                return(readResult);
            }
        }
コード例 #2
0
        public IObserveOperationResult ExecuteObserveOperation(IObserveOperation op)
        {
            var readResult = new ObserveOperationResult();
            var result = this.Acquire();
            if (result.Success && result.HasValue)
            {
                try
                {
                    var socket = result.Value;
                    var b = op.GetBuffer();

                    socket.Write(b);

                    readResult = op.ReadResponse(socket) as ObserveOperationResult;
                    if (readResult.Success)
                    {
                        readResult.Pass();
                    }
                    else
                    {
                        readResult.InnerResult = result;
                        readResult.Fail("Failed to read response, see inner result for details");
                    }
                    return readResult;
                }
                catch (IOException e)
                {
                    log.Error(e);
                    readResult.StatusCode = StatusCode.UnspecifiedError;
                    readResult.Fail("Exception reading response", e);
                    return readResult;
                }
                finally
                {
                    ((IDisposable)result.Value).Dispose();
                }
            }
            else
            {
                result.Combine(readResult);
                return readResult;
            }
        }
コード例 #3
0
 public IObserveOperationResult ExecuteObserveOperation(IObserveOperation op)
 {
     return Execute(op) as IObserveOperationResult;
 }
コード例 #4
0
        private IObserveOperationResult checkNodesForKey(ObservedNode[] nodes, IObserveOperation command, ref bool isMasterInExpectedState, ref int replicaFoundCount, ref int replicaPersistedCount, ObserveKeyState persistedKeyState, ObserveKeyState replicatedKeyState)
        {
            var tmpReplicaFoundCount = 0;
            var tmpReplicaPersistedCount = 0;
            var tmpIsPersistedToMaster = false;
            var result = new ObserveOperationResult();

            var lockObject = new object();
            foreach (var node in nodes)
            {
                lock (lockObject)
                {
                    var opResult = node.Node.ExecuteObserveOperation(command);
                    if (log.IsDebugEnabled) log.Debug("Node: " + node.Node.EndPoint + ", Result: " + opResult.KeyState + ", Master: " + node.IsMaster + ", Cas: " + opResult.Cas + ", Key: " + _settings.Key);

                    if (!opResult.Success) //Probably an IO Exception
                    {
                        break;
                    }
                    else if (node.IsMaster && opResult.Cas != _settings.Cas &&
                             (persistedKeyState == ObserveKeyState.FoundPersisted ||
                              replicatedKeyState == ObserveKeyState.FoundNotPersisted))
                    {
                        result.Success = false;
                        result.Message = ObserveOperationConstants.MESSAGE_MODIFIED;
                        break;
                    }
                    else if (opResult.KeyState == persistedKeyState)
                    {
                        node.KeyIsPersisted = true;
                        if (node.IsMaster)
                        {
                            tmpIsPersistedToMaster = true;
                        }
                        else
                        {
                            tmpReplicaPersistedCount++;
                        }
                    }
                    else if (opResult.KeyState == replicatedKeyState)
                    {
                        if (!node.IsMaster)
                        {
                            tmpReplicaFoundCount++;
                        }
                    }
                }
            }

            isMasterInExpectedState = tmpIsPersistedToMaster;
            replicaFoundCount = tmpReplicaFoundCount;
            replicaPersistedCount = tmpReplicaPersistedCount;

            if (log.IsDebugEnabled) log.Debug("Master Persisted: " + tmpIsPersistedToMaster + ", Replica Found: " + replicaFoundCount + ", Replica Persisted: " + tmpReplicaPersistedCount);

            return result;
        }
コード例 #5
0
        private IObserveOperationResult checkNodesForKey(ObservedNode[] nodes, IObserveOperation command, ref bool isMasterInExpectedState, ref int replicaFoundCount, ref int replicaPersistedCount)
        {
            var tmpReplicaFoundCount     = 0;
            var tmpReplicaPersistedCount = 0;
            var tmpIsPersistedToMaster   = false;
            var result = new ObserveOperationResult();

            var lockObject = new object();

            foreach (var node in nodes)
            {
                lock (lockObject)
                {
                    var opResult = node.Node.ExecuteObserveOperation(command);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Node: " + node.Node.EndPoint + ", Result: " + opResult.KeyState + ", Master: " + node.IsMaster + ", Cas: " + opResult.Cas + ", Key: " + _settings.Key);
                    }

                    if (!opResult.Success)                     //Probably an IO Exception
                    {
                        break;
                    }
                    else if (node.IsMaster && opResult.Cas != _settings.Cas)
                    {
                        result.Success = false;
                        result.Message = ObserveOperationConstants.MESSAGE_MODIFIED;
                        break;
                    }
                    else if (opResult.KeyState == ObserveKeyState.FoundPersisted)
                    {
                        node.KeyIsPersisted = true;
                        if (node.IsMaster)
                        {
                            tmpIsPersistedToMaster = true;
                        }
                        else
                        {
                            tmpReplicaPersistedCount++;
                        }
                    }
                    else if (opResult.KeyState == ObserveKeyState.FoundNotPersisted)
                    {
                        if (!node.IsMaster)
                        {
                            tmpReplicaFoundCount++;
                        }
                    }
                }
            }

            isMasterInExpectedState = tmpIsPersistedToMaster;
            replicaFoundCount       = tmpReplicaFoundCount;
            replicaPersistedCount   = tmpReplicaPersistedCount;

            if (log.IsDebugEnabled)
            {
                log.Debug("Master Persisted: " + tmpIsPersistedToMaster + ", Replica Found: " + replicaFoundCount + ", Replica Persisted: " + tmpReplicaPersistedCount);
            }

            return(result);
        }
コード例 #6
0
 public IObserveOperationResult ExecuteObserveOperation(IObserveOperation op)
 {
     return(Execute(op) as IObserveOperationResult);
 }