public void GetStauts(JobMsgEntity entity, string jobClass, int configid) { WaitHandle.WaitAll(this.writes); this.reads[0].Reset(); bool haveConfigid = false; foreach (JobBase job in this.bases) { if (configid == job.ConfigId) { haveConfigid = true; entity.JobStatus = job.JobStatus; entity.JobResult = job.JobResult; if (job.JobStatus == JobStatus.Stoped && job.lastEndTime > entity.LastEndTime) { entity.LastEndTime = job.lastEndTime; } } } if (!haveConfigid && this.bases.Count > 0) { entity.JobStatus = this.bases[0].JobStatus; entity.JobResult = this.bases[0].JobResult; if (this.bases[0].lastEndTime > entity.LastEndTime) { entity.LastEndTime = this.bases[0].lastEndTime; } } this.reads[0].Set(); }
public JobMsgEntity Request2(JobMsgEntity jme) { if (jme == null) { throw new Exception("请求参数为空!不允许!"); } if (string.IsNullOrEmpty(jme.Action)) { throw new Exception("未指定操作指令!"); } if (string.IsNullOrEmpty(jme.JobClassFullName)) { throw new Exception("未指定要操作的JOB,请检查配置是否正确,并指定JOB类的全称!"); } jme.HostIP = this.GetIP(); string a; if ((a = jme.Action.ToUpper()) != null) { if (!(a == "RUN")) { if (!(a == "RUNPARALLE")) { if (!(a == "STOP")) { if (!(a == "GETSTATUS")) { if (!(a == "GETJOBINFO")) { goto IL_106; } int configId = int.Parse(jme.JobInfo ?? "0"); jme.JobInfo = JobManager2.Instance.GetJobInfo(jme.JobClassFullName, configId); } else { JobManager2.Instance.GetStauts(jme); } } else { JobManager2.Instance.StopJob(jme.JobClassFullName); } } else { JobManager2.Instance.RunJob(jme, true); } } else { JobManager2.Instance.RunJob(jme, false); } return(jme); } IL_106: throw new Exception("无法解析指令:" + jme.Action); }
public JobMsgEntity Request1(JobMsgEntity jme) { if (jme == null) { throw new Exception("请求参数为空!不允许!"); } if (string.IsNullOrEmpty(jme.Action)) { throw new Exception("未指定操作指令!"); } if (string.IsNullOrEmpty(jme.JobClassFullName)) { throw new Exception("未指定要操作的JOB,请检查配置是否正确,并指定JOB类的全称!"); } string action; if ((action = jme.Action) != null) { if (!(action == "RUN")) { if (!(action == "RUNPARALLE")) { if (!(action == "STOP")) { if (!(action == "GETSTATUS")) { if (!(action == "GETJOBINFO")) { goto IL_121; } jme.JobInfo = JobManager1.Instance.GetJobInfo(jme.JobClassFullName, int.Parse(jme.JobInfo ?? "0")); } else { jme.JobStatus = JobManager1.Instance.GetStauts(jme.JobClassFullName); jme.JobResult = JobManager1.Instance.GetJobResult(jme.JobClassFullName); } } else { JobManager1.Instance.StopJob(jme.JobClassFullName); } } else { JobManager1.Instance.RunJob(jme, true); } } else { JobManager1.Instance.RunJob(jme, false); } return(jme); } IL_121: throw new Exception("无法解析指令:" + jme.Action + ",请注意大小写"); }
public JobMsgEntity Request1(JobMsgEntity jme) { if (jme == null) { throw new Exception("请求参数为空!不允许!"); } if (string.IsNullOrEmpty(jme.Action)) { throw new Exception("未指定操作指令!"); } if (string.IsNullOrEmpty(jme.JobClassFullName)) { throw new Exception("未指定要操作的JOB,请检查配置是否正确,并指定JOB类的全称!"); } string action; if ((action = jme.Action) != null) { if (!(action == "RUN")) { if (!(action == "RUNPARALLE")) { if (!(action == "STOP")) { if (!(action == "GETSTATUS")) { if (!(action == "GETJOBINFO")) { goto IL_121; } jme.JobInfo = JobManager1.Instance.GetJobInfo(jme.JobClassFullName, int.Parse(jme.JobInfo ?? "0")); } else { jme.JobStatus = JobManager1.Instance.GetStauts(jme.JobClassFullName); jme.JobResult = JobManager1.Instance.GetJobResult(jme.JobClassFullName); } } else { JobManager1.Instance.StopJob(jme.JobClassFullName); } } else { JobManager1.Instance.RunJob(jme, true); } } else { JobManager1.Instance.RunJob(jme, false); } return jme; } IL_121: throw new Exception("无法解析指令:" + jme.Action + ",请注意大小写"); }
public void RemoveStoped(JobMsgEntity jme) { WaitHandle.WaitAll(this.reads); this.writes[1].Reset(); for (int i = this.bases.Count - 1; i >= 0; i--) { if (this.bases[i].JobStatus == JobStatus.Stoped) { if (this.bases[i].lastEndTime > jme.LastEndTime) { jme.LastEndTime = this.bases[i].lastEndTime; jme.JobResult = this.bases[i].JobResult; } this.bases.RemoveAt(i); } } this.writes[1].Set(); }
public bool CanotParallel(JobMsgEntity jme, bool needParallel, string jobClass) { bool stop = false; WaitHandle.WaitAll(this.writes); this.reads[4].Reset(); foreach (JobBase one in this.bases) { if ((one.JobStatus == JobStatus.Running || one.JobStatus == JobStatus.Stopping) && !needParallel) { jme.JobInfo = "有实例在运行,此次请求忽略!"; stop = true; break; } } this.reads[4].Set(); return(stop); }
public void RunJob(JobMsgEntity jme, bool needParallel) { string jobClass = jme.JobClassFullName; string param = jme.Param; string[] infos = null; //锁定代码块 object obj; Monitor.Enter(obj = JobManager2.runObj); try { if (jme.JobInfo.IndexOf(":") > -1) { infos = jme.JobInfo.Split(new char[] { ':' }); bool groupRunning = this.GroupSet(jme, jobClass, infos); if (groupRunning) { return; } } if (this.Jobs.ContainsKey(jobClass)) { if (this.Jobs[jobClass].CanotParallel(jme, needParallel, jobClass)) { return; } this.Jobs[jobClass].RemoveStoped(jme); } this.AddJobAndRun(jobClass, param, (infos == null) ? jme.JobInfo : infos[0]); } finally { Monitor.Exit(obj); } jme.JobInfo = "开始运行新实例!"; }
private bool GroupSet(JobMsgEntity jme, string jobClass, string[] groupset) { bool groupRunning = false; if (!string.IsNullOrEmpty(groupset[1]) && !string.IsNullOrEmpty(groupset[2])) { string flag = groupset[1]; int prority = int.Parse(groupset[2]); if (!this.ExistGroupInfo(jobClass)) { this.Groups.Add(new GroupInfo { JobClass = jobClass, Flag = flag, Prority = prority }); } for (int i = this.Groups.Count - 1; i >= 0; i--) { if (this.Groups[i].Flag == flag) { if (this.Groups[i].Prority < prority) { this.StopJob(this.Groups[i].JobClass); } else { int configId = int.Parse((groupset == null) ? jme.JobInfo : groupset[0]); if (this.GetJobStauts(this.Groups[i].JobClass, configId) == JobStatus.Running) { jme.JobInfo = groupset[1] + "组内,有更高优先级的实例(" + this.Groups[i].JobClass + ")在运行,此次请求忽略!"; groupRunning = true; } } } } } return(groupRunning); }
internal void GetStauts(JobMsgEntity entity) { string jobClass = entity.JobClassFullName; int configid = int.Parse(entity.JobInfo ?? "0"); entity.JobStatus = JobStatus.Stop; entity.JobResult = JobResult.Success; object obj; Monitor.Enter(obj = JobManager2.runObj); try { if (this.Jobs.ContainsKey(jobClass)) { this.Jobs[jobClass].GetStauts(entity, jobClass, configid); } } finally { Monitor.Exit(obj); } }
public void RunJob(JobMsgEntity jme, bool needParallel) { string jobClassFullName = jme.JobClassFullName; string jobNameSpace = jme.JobNameSpace; string param = jme.Param; string[] array = null; if (jme.JobInfo.IndexOf(":") > -1) { array = jme.JobInfo.Split(new char[] { ':' }); if (!string.IsNullOrEmpty(array[1]) && !string.IsNullOrEmpty(array[2])) { //组中是否存在相同的作业 if (!this.ExistGroupInfo(jobClassFullName)) { this.groupInfo.Add(new GroupInfo { JobClass = jobClassFullName, Flag = array[1], Prority = int.Parse(array[2]) }); } //优先级处理 for (int i = this.groupInfo.Count - 1; i >= 0; i--) { if (this.groupInfo[i].Flag == array[1]) { //停止优先级低的作业 if (this.groupInfo[i].Prority < int.Parse(array[2])) { this.StopJob(this.groupInfo[i].JobClass); } else { if (this.GetStauts(this.groupInfo[i].JobClass) == JobStatus.Running) { jme.JobInfo = array[1] + "组内,有更高优先级的实例(" + this.groupInfo[i].JobClass + ")在运行,此次请求忽略!"; return; } } } } } } if (this.pool.ContainsKey(jobClassFullName)) { JobBase jobBase = this.pool[jobClassFullName][0]; //有实例运行 if ((jobBase.JobStatus == JobStatus.Running || jobBase.JobStatus == JobStatus.Stopping) && !needParallel) { jme.JobInfo = "有实例在运行,此次请求忽略!"; return; } for (int j = this.pool[jobClassFullName].Count - 1; j >= 0; j--) { if (this.pool[jobClassFullName][j].JobStatus == JobStatus.Stoped) { if (this.pool[jobClassFullName][j].lastEndTime > jme.LastEndTime) { jme.LastEndTime = this.pool[jobClassFullName][j].lastEndTime; jme.JobResult = this.pool[jobClassFullName][j].JobResult; } this.pool[jobClassFullName].RemoveAt(j); } } } this.AddJobToRun(jobNameSpace, jobClassFullName, param, (array == null) ? jme.JobInfo : array[0]); jme.JobInfo = "开始运行新实例!"; }
public bool CanotParallel(JobMsgEntity jme, bool needParallel, string jobClass) { bool stop = false; WaitHandle.WaitAll(this.writes); this.reads[4].Reset(); foreach (JobBase one in this.bases) { if ((one.JobStatus == JobStatus.Running || one.JobStatus == JobStatus.Stopping) && !needParallel) { jme.JobInfo = "有实例在运行,此次请求忽略!"; stop = true; break; } } this.reads[4].Set(); return stop; }
private bool GroupSet(JobMsgEntity jme, string jobClass, string[] groupset) { bool groupRunning = false; if (!string.IsNullOrEmpty(groupset[1]) && !string.IsNullOrEmpty(groupset[2])) { string flag = groupset[1]; int prority = int.Parse(groupset[2]); if (!this.ExistGroupInfo(jobClass)) { this.Groups.Add(new GroupInfo { JobClass = jobClass, Flag = flag, Prority = prority }); } for (int i = this.Groups.Count - 1; i >= 0; i--) { if (this.Groups[i].Flag == flag) { if (this.Groups[i].Prority < prority) { this.StopJob(this.Groups[i].JobClass); } else { int configId = int.Parse((groupset == null) ? jme.JobInfo : groupset[0]); if (this.GetJobStauts(this.Groups[i].JobClass, configId) == JobStatus.Running) { jme.JobInfo = groupset[1] + "组内,有更高优先级的实例(" + this.Groups[i].JobClass + ")在运行,此次请求忽略!"; groupRunning = true; } } } } } return groupRunning; }
public JobMsgEntity Request2(JobMsgEntity jme) { if (jme == null) { throw new Exception("请求参数为空!不允许!"); } if (string.IsNullOrEmpty(jme.Action)) { throw new Exception("未指定操作指令!"); } if (string.IsNullOrEmpty(jme.JobClassFullName)) { throw new Exception("未指定要操作的JOB,请检查配置是否正确,并指定JOB类的全称!"); } jme.HostIP = this.GetIP(); string a; if ((a = jme.Action.ToUpper()) != null) { if (!(a == "RUN")) { if (!(a == "RUNPARALLE")) { if (!(a == "STOP")) { if (!(a == "GETSTATUS")) { if (!(a == "GETJOBINFO")) { goto IL_106; } int configId = int.Parse(jme.JobInfo ?? "0"); jme.JobInfo = JobManager2.Instance.GetJobInfo(jme.JobClassFullName, configId); } else { JobManager2.Instance.GetStauts(jme); } } else { JobManager2.Instance.StopJob(jme.JobClassFullName); } } else { JobManager2.Instance.RunJob(jme, true); } } else { JobManager2.Instance.RunJob(jme, false); } return jme; } IL_106: throw new Exception("无法解析指令:" + jme.Action); }