// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ // ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com package engine.job; import engine.core.ControlledRunnable; import engine.server.MBServerStatics; import engine.util.ThreadUtils; import org.pmw.tinylog.Logger; import java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; /** * Note to DEVs. When attempting to log something in this class, use logDIRECT * only. */ public class JobManager extends ControlledRunnable { /* * Singleton implementation. */ private static volatile JobManager INSTANCE; public static JobManager getInstance() { if (JobManager.INSTANCE == null) { synchronized (JobManager.class) { if (JobManager.INSTANCE == null) { JobManager.INSTANCE = new JobManager(); JobManager.INSTANCE.startup(); } } } return JobManager.INSTANCE; } /* * Class implementation */ private final ArrayList jobPoolList = new ArrayList<>(); private final ConcurrentHashMap jobQueueMapping= new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_HIGH); private boolean shutdownNowFlag = false; private JobManager() { super("JobManager"); // create the initial job pools with the correct sizes // based on the number of array elements in the initial_jo_workers // definition in Statisc if (MBServerStatics.INITIAL_JOBPOOL_WORKERS != null && MBServerStatics.INITIAL_JOBPOOL_WORKERS.length >0 ) { for (int i=0; i required"; } public String resetJobs() { // moves all jobs to the P1 queue this.jobQueueMapping.clear(); return "All Jobs reset onto P1 queue"; } public String showJobs() { String out = ""; Iterator jmi = this.jobQueueMapping.keySet().iterator(); while (jmi.hasNext()) { String jmiKey = jmi.next(); out += jmiKey + ' ' + this.jobQueueMapping.get(jmiKey).getJobPoolID() + '\n'; } return out; } public ArrayList getJobPoolList() { return this.jobPoolList; } public String modifyJobPoolWorkers(String jobPoolID, String maxWorkers) { try { // parse string into an int Integer jid = Integer.parseInt(jobPoolID); Integer mw = Integer.parseInt(maxWorkers); for (JobPool jp : this.jobPoolList) { if (jp.getJobPoolID() == jid) { // change the number of workers return jp.setMaxWorkers(mw); } } } catch (NumberFormatException e) { return "Invalid parameters required"; } return "Invalid parameters required"; } }