function success = initclient()
; %#ok Undocumented
% Copyright 2004-2016 The MathWorks, Inc.

% initclient may be called multiple times because clear classes will clear
% the schema.

% Don't call this on a worker
if feature('isdmlworker')
    success = false;
    return
end

% Call the common initialization.  Log errors that may occur to dctSchedulerMessage.
initCommonLogFcn = @(varargin) dctSchedulerMessage(6, varargin{:});
initcommon(initCommonLogFcn);

% Set the values of the export port and hostname.
config = pctconfig;
% The conditions are necessary because initclient may be called multiple times.
import com.mathworks.toolbox.distcomp.mjs.service.ExportConfigInfo;
if ~ExportConfigInfo.checkIfPortSet()
    portrange = config.portrange;
    % portrange will be either [minPort, maxPort] or 0    
    if isscalar(portrange)
        ExportConfigInfo.useEphemeralPort();
    else
        ExportConfigInfo.setPortRange(portrange(1), ...
                                      portrange(2));
    end
end
export_hostname = config.hostname;
java.lang.System.setProperty('java.rmi.server.hostname',export_hostname);

% Turn down the JINI logging levels to SEVERE, unless they have already
% been set to some other level. This would ensure that the second time this
% function is called we don't change the level.
try
    logger = java.util.logging.Logger.getLogger('net.jini');
    if isempty(logger.getLevel)
        logger.setLevel(java.util.logging.Level.SEVERE);
    end
catch err
    % It's OK to proceed if we couldn't change the log level.
    dctSchedulerMessage(6, 'Failed to change JINI log level to severe.  Reason: %s', ...
        err.getReport());
end

% Register a validator with profiles (if one does not already exist)
if isempty(parallel.settings.Profile.hGetRegisteredValidator())
    validator = parallel.internal.validator.Validator();
    parallel.settings.Profile.hRegisterValidator(validator);
end

% Tell pctconfig that we have used values from it
pctconfig('initclienthasrun', true);
success = true;
end
