DynamicGroupsJob.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.maxkey.jobs;
  17. import java.io.Serializable;
  18. import org.maxkey.persistence.service.GroupsService;
  19. import org.quartz.Job;
  20. import org.quartz.JobExecutionContext;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. public class DynamicGroupsJob extends AbstractScheduleJob implements Job , Serializable {
  24. /**
  25. *
  26. */
  27. private static final long serialVersionUID = 8831626240807856084L;
  28. final static Logger _logger = LoggerFactory.getLogger(DynamicGroupsJob.class);
  29. private static GroupsService groupsService = null;
  30. @Override
  31. public void execute(JobExecutionContext context){
  32. if(jobStatus == JOBSTATUS.RUNNING) {return;}
  33. init(context);
  34. _logger.debug("DynamicGroups Job running ... " );
  35. jobStatus = JOBSTATUS.RUNNING;
  36. try {
  37. if(groupsService != null) {
  38. groupsService.refreshAllDynamicGroups();
  39. Thread.sleep(10 * 1000);//10 minutes
  40. }
  41. _logger.debug("DynamicGroups Job finished " );
  42. jobStatus = JOBSTATUS.FINISHED;
  43. }catch(Exception e) {
  44. jobStatus = JOBSTATUS.ERROR;
  45. _logger.error("Exception " ,e);
  46. }
  47. }
  48. @Override
  49. void init(JobExecutionContext context){
  50. if(groupsService == null) {
  51. groupsService =
  52. (GroupsService) context.getMergedJobDataMap().get("service");
  53. }
  54. }
  55. }