function oldManager = currentJobStorageEventManager(newManager)
    % oldManager = currentJobStorageEventManager(newManager)
    % Get or set the job storage event manager

    % Copyright 2016 The MathWorks, Inc.

    mlock;
    persistent jobStorageEventManager;

    if isempty(jobStorageEventManager)
        jobStorageEventManager = iGetDefaultJobStoragerEventManager();
    end

    oldManager = jobStorageEventManager;

    if nargin > 0
        jobStorageEventManager = newManager;
        dctSchedulerMessage(6, 'Setting a new job storage event manager');
    end
end

%----------------------------------------------------------------
function val = iGetDefaultJobStoragerEventManager()
    persistent defaultEventManager;
    if isempty(defaultEventManager)
        defaultEventManager = parallel.internal.cluster.JobStorageEventManager.getInstance();
    end
    val = defaultEventManager;
end

