Package com.google.code.lightssh.project.scheduler.entity

Examples of com.google.code.lightssh.project.scheduler.entity.JobInterval


    }
    if( trigger == null )
      throw new ApplicationException("时钟["+group+"]["+name+"]不存在!");
   
    boolean enabled = !TriggerState.PAUSED.equals(getTriggerState(trigger.getKey()));
    JobInterval jobInterval = jobIntervalManager.get( name );
    boolean insert = false;
    if( jobInterval == null ){
      jobInterval = new JobInterval();
      jobInterval.setTriggerName(name);
      insert = true;
    }
    jobInterval.setCronExpression(cronExp.toString());
    jobInterval.setEnabled(enabled);
    if( insert )
      this.jobIntervalManager.create(jobInterval);
    else
      this.jobIntervalManager.update(jobInterval);
   
View Full Code Here


    if( triggers == null || triggers.isEmpty() )
      return;
   
    //针对每个Trigger 设置Cron表示达
    for( Trigger trigger:triggers ){
      JobInterval jobInterval = jiMap.get( trigger.getKey().getName() );
      if( trigger instanceof CronTrigger && jobInterval != null ){
        freshTrigger( trigger,jobInterval.isEnabled()
            ,jobInterval.getCronExpression() );
      }
    }//end for
  }
View Full Code Here

      return;
   
    try {
      Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(name, group));
      if( trigger != null && trigger instanceof CronTrigger){
        JobInterval jobInterval = this.jobIntervalManager.get( name );
        if( jobInterval != null ){
          CronScheduleBuilder csb = CronScheduleBuilder.cronSchedule(
              jobInterval.getCronExpression());
         
          trigger = TriggerBuilder.newTrigger()
            .withIdentity( trigger.getKey() )
            .withDescription(trigger.getDescription())
            .withSchedule(csb).build();
          scheduler.rescheduleJob(trigger.getKey(),trigger);
          if( !jobInterval.isEnabled() )
            scheduler.pauseTrigger(trigger.getKey());
        }
      }
    } catch (SchedulerException e) {
      throw new ApplicationException(e);
View Full Code Here

  @Override
  public void changeCronTrigger(String triggerName, String cronExpression) {
    if( triggerName == null || cronExpression == null )
      return;
   
    JobInterval jobInterval = jobIntervalManager.get( triggerName );
    if( jobInterval == null )
      return;
    jobInterval.setCronExpression(cronExpression);
    jobIntervalManager.save(jobInterval);
   
    List<Trigger> triggers = listTriggers( );
    if( triggers == null || triggers.isEmpty() )
      return;
View Full Code Here

  public void toggleTrigger(String triggerName,String group ){
    if( StringUtil.clean(triggerName)==null )
      return;
   
    String cronExpression = null,description;
    JobInterval jobInterval = jobIntervalManager.get( triggerName );
    if( jobInterval != null ){
      jobInterval.setEnabled( Boolean.valueOf( !jobInterval.isEnabled() ) );
      cronExpression = StringUtil.clean(jobInterval.getCronExpression());
    }
   
    Trigger target = null;
    try {
      target = scheduler.getTrigger(TriggerKey.triggerKey(triggerName,group));
    } catch (SchedulerException e) {
      log.warn("获取定时任务[{}]异常:{}",triggerName,e.getMessage());
      throw new ApplicationException( e );
    }
   
    if( target == null )
      throw new ApplicationException( "找不到相关定时任务["+triggerName+"]" );
     
    description = target.getDescription();
    boolean enabled = false;
   
    try {
      TriggerState state = scheduler.getTriggerState( target.getKey() );
     
      if( target instanceof CronTrigger){
        cronExpression = ((CronTrigger)target).getCronExpression();
      }
     
      if( TriggerState.PAUSED.equals(state) ){
        scheduler.resumeTrigger( target.getKey() );//启动定时器
        enabled = true;
      }else if( TriggerState.NORMAL.equals(state) ){
        scheduler.pauseTrigger(target.getKey());//暂停定时器
      }
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
   
    if( jobInterval == null ){
      jobInterval = new JobInterval();
      jobInterval.setCronExpression(cronExpression);
      jobInterval.setTriggerName(triggerName);
      jobInterval.setDescription(description);
    }

    jobInterval.setEnabled( enabled );
   
    jobIntervalManager.save(jobInterval);
  }
View Full Code Here

TOP

Related Classes of com.google.code.lightssh.project.scheduler.entity.JobInterval

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.