Пример #1
0
        public TaskEnumeratorResult GetEnumerator(TaskEnumeratorPointer pointer)
        {
            if (this.enumerators == null)
            {
                this.enumerators = new HashVector();
            }

            if (this.enumerators.ContainsKey(pointer))
            {
                throw new InvalidTaskEnumeratorException("Enumerator already exists with specified Pointer.");
            }
            if (!IsValidPointer(pointer))
            {
                throw new InvalidTaskEnumeratorException("Invalid Enumerator Pointer specified.");
            }

            IEnumerator it = this.output.GetEnumerator();

            it.MoveNext();
            lock (_mutex)
            {
                this.enumerators.Add(pointer, it);
            }
            return(NextRecord(pointer));
        }
Пример #2
0
        public TaskPartitionedEnumerator(TaskEnumeratorHandler remoteCache, TaskEnumeratorPointer pntr,
                                         DictionaryEntry entry, string nodeaddress, bool isLast)
        {
            this.handler       = remoteCache;
            this.pointer       = pntr;
            this.nextRecordSet = entry;
            this.nodeAddress   = nodeaddress;
            this.isLastResult  = isLast;

            this.callbackId = pointer.CallbackId;

            if (nextRecordSet.Key != null)
            {
                isValid = true;
            }
        }
Пример #3
0
        public TaskEnumeratorResult NextRecord(TaskEnumeratorPointer pointer)
        {
            if (!this.enumerators.ContainsKey(pointer))
            {
                throw new InvalidTaskEnumeratorException("Enumerator does not exist with specified Pointer.");
            }

            TaskEnumeratorResult result = new TaskEnumeratorResult();

            result.Pointer = pointer;

            IEnumerator it = null;

            lock (_mutex)
            {
                it = (IEnumerator)this.enumerators[pointer];
            }

            try
            {
                if (it.Current != null)
                {
                    TaskOutputPair pair = (TaskOutputPair)it.Current;
                    result.RecordSet = new DictionaryEntry(pair.Key, pair.Value);
                }
            }
            catch (Exception exx) { }

            if (!it.MoveNext())
            {
                result.IsLastResult = true;
                lock (_mutex)
                {
                    this.enumerators.Remove(pointer);
                }

                this.RemoveFromListeners(pointer);

                if (this.enumerators.Count == 0 && this.listeners.Count == 0)
                {
                    disposeOutput = true;
                }
            }
            return(result);
        }
Пример #4
0
 private bool IsValidPointer(TaskEnumeratorPointer pointer)
 {
     if (this.listeners != null)
     {
         lock (_mutex)
         {
             IEnumerator it = this.listeners.GetEnumerator();
             while (it.MoveNext())
             {
                 TaskCallbackInfo callbackInfo = (TaskCallbackInfo)it.Current;
                 if ((callbackInfo.Client.Equals(pointer.ClientId) && (callbackInfo.CallbackId.Equals(pointer.CallbackId))))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Пример #5
0
 private void RemoveFromListeners(TaskEnumeratorPointer pointer)
 {
     if (listeners != null)
     {
         lock (_mutex)
         {
             IEnumerator itListeners = listeners.GetEnumerator();
             // change to for loop.
             for (int i = 0; i < listeners.Count; i++)
             {
                 TaskCallbackInfo callBackInfo = (TaskCallbackInfo)listeners[i];
                 if (callBackInfo.Client.Equals(pointer.ClientId) && ((short)callBackInfo.CallbackId).Equals(pointer.CallbackId))
                 {
                     listeners.RemoveAt(i);
                 }
             }
         }
     }
 }
Пример #6
0
        public TaskEnumeratorResult NextRecord(TaskEnumeratorPointer pointer)
        {
            lock (objectMutex) {
                if (TaskOutputExists(pointer.TaskId))
                {
                    TaskOutput           output = (TaskOutput)taskOutput[pointer.TaskId];
                    TaskEnumeratorResult result = output.NextRecord(pointer);

                    if (output.OutputDisposed)
                    {
                        taskOutput.Remove(pointer.TaskId);
                    }

                    return(result);
                }
                else
                {
                    throw new InvalidTaskEnumeratorException("Output with task id : " + pointer.TaskId + " got corrupted.");
                }
            }
        }
Пример #7
0
        public TaskEnumeratorResult GetTaskEnumerator(TaskEnumeratorPointer pointer)
        {
            lock (objectMutex)
            {
                if (TaskOutputExists(pointer.TaskId))
                {
                    TaskOutput           output = (TaskOutput)taskOutput[pointer.TaskId];
                    TaskEnumeratorResult result = output.GetEnumerator(pointer);

                    if (output.OutputDisposed)
                    {
                        taskOutput.Remove(pointer.TaskId);
                    }

                    return(result);
                }
                else
                {
                    throw new InvalidTaskEnumeratorException("Output with taskId '" + pointer.TaskId + "' does not exist. Task might be cancelled or failed.");
                }
            }
        }
Пример #8
0
        private Object NextRecord(MapReduceOperation operation)
        {
            TaskEnumeratorPointer pointer = (TaskEnumeratorPointer)operation.Data;

            // Task cancellation check
            if (this.cancelledTask.Contains(pointer.TaskId))
            {
                throw new OperationFailedException("Task with specified Task ID was Cancelled.");
            }

            TaskEnumeratorResult result = null;

            if (taskOutputStore != null)
            {
                try {
                    result             = taskOutputStore.NextRecord(pointer);
                    result.NodeAddress = _context.Render.IPAddress.ToString();
                } catch (InvalidTaskEnumeratorException ex) {
                    _context.NCacheLog.Error("TaskTracker.GetTaskEnumerator", ex.Message);
                    throw ex;
                }
            }
            return(result);
        }
Пример #9
0
        private object GetTaskEnumerator(MapReduceOperation operation)
        {
            TaskEnumeratorPointer pointer = (TaskEnumeratorPointer)operation.Data;

            if (clientAddress == null)
            {
                try {
                    if (_context.Render != null)
                    {
                        clientAddress = new Address(_context.Render.IPAddress, _context.Render.Port);
                    }
                } catch (Exception ex) {
                    throw new InvalidTaskEnumeratorException(ex.Message, ex);
                }
            }
            pointer.ClientAddress = clientAddress;

            if (clusterAddress == null)
            {
#if !CLIENT
                if (_context.CacheImpl is ClusterCacheBase)
                {
                    clusterAddress = ((ClusterCacheBase)_context.CacheImpl).Cluster.LocalAddress;
                }
                else if (_context.CacheImpl is LocalCacheImpl)
                {
                    clusterAddress = new Address(_context.Render.IPAddress, _context.Render.Port);
                }
#else
                clusterAddress = new Address(_context.Render.IPAddress, _context.Render.Port);
#endif
            }

            pointer.ClusterAddress = clusterAddress;

            // Task Cancellation check.
            if (this.cancelledTask.Contains(pointer.TaskId))
            {
                throw new OperationFailedException("Task with specified Task ID was cancelled");
            }

            TaskEnumeratorResult result = null;
            if (taskOutputStore != null)
            {
                try {
                    result = taskOutputStore.GetTaskEnumerator(pointer);
                    //result.NodeAddress = _context.Render.IPAddress.ToString();
                    result.Pointer = pointer;
                } catch (InvalidTaskEnumeratorException ex) {
                    _context.NCacheLog.Error("TaskTracker.GetTaskEnumerator", ex.Message);
                    throw ex;
                }
            }

            if (_context.NCacheLog.IsInfoEnabled)
            {
                _context.NCacheLog.Info("TaskTracker.GetTaskEnumerator", "Task Enumerator provided to client.");
            }

            return(result);
        }
Пример #10
0
 public virtual TaskEnumeratorResult NextRecord(string serverAddress, TaskEnumeratorPointer pointer)
 {
     return(null);
 }