privatevoidvalidate(APICreateSchedulerMessagemsg){ if(msg.getType().equals("simple")){ if(msg.getInterval()==null){ if(msg.getRepeatCount()!=null){ if(msg.getRepeatCount()!=1){ thrownewApiMessageInterceptionException(argerr("interval must be set when use simple scheduler when repeat more than once")); } }else{ thrownewApiMessageInterceptionException(argerr("interval must be set when use simple scheduler when repeat forever")); } }elseif(msg.getInterval()!=null){ if(msg.getRepeatCount()!=null){ if(msg.getInterval()<=0){ thrownewApiMessageInterceptionException(argerr("interval must be positive integer")); }elseif((long)msg.getInterval()*(long)msg.getRepeatCount()*1000L+msg.getStartTime()<0){ thrownewApiMessageInterceptionException(argerr("duration time out of range")); }elseif((long)msg.getInterval()*(long)msg.getRepeatCount()*1000L+msg.getStartTime()>2147454847000L){ thrownewApiMessageInterceptionException(argerr("stopTime out of mysql timestamp range")); } } }
if(msg.getStartTime()==null){ thrownewApiMessageInterceptionException(argerr("startTime must be set when use simple scheduler")); }elseif(msg.getStartTime()!=null&&msg.getStartTime()<0){ thrownewApiMessageInterceptionException(argerr("startTime must be positive integer or 0")); }elseif(msg.getStartTime()!=null&&msg.getStartTime()>2147454847){ // mysql timestamp range is 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. // we accept 0 as startDate means start from current time thrownewApiMessageInterceptionException(argerr("startTime out of range")); }
if(msg.getRepeatCount()!=null&&msg.getRepeatCount()<=0){ thrownewApiMessageInterceptionException(argerr("repeatCount must be positive integer")); } }
if(msg.getType().equals("cron")){ if(msg.getCron()==null||(msg.getCron()!=null&&msg.getCron().isEmpty())){ thrownewApiMessageInterceptionException(argerr("cron must be set when use cron scheduler")); } if((!msg.getCron().contains("?"))||msg.getCron().split(" ").length!=6){ thrownewApiMessageInterceptionException(argerr("cron task must follow format like this : "0 0/3 17-23 * * ?" ")); } if(msg.getInterval()!=null||msg.getRepeatCount()!=null||msg.getStartTime()!=null){ thrownewApiMessageInterceptionException(argerr("cron scheduler only need to specify cron task")); } } }