classdef JobContainer < handle
% JobContainer is an abstract class defining the common behavior between a
% Scheduler and a Job, both able to contain child Jobs.

%    Copyright 2018-2019 The MathWorks, Inc.
    
    properties
        MarkForReuseFlag   % dictates cache policy for all contained jobs
    end
    
    methods(Abstract)
        registerChildJob(Container,NewJob)
    end
    
    methods(Static)
        function [iContainer,vin] = catchJobContainerFromInputArgs(vin)
            % catchJobContainerFromInputArgs detects if an input argument is a JobContainer.
            %
            % [Container,InputArguments] = catchJobContainerFromInputArgs(InputArguments) 
            % splits a JobContainer from the rest of input arguments to a function.
            % catchJobContainerFromInputArgs should only be used within a function with 
            % gather-free scheduler support. If a JobContainer is not present in the input
            % arguments then Container is [], this happens when a user called directly a
            % function with gather-free scheduler support without any scheduler, in this 
            % case it should be possible to use internal.stats.bigdata.Scheduler.createAndRun 
            % to automatically create a scheduler and run this function without other 
            % concurrent jobs.
            
            i = cellfun(@(x) isa(x,'internal.stats.bigdata.JobContainer'),vin);
            if any(i)
                iContainer = vin{i};
                vin(i) = [];
            else
                iContainer = [];
            end
        end
    end
    
end
