You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2021/10/01 10:14:52 UTC

[syncope] branch 2_1_X updated: [SYNCOPE-1644] Fixing job reporting

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new e59b456  [SYNCOPE-1644] Fixing job reporting
e59b456 is described below

commit e59b4567e90cadc93852349aff29352a3046de13
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Fri Oct 1 12:14:29 2021 +0200

    [SYNCOPE-1644] Fixing job reporting
---
 .../java/job/SyncopeSpringBeanJobFactory.java            | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SyncopeSpringBeanJobFactory.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SyncopeSpringBeanJobFactory.java
index c690f39..6565f27 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SyncopeSpringBeanJobFactory.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/SyncopeSpringBeanJobFactory.java
@@ -21,11 +21,17 @@ package org.apache.syncope.core.provisioning.java.job;
 import java.util.Optional;
 import org.apache.syncope.core.provisioning.api.job.JobManager;
 import org.apache.syncope.core.provisioning.java.job.report.ReportJob;
+import org.apache.syncope.core.spring.ApplicationContextProvider;
 import org.quartz.spi.TriggerFiredBundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 import org.springframework.scheduling.quartz.SpringBeanJobFactory;
 
 public class SyncopeSpringBeanJobFactory extends SpringBeanJobFactory {
 
+    private static final Logger LOG = LoggerFactory.getLogger(SyncopeSpringBeanJobFactory.class);
+
     @Override
     protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
         Object job = super.createJobInstance(bundle);
@@ -40,6 +46,16 @@ public class SyncopeSpringBeanJobFactory extends SpringBeanJobFactory {
             }
         }
 
+        DefaultListableBeanFactory factory = ApplicationContextProvider.getBeanFactory();
+        try {
+            if (factory.containsSingleton(bundle.getJobDetail().getKey().getName())) {
+                factory.destroySingleton(bundle.getJobDetail().getKey().getName());
+            }
+            factory.registerSingleton(bundle.getJobDetail().getKey().getName(), job);
+        } catch (Exception e) {
+            LOG.error("While attempting to replace job instance as singleton Spring bean", e);
+        }
+
         return job;
     }
 }