classdef JobManagerProxyWaiter < parallel.internal.cloud.Waiter
%

%   Copyright 2014-2020 The MathWorks, Inc.

    properties (SetAccess = immutable)
        JmAccessFactory
    end

    properties (SetAccess = private)
        JmAccess
        JmAccessCleanup
        Error
    end

    
    methods
        function obj = JobManagerProxyWaiter(waitDelay, jmAccessFactory)
            obj@parallel.internal.cloud.Waiter(waitDelay)
            obj.JmAccessFactory = jmAccessFactory;
        end
    end

    methods (Access = protected)
        function ok = doCheck(obj)
            try
                [obj.JmAccess, obj.JmAccessCleanup] = obj.JmAccessFactory.getOrCreate();
                ok = true;
            catch E
                if strcmp(E.identifier, 'parallel:cluster:MJSNotFoundFullySpecified')
                    ok = false;
                    obj.Error = E;
                else
                    rethrow(E);
                end
            end
        end
    end
end
