svn commit: r1818473 - in /ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job: GenericServiceJob.java JobManager.java JobPoller.java PersistedServiceJob.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1818473 - in /ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job: GenericServiceJob.java JobManager.java JobPoller.java PersistedServiceJob.java

mbrohl
Author: mbrohl
Date: Sun Dec 17 11:12:00 2017
New Revision: 1818473

URL: http://svn.apache.org/viewvc?rev=1818473&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.service.job.
(OFBIZ-9954)

Thanks Dennis Balkir for reporting and providing the patches.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/GenericServiceJob.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobManager.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobPoller.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/GenericServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/GenericServiceJob.java?rev=1818473&r1=1818472&r2=1818473&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/GenericServiceJob.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/GenericServiceJob.java Sun Dec 17 11:12:00 2017
@@ -93,7 +93,9 @@ public class GenericServiceJob extends A
      * Method is called prior to running the service.
      */
     protected void init() throws InvalidJobException {
-        if (Debug.verboseOn()) Debug.logVerbose("Async-Service initializing.", module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Async-Service initializing.", module);
+        }
     }
 
     /**
@@ -104,7 +106,9 @@ public class GenericServiceJob extends A
             throw new InvalidJobException("Illegal state change");
         }
         currentState = State.FINISHED;
-        if (Debug.verboseOn()) Debug.logVerbose("Async-Service finished.", module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Async-Service finished.", module);
+        }
     }
 
     /**

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobManager.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobManager.java?rev=1818473&r1=1818472&r2=1818473&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobManager.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobManager.java Sun Dec 17 11:12:00 2017
@@ -129,7 +129,7 @@ public final class JobManager {
 
     /**
      * Get a List of each threads current state.
-     *
+     *
      * @return List containing a Map of each thread's state.
      */
     public Map<String, Object> getPoolState() {
@@ -138,7 +138,7 @@ public final class JobManager {
 
     /**
      * Return true if the jobManager can run job.
-     *
+     *
      * @return boolean.
      */
     public boolean isAvailable() {
@@ -311,7 +311,9 @@ public final class JobManager {
             Timestamp now = UtilDateTime.nowTimestamp();
             for (GenericValue job : crashed) {
                 try {
-                    if (Debug.infoOn()) Debug.logInfo("Scheduling Job : " + job, module);
+                    if (Debug.infoOn()) {
+                        Debug.logInfo("Scheduling Job : " + job, module);
+                    }
                     String pJobId = job.getString("parentJobId");
                     if (pJobId == null) {
                         pJobId = job.getString("jobId");
@@ -336,11 +338,13 @@ public final class JobManager {
                     Debug.logWarning(e, module);
                 }
             }
-            if (Debug.infoOn())
+            if (Debug.infoOn()) {
                 Debug.logInfo("-- " + rescheduled + " jobs re-scheduled", module);
+            }
         } else {
-            if (Debug.infoOn())
+            if (Debug.infoOn()) {
                 Debug.logInfo("No crashed jobs to re-schedule", module);
+            }
         }
         crashedJobsReloaded = true;
     }
@@ -358,7 +362,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param serviceName
      *            The name of the service to invoke
      *@param context
@@ -378,7 +382,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param serviceName
      *            The name of the service to invoke
      *@param context
@@ -400,7 +404,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param serviceName
      *            The name of the service to invoke
      *@param context
@@ -420,7 +424,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param poolName
      *            The name of the pool to run the service from
      *@param serviceName
@@ -445,7 +449,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param poolName
      *            The name of the pool to run the service from
      *@param serviceName
@@ -461,7 +465,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param jobName
      *            The name of the job
      *@param poolName
@@ -501,7 +505,7 @@ public final class JobManager {
 
     /**
      * Schedule a job to start at a specific time with specific recurrence info
-     *
+     *
      * @param jobName
      *            The name of the job
      *@param poolName

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobPoller.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobPoller.java?rev=1818473&r1=1818472&r2=1818473&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobPoller.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/JobPoller.java Sun Dec 17 11:12:00 2017
@@ -49,7 +49,7 @@ public final class JobPoller implements
 
     public static final String module = JobPoller.class.getName();
     private static final AtomicInteger created = new AtomicInteger();
-    private static final ConcurrentHashMap<String, JobManager> jobManagers = new ConcurrentHashMap<String, JobManager>();
+    private static final ConcurrentHashMap<String, JobManager> jobManagers = new ConcurrentHashMap<>();
     private static final ThreadPoolExecutor executor = createThreadPoolExecutor();
     private static final JobPoller instance = new JobPoller();
 
@@ -84,7 +84,7 @@ public final class JobPoller implements
 
     /**
      * Register a {@link JobManager} with the job poller.
-     *
+     *
      * @param jm The <code>JobManager</code> to register.
      * @throws IllegalArgumentException if <code>jm</code> is null
      */
@@ -112,7 +112,7 @@ public final class JobPoller implements
      * Returns a <code>Map</code> containing <code>JobPoller</code> statistics.
      */
     public Map<String, Object> getPoolState() {
-        Map<String, Object> poolState = new HashMap<String, Object>();
+        Map<String, Object> poolState = new HashMap<>();
         poolState.put("keepAliveTimeInSeconds", executor.getKeepAliveTime(TimeUnit.SECONDS));
         poolState.put("numberOfCoreInvokerThreads", executor.getCorePoolSize());
         poolState.put("currentNumberOfInvokerThreads", executor.getPoolSize());
@@ -121,11 +121,11 @@ public final class JobPoller implements
         poolState.put("greatestNumberOfInvokerThreads", executor.getLargestPoolSize());
         poolState.put("numberOfCompletedTasks", executor.getCompletedTaskCount());
         BlockingQueue<Runnable> queue = executor.getQueue();
-        List<Map<String, Object>> taskList = new ArrayList<Map<String, Object>>();
+        List<Map<String, Object>> taskList = new ArrayList<>();
         Map<String, Object> taskInfo = null;
         for (Runnable task : queue) {
             Job job = (Job) task;
-            taskInfo = new HashMap<String, Object>();
+            taskInfo = new HashMap<>();
             taskInfo.put("id", job.getJobId());
             taskInfo.put("name", job.getJobName());
             String serviceName = "";
@@ -218,17 +218,19 @@ public final class JobPoller implements
                     if (remainingCapacity > 0) {
                         // Build "list of lists"
                         Collection<JobManager> jmCollection = jobManagers.values();
-                        List<Iterator<Job>> pollResults = new ArrayList<Iterator<Job>>();
+                        List<Iterator<Job>> pollResults = new ArrayList<>();
                         for (JobManager jm : jmCollection) {
                             if (!jm.isAvailable()) {
-                                if (Debug.infoOn()) Debug.logInfo("The job manager is locked.", module);
+                                if (Debug.infoOn()) {
+                                    Debug.logInfo("The job manager is locked.", module);
+                                }
                                 continue;
                             }
                             jm.reloadCrashedJobs();
                             pollResults.add(jm.poll(remainingCapacity).iterator());
                         }
                         // Create queue candidate list from "list of lists"
-                        List<Job> queueCandidates = new ArrayList<Job>();
+                        List<Job> queueCandidates = new ArrayList<>();
                         boolean addingJobs = true;
                         while (addingJobs) {
                             addingJobs = false;

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java?rev=1818473&r1=1818472&r2=1818473&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java Sun Dec 17 11:12:00 2017
@@ -183,11 +183,15 @@ public class PersistedServiceJob extends
         } catch (GenericEntityException e) {
             throw new InvalidJobException(e);
         }
-        if (Debug.infoOn()) Debug.logInfo("Job  [" + getJobName() + "] Id ["  + getJobId() + "] -- Next runtime: " + new Date(nextRecurrence), module);
+        if (Debug.infoOn()) {
+            Debug.logInfo("Job  [" + getJobName() + "] Id ["  + getJobId() + "] -- Next runtime: " + new Date(nextRecurrence), module);
+        }
     }
 
     private void createRecurrence(long next, boolean isRetryOnFailure) throws GenericEntityException {
-        if (Debug.verboseOn()) Debug.logVerbose("Next runtime returned: " + next, module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Next runtime returned: " + next, module);
+        }
         if (next > startTime) {
             String pJobId = jobValue.getString("parentJobId");
             if (pJobId == null) {
@@ -208,7 +212,9 @@ public class PersistedServiceJob extends
             }
             nextRecurrence = next;
             delegator.createSetNextSeqId(newJob);
-            if (Debug.verboseOn()) Debug.logVerbose("Created next job entry: " + newJob, module);
+            if (Debug.verboseOn()) {
+                Debug.logVerbose("Created next job entry: " + newJob, module);
+            }
         }
     }