% ClientMJSAccess - MJSAccess for use by client MATLAB. Designed to cache
% read only cluster properties to minimise remote calls

% Copyright 2020-2021 The MathWorks, Inc.

classdef (Sealed, Hidden) ClientMJSAccess < parallel.internal.cluster.ForwardingMJSAccess
    
    methods (Access = private)
        function obj = ClientMJSAccess(access)
            obj@parallel.internal.cluster.ForwardingMJSAccess(access);
        end
    end
        
    methods (Static)
        function clientAccess = create(access)           
            cachedAccess = parallel.internal.cluster.CachedMJSAccess(access);
            propertiesToCache = {'AdminUsername', 'AllHostAddresses', 'AllowClientPasswordCache', ...
                'AuthorisationLevel', 'HostName', 'Name', ...
                'ClusterMatlabRoot', 'LookupURL', 'SecurityLevel', ...
                'RequiresOnlineLicensing', 'OperatingSystem', 'MpiLibraryName', ...
                'HasSecureCommunication', 'WorkerProxiesPoolConnections', ...
                'IsRunAsUser'};
            values = access.getClusterProperties(propertiesToCache, []);
            values = cellfun(@(v) v{1}, values, 'UniformOutput', false);
            clusterPropertyMap = containers.Map(propertiesToCache, values);
            cachedAccess.cacheClusterProperties(clusterPropertyMap);
            
            clientAccess = parallel.internal.cluster.ClientMJSAccess(cachedAccess);
        end
    end
end

