%AbstractTask
% Interface for tasks that will execute within a mapreduce call.
% Implementors of this should be serializable.

% Copyright 2014-2016 The MathWorks, Inc.

classdef (Abstract, Hidden) AbstractTask < handle

properties
ShuffleSortStrategy; % The Shuffle-Sort Strategy associated with this task.

MapReduceRemoteCache; % A reference of job-wide data held by the worker.
% This is allowed to be empty.
end

methods
function obj = AbstractTask(input)
if isa(input, 'parallel.internal.mapreduce.MapReduceRemoteCache')
obj.MapReduceRemoteCache = input;
else
obj.ShuffleSortStrategy = input;
end
end
end

methods (Abstract)
% Run the task
result = run(obj);
end

methods (Access = protected)
function shuffleSortStrategy = getShuffleSortStrategy(obj)
if isempty(obj.MapReduceRemoteCache)
shuffleSortStrategy = obj.ShuffleSortStrategy;
else
shuffleSortStrategy = obj.MapReduceRemoteCache.getShuffleSortStrategy();
end
end
end

methods (Abstract, Hidden)
% Launch a task on the given pool.
% Visitor will be an object/struct with both a runOnSingle and a
% runOnAll method. This should call one of those and return the
% result.
future = hLaunchTask(obj, visitor);
end
end