%HadoopTask
% Helper class that enables auto-attach for the Map/Reduce functions.

%   Copyright 2014-2019 The MathWorks, Inc.

classdef (Sealed, Hidden) HadoopTask < parallel.Task
    properties (Access = private)
        PFunction; % Internal storage for the Function property.
        PStateEnum = parallel.internal.types.States.Pending; % Internal storage for the StateEnum property.
        PDependentFiles = {}; % Internal storage for the DependentFiles property.
    end
    
    methods
        % Construct a HadoopTask from the given Hadoop job, id and function
        % handle/string.
        function this = HadoopTask(parent, id, fcn)
            this = this@parallel.Task(parent, id);
            this.Function = fcn;
        end
    end
    
    methods ( Access = protected )
        % Unimplemented
        destroyTasks( ~ )
        cancelOneTask( ~, ~ )
        getWorker( ~ )
    end
    
    methods ( Hidden )
        % Unimplemented
        pPreTaskEvaluate( ~ )
    end
    
    methods
        function value = hGetProperty(obj, name)
            % hGetProperty supports vectorized calls for arrays of obj and 
            % cell arrays of name, so that remote calls can be minimized with MJS.
            returnCell = iscell(name);
            if ~returnCell
                name = {name};
            end
            value = cell(numel(obj), numel(name) );
            for ii = 1:numel(obj)
                for jj = 1:numel(name)
                    value{ii, jj} = obj(ii).(['P', name{jj}]);
                end
            end

            if numel( obj ) == 1 && ~returnCell
                value = value{1,1};
            end
        end
        
        function hSetPropertyNoCheck(obj, names, values)
            if ~iscell(names)
                names = {names};
                values = {values};
            end
            for ii = 1:length(names)
                obj.(['P', names{ii}]) = values{ii};
            end
        end
    end
end
