public WriteBehindQueueResponse GetWriteBehindQueue(WriteBehindQueueRequest req)
        {
            WriteBehindQueueResponse rsp = null;

            if (_dsManager != null)
            {
                return(rsp);
            }
            WriteBehindAsyncProcessor.WriteBehindQueue queueChunk = new WriteBehindAsyncProcessor.WriteBehindQueue(_parent.Context);
            int    indexOfNextTask  = 0;
            long   currentChunkSize = 0;
            string nextChunkId      = null;

            if (req != null)
            {
                if (NCacheLog.IsInfoEnabled)
                {
                    NCacheLog.Info("DSReplicationCorr.GetWriteBehindQueue", "received chunk request; nextchunkId :" + req.NextChunkId);
                }

                DSWriteBehindOperation operation = null;
                if (_queue == null)
                {
                    WriteBehindAsyncProcessor.WriteBehindQueue queue = null;
                    if (_dsManager._writeBehindAsyncProcess != null)
                    {
                        queue = _dsManager._writeBehindAsyncProcess.CloneQueue();
                    }
                    if (queue != null)
                    {
                        _queue = new WriteBehindAsyncProcessor.WriteBehindQueue(_parent.Context);
                        _queue.MergeQueue(queue);
                    }
                    else
                    {
                        return(null);
                    }
                }

                if (req.NextChunkId != null)
                {
                    for (int i = 0; i < _queue.Count; i++)
                    {
                        operation = _queue[i] as DSWriteBehindOperation;
                        if (operation != null)
                        {
                            if (operation.TaskId == req.NextChunkId)
                            {
                                indexOfNextTask = i;
                                break;
                            }
                        }
                    }
                }

                for (int i = indexOfNextTask; i < _queue.Count; i++)
                {
                    operation = _queue[i] as DSWriteBehindOperation;
                    if (operation != null)
                    {
                        if (currentChunkSize >= CHUNK_SIZE)
                        {
                            nextChunkId = operation.TaskId;
                            break;
                        }
                        currentChunkSize += operation.Size;
                        queueChunk.Enqueue(operation.Key, true, operation);
                    }
                }

                if (nextChunkId == null)
                {
                    _queue.Clear();
                    _queue = null;
                }
                if (queueChunk.Count > 0)
                {
                    rsp = new WriteBehindQueueResponse(queueChunk, nextChunkId, null);
                }
            }

            return(rsp);
        }
        public void ReplicateWriteBehindQueue()
        {
            if (_parent != null)
            {
                if (_dsManager != null)
                {
                    return;
                }

                WriteBehindQueueRequest  req = new WriteBehindQueueRequest(null, null);
                WriteBehindQueueResponse rsp = null;
                if (NCacheLog.IsInfoEnabled)
                {
                    NCacheLog.Info("DSReplicationMgr.ReplicatedQueue", "---->started replicating queue");
                }
                while (true)
                {
                    Address coordinator = _parent.Cluster.Coordinator;
                    if (_parent.Cluster.IsCoordinator)
                    {
                        break;
                    }
                    if (_parent.Cluster.CurrentSubCluster != null)
                    {
                        if (_parent.Cluster.CurrentSubCluster.IsCoordinator)
                        {
                            break;
                        }
                    }

                    try
                    {
                        if (coordinator != null)
                        {
                            rsp = _parent.TransferQueue(coordinator, req);
                        }
                    }
                    catch (SuspectedException se)
                    {
                        System.Threading.Thread.Sleep(5);//wait until view is changed properly
                        continue;
                    }

                    catch (Runtime.Exceptions.TimeoutException te)
                    {
                        continue;
                    }

                    if (rsp != null)
                    {
                        //install the queue

                        WriteBehindAsyncProcessor.WriteBehindQueue chunkOfQueue = rsp.Queue;
                        if (chunkOfQueue != null)
                        {
                            _queue.MergeQueue(chunkOfQueue);
                        }

                        if (rsp.NextChunkId == null)
                        {
                            break;
                        }
                        else
                        {
                            req = new WriteBehindQueueRequest(rsp.NextChunkId, null);
                        }

                        if (NCacheLog.IsInfoEnabled)
                        {
                            NCacheLog.Info("DSReplicationMgr.ReplicatedQueue", "received chunk from " + coordinator + " nextchunkId :" + req.NextChunkId);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                if (NCacheLog.IsInfoEnabled)
                {
                    NCacheLog.Info("DSReplicationMgr.ReplicatedQueue", "queue has been transfered");
                }
                if (_queue.Count > 0)
                {
                    if (NCacheLog.IsInfoEnabled)
                    {
                        NCacheLog.Info("DSReplicationMgr.ReplicatedQueue", "queue count :" + _queue.Count);
                    }

                    if (_dsManager._writeBehindAsyncProcess != null)
                    {
                        _dsManager._writeBehindAsyncProcess.MergeQueue(_parent.Context, _queue);
                    }
                }
                if (NCacheLog.IsInfoEnabled)
                {
                    NCacheLog.Info("DSReplicationMgr.ReplicatedQueue", "---->replication of queue completed");
                }
            }
        }