%MapReduceRemoteCache
% Class for holding details for a given mapreduce call on the workers.

% Copyright 2014-2016 The MathWorks, Inc.

classdef (Sealed, Hidden) MapReduceRemoteCache < handle

properties (GetAccess = private, SetAccess = immutable)
RemoteValue; % An instance of parallel.pool.Constant that embodies the data stored on worker.
end

methods
% Construct a client-side reference to the data to be put on the
% worker.
function obj = MapReduceRemoteCache(inputDatastore, mapFunction, reduceFunction, shuffleSortStrategy)
import parallel.pool.Constant;

remoteStruct.InputDatastore = inputDatastore;
remoteStruct.MapFunction = mapFunction;
remoteStruct.ReduceFunction = reduceFunction;
remoteStruct.ShuffleSortStrategy = shuffleSortStrategy;
obj.RemoteValue = Constant(remoteStruct);
end

% Get the input datastore
function inputDatastore = getInputDatastore(obj)
inputDatastore = obj.RemoteValue.Value.InputDatastore;
end

% Get the mapper function
function mapFunction = getMapFunction(obj)
mapFunction = obj.RemoteValue.Value.MapFunction;
end

% Get the reducer function
function reduceFunction = getReduceFunction(obj)
reduceFunction = obj.RemoteValue.Value.ReduceFunction;
end

% Get the shuffle-sort strategy
function shuffleSortStrategy = getShuffleSortStrategy(obj)
shuffleSortStrategy = obj.RemoteValue.Value.ShuffleSortStrategy;
end
end
end