DynamicGroupsJob.java 2.2 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
18 19
package org.maxkey.jobs;

M
MaxKey 已提交
20
import java.io.Serializable;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
21 22 23 24 25 26
import org.maxkey.persistence.service.GroupsService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

M
MaxKey 已提交
27 28 29 30 31 32
public class DynamicGroupsJob  implements Job , Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 8831626240807856084L;

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    final static Logger _logger = LoggerFactory.getLogger(DynamicGroupsJob.class);
    
    private static  GroupsService groupsService = null;
    
    public static class JOBSTATUS{
        public static int STOP = 0;
        public static int RUNNING = 1;
        public static int FINISHED = 2;
    }
    
    private static int jobStatus = JOBSTATUS.STOP;

    @Override
    public void execute(JobExecutionContext context){
        if(jobStatus == JOBSTATUS.RUNNING) {
            _logger.info("DynamicGroupsJob is in running . " );
            return;
        }
        
        _logger.debug("DynamicGroupsJob is running ... " );
        jobStatus = JOBSTATUS.RUNNING;
        try {
            if(groupsService == null) {
M
MaxKey 已提交
56 57 58
                groupsService = 
                		(GroupsService) context.getMergedJobDataMap().get("service");
            }else {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
59

M
MaxKey 已提交
60
            	groupsService.refreshAllDynamicGroups();
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
61
            
M
MaxKey 已提交
62 63
            	Thread.sleep(10 *1000);
            }
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
64 65 66 67 68 69 70 71
            _logger.debug("DynamicGroupsJob is success  " );
        }catch(Exception e) {
            _logger.error("Exception " ,e);
            jobStatus = JOBSTATUS.STOP;
        }
        jobStatus = JOBSTATUS.FINISHED;
        _logger.debug("DynamicGroupsJob is finished . " );
    }
M
MaxKey 已提交
72

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
73 74

}