Skip to content

Commit

Permalink
Merge pull request #1206 from bcode2/refactor_branch_2.5
Browse files Browse the repository at this point in the history
Refactor branch 2.5, clean code
  • Loading branch information
jhouserizer authored Oct 25, 2024
2 parents 8e0e0c0 + bf8636a commit f317075
Show file tree
Hide file tree
Showing 45 changed files with 260 additions and 507 deletions.
8 changes: 4 additions & 4 deletions quartz/src/main/java/org/quartz/DateBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public enum IntervalUnit { MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH,

public static final int DECEMBER = 12;

public static final long MILLISECONDS_IN_MINUTE = 60l * 1000l;
public static final long MILLISECONDS_IN_MINUTE = 60L * 1000L;

public static final long MILLISECONDS_IN_HOUR = 60l * 60l * 1000l;
public static final long MILLISECONDS_IN_HOUR = 60L * 60L * 1000L;

public static final long SECONDS_IN_MOST_DAYS = 24l * 60l * 60L;
public static final long SECONDS_IN_MOST_DAYS = 24L * 60L * 60L;

public static final long MILLISECONDS_IN_DAY = SECONDS_IN_MOST_DAYS * 1000l;
public static final long MILLISECONDS_IN_DAY = SECONDS_IN_MOST_DAYS * 1000L;

private int month;
private int day;
Expand Down
40 changes: 14 additions & 26 deletions quartz/src/main/java/org/quartz/core/QuartzScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,12 @@ public void startDelayed(final int seconds) throws SchedulerException
"The Scheduler cannot be restarted after shutdown() has been called.");
}

Thread t = new Thread(new Runnable() {
public void run() {
try { Thread.sleep(seconds * 1000L); }
catch(InterruptedException ignore) {}
try { start(); }
catch(SchedulerException se) {
getLog().error("Unable to start scheduler after startup delay.", se);
}
Thread t = new Thread(() -> {
try { Thread.sleep(seconds * 1000L); }
catch(InterruptedException ignore) {}
try { start(); }
catch(SchedulerException se) {
getLog().error("Unable to start scheduler after startup delay.", se);
}
});
t.start();
Expand Down Expand Up @@ -1851,10 +1849,9 @@ public boolean notifyTriggerListenersFired(JobExecutionContext jec)
vetoedExecution = true;
}
} catch (Exception e) {
SchedulerException se = new SchedulerException(
throw new SchedulerException(
"TriggerListener '" + tl.getName()
+ "' threw exception: " + e.getMessage(), e);
throw se;
}
}

Expand All @@ -1874,10 +1871,9 @@ public void notifyTriggerListenersMisfired(Trigger trigger)
continue;
tl.triggerMisfired(trigger);
} catch (Exception e) {
SchedulerException se = new SchedulerException(
throw new SchedulerException(
"TriggerListener '" + tl.getName()
+ "' threw exception: " + e.getMessage(), e);
throw se;
}
}
}
Expand All @@ -1894,10 +1890,9 @@ public void notifyTriggerListenersComplete(JobExecutionContext jec,
continue;
tl.triggerComplete(jec.getTrigger(), jec, instCode);
} catch (Exception e) {
SchedulerException se = new SchedulerException(
throw new SchedulerException(
"TriggerListener '" + tl.getName()
+ "' threw exception: " + e.getMessage(), e);
throw se;
}
}
}
Expand All @@ -1914,10 +1909,9 @@ public void notifyJobListenersToBeExecuted(JobExecutionContext jec)
continue;
jl.jobToBeExecuted(jec);
} catch (Exception e) {
SchedulerException se = new SchedulerException(
throw new SchedulerException(
"JobListener '" + jl.getName() + "' threw exception: "
+ e.getMessage(), e);
throw se;
}
}
}
Expand All @@ -1934,10 +1928,9 @@ public void notifyJobListenersWasVetoed(JobExecutionContext jec)
continue;
jl.jobExecutionVetoed(jec);
} catch (Exception e) {
SchedulerException se = new SchedulerException(
throw new SchedulerException(
"JobListener '" + jl.getName() + "' threw exception: "
+ e.getMessage(), e);
throw se;
}
}
}
Expand All @@ -1954,10 +1947,9 @@ public void notifyJobListenersWasExecuted(JobExecutionContext jec,
continue;
jl.jobWasExecuted(jec, je);
} catch (Exception e) {
SchedulerException se = new SchedulerException(
throw new SchedulerException(
"JobListener '" + jl.getName() + "' threw exception: "
+ e.getMessage(), e);
throw se;
}
}
}
Expand Down Expand Up @@ -2340,17 +2332,13 @@ public boolean interrupt(String fireInstanceId) throws UnableToInterruptJobExcep
}

private void shutdownPlugins() {
java.util.Iterator<SchedulerPlugin> itr = resources.getSchedulerPlugins().iterator();
while (itr.hasNext()) {
SchedulerPlugin plugin = itr.next();
for (SchedulerPlugin plugin : resources.getSchedulerPlugins()) {
plugin.shutdown();
}
}

private void startPlugins() {
java.util.Iterator<SchedulerPlugin> itr = resources.getSchedulerPlugins().iterator();
while (itr.hasNext()) {
SchedulerPlugin plugin = itr.next();
for (SchedulerPlugin plugin : resources.getSchedulerPlugins()) {
plugin.start();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ public void setSampledStatisticsEnabled(boolean enabled) {
this.sampledStatistics.shutdown();
this.sampledStatistics = NULL_SAMPLED_STATISTICS;
}
sendNotification(SAMPLED_STATISTICS_ENABLED, Boolean.valueOf(enabled));
sendNotification(SAMPLED_STATISTICS_ENABLED, enabled);
}
}

Expand All @@ -1000,12 +1000,9 @@ public long getJobsScheduledMostRecentSample() {

public Map<String, Long> getPerformanceMetrics() {
Map<String, Long> result = new HashMap<>();
result.put("JobsCompleted", Long
.valueOf(getJobsCompletedMostRecentSample()));
result.put("JobsExecuted", Long
.valueOf(getJobsExecutedMostRecentSample()));
result.put("JobsScheduled", Long
.valueOf(getJobsScheduledMostRecentSample()));
result.put("JobsCompleted", getJobsCompletedMostRecentSample());
result.put("JobsExecuted", getJobsExecutedMostRecentSample());
result.put("JobsScheduled", getJobsScheduledMostRecentSample());
return result;
}
}
21 changes: 8 additions & 13 deletions quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static javax.management.openmbean.SimpleType.STRING;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

import javax.management.openmbean.CompositeData;
Expand All @@ -18,17 +17,17 @@
import org.quartz.JobDataMap;

public class JobDataMapSupport {
private static final String typeName = "JobDataMap";
private static final String TYPE_NAME = "JobDataMap";
private static final String[] keyValue = new String[] { "key", "value" };
private static final OpenType[] openTypes = new OpenType[] { STRING, STRING };
private static final CompositeType rowType;
public static final TabularType TABULAR_TYPE;

static {
try {
rowType = new CompositeType(typeName, typeName, keyValue, keyValue,
rowType = new CompositeType(TYPE_NAME, TYPE_NAME, keyValue, keyValue,
openTypes);
TABULAR_TYPE = new TabularType(typeName, typeName, rowType,
TABULAR_TYPE = new TabularType(TYPE_NAME, TYPE_NAME, rowType,
new String[] { "key" });
} catch (OpenDataException e) {
throw new RuntimeException(e);
Expand All @@ -51,12 +50,10 @@ public static JobDataMap newJobDataMap(TabularData tabularData) {
public static JobDataMap newJobDataMap(Map<String, Object> map) {
JobDataMap jobDataMap = new JobDataMap();

if(map != null) {
for (String key : map.keySet()) {
jobDataMap.put(key, map.get(key));
}
if (map != null) {
jobDataMap.putAll(map);
}

return jobDataMap;
}

Expand All @@ -79,10 +76,8 @@ public static CompositeData toCompositeData(String key, String value) {
public static TabularData toTabularData(JobDataMap jobDataMap) {
TabularData tData = new TabularDataSupport(TABULAR_TYPE);
ArrayList<CompositeData> list = new ArrayList<>();
Iterator<String> iter = jobDataMap.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
list.add(toCompositeData(key, String.valueOf(jobDataMap.get(key))));
for (Map.Entry<String, Object> entry : jobDataMap.entrySet()) {
list.add(toCompositeData(entry.getKey(), String.valueOf(entry.getValue())));
}
tData.putAll(list.toArray(new CompositeData[list.size()]));
return tData;
Expand Down
4 changes: 1 addition & 3 deletions quartz/src/main/java/org/quartz/core/jmx/TriggerSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ public static List<CompositeData> toCompositeList(List<? extends Trigger> trigge
List<CompositeData> result = new ArrayList<>();
for(Trigger trigger : triggers) {
CompositeData cData = TriggerSupport.toCompositeData(trigger);
if(cData != null) {
result.add(cData);
}
result.add(cData);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public void contextInitialized(ServletContextEvent sce) {
if(shutdownPref == null)
shutdownPref = servletContext.getInitParameter("shutdown-on-unload");
if (shutdownPref != null) {
performShutdown = Boolean.valueOf(shutdownPref);
performShutdown = Boolean.parseBoolean(shutdownPref);
}
String shutdownWaitPref = servletContext.getInitParameter("quartz:wait-on-shutdown");
if (shutdownWaitPref != null) {
waitOnShutdown = Boolean.valueOf(shutdownWaitPref);
waitOnShutdown = Boolean.parseBoolean(shutdownWaitPref);
}

factory = getSchedulerFactory(configFile);
Expand Down Expand Up @@ -191,7 +191,7 @@ public void contextInitialized(ServletContextEvent sce) {
* the scheduler will be started. This is to maintain backwards
* compatability.
*/
if (startOnLoad == null || (Boolean.valueOf(startOnLoad))) {
if (startOnLoad == null || (Boolean.parseBoolean(startOnLoad))) {
if(startDelay <= 0) {
// Start now
scheduler.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ public void init(ServletConfig cfg) throws jakarta.servlet.ServletException {
String shutdownPref = cfg.getInitParameter("shutdown-on-unload");

if (shutdownPref != null) {
performShutdown = Boolean.valueOf(shutdownPref);
performShutdown = Boolean.parseBoolean(shutdownPref);
}
String shutdownWaitPref = cfg.getInitParameter("wait-on-shutdown");
if (shutdownPref != null) {
waitOnShutdown = Boolean.valueOf(shutdownWaitPref);
waitOnShutdown = Boolean.parseBoolean(shutdownWaitPref);
}

factory = getSchedulerFactory(configFile);
Expand Down Expand Up @@ -204,7 +204,7 @@ public void init(ServletConfig cfg) throws jakarta.servlet.ServletException {
* the scheduler will be started. This is to maintain backwards
* compatability.
*/
if (startOnLoad == null || (Boolean.valueOf(startOnLoad))) {
if (startOnLoad == null || (Boolean.parseBoolean(startOnLoad))) {
if(startDelay <= 0) {
// Start now
scheduler.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.quartz.impl;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

Expand Down
3 changes: 1 addition & 2 deletions quartz/src/main/java/org/quartz/impl/JobDetailImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,12 @@ public Object clone() {
}

public JobBuilder getJobBuilder() {
JobBuilder b = JobBuilder.newJob()
return JobBuilder.newJob()
.ofType(getJobClass())
.requestRecovery(requestsRecovery())
.storeDurably(isDurable())
.usingJobData(getJobDataMap())
.withDescription(getDescription())
.withIdentity(getKey());
return b;
}
}
2 changes: 1 addition & 1 deletion quartz/src/main/java/org/quartz/impl/QuartzServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void serve(SchedulerFactory schedFact, boolean console)
sched.start();

try {
Thread.sleep(3000l);
Thread.sleep(3000L);
} catch (Exception ignore) {
}

Expand Down
6 changes: 2 additions & 4 deletions quartz/src/main/java/org/quartz/impl/RemoteScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ protected RemotableQuartzScheduler getRemoteScheduler()
rsched = (RemotableQuartzScheduler) registry.lookup(schedId);

} catch (Exception e) {
SchedulerException initException = new SchedulerException(
throw new SchedulerException(
"Could not get handle to remote scheduler: "
+ e.getMessage(), e);
throw initException;
}

return rsched;
Expand All @@ -127,8 +126,7 @@ protected RemotableQuartzScheduler getRemoteScheduler()
protected SchedulerException invalidateHandleCreateException(String msg,
Exception cause) {
rsched = null;
SchedulerException ex = new SchedulerException(msg, cause);
return ex;
return new SchedulerException(msg, cause);
}

/**
Expand Down
13 changes: 6 additions & 7 deletions quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,7 @@ else if(tpInited)

protected Scheduler instantiate(QuartzSchedulerResources rsrcs, QuartzScheduler qs) {

Scheduler scheduler = new StdScheduler(qs);
return scheduler;
return new StdScheduler(qs);
}


Expand Down Expand Up @@ -1477,15 +1476,15 @@ private void setBeanProps(Object obj, Properties props)
refName = name;

if (params[0].equals(int.class)) {
setMeth.invoke(obj, new Object[]{Integer.valueOf(refProps.getIntProperty(refName))});
setMeth.invoke(obj, new Object[]{refProps.getIntProperty(refName)});
} else if (params[0].equals(long.class)) {
setMeth.invoke(obj, new Object[]{Long.valueOf(refProps.getLongProperty(refName))});
setMeth.invoke(obj, new Object[]{refProps.getLongProperty(refName)});
} else if (params[0].equals(float.class)) {
setMeth.invoke(obj, new Object[]{Float.valueOf(refProps.getFloatProperty(refName))});
setMeth.invoke(obj, new Object[]{refProps.getFloatProperty(refName)});
} else if (params[0].equals(double.class)) {
setMeth.invoke(obj, new Object[]{Double.valueOf(refProps.getDoubleProperty(refName))});
setMeth.invoke(obj, new Object[]{refProps.getDoubleProperty(refName)});
} else if (params[0].equals(boolean.class)) {
setMeth.invoke(obj, new Object[]{Boolean.valueOf(refProps.getBooleanProperty(refName))});
setMeth.invoke(obj, new Object[]{refProps.getBooleanProperty(refName)});
} else if (params[0].equals(String.class)) {
setMeth.invoke(obj, new Object[]{refProps.getStringProperty(refName)});
} else {
Expand Down
13 changes: 3 additions & 10 deletions quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.TimeZone;

import org.quartz.Calendar;
Expand All @@ -41,7 +40,7 @@
public class AnnualCalendar extends BaseCalendar implements Calendar,
Serializable {

static final long serialVersionUID = 7346867105876610961L;
private static final long serialVersionUID = 7346867105876610961L;

private ArrayList<java.util.Calendar> excludeDays = new ArrayList<>();

Expand Down Expand Up @@ -104,10 +103,7 @@ public boolean isDayExcluded(java.util.Calendar day) {
dataSorted = true;
}

Iterator<java.util.Calendar> iter = excludeDays.iterator();
while (iter.hasNext()) {
java.util.Calendar cl = (java.util.Calendar) iter.next();

for (java.util.Calendar cl : excludeDays) {
// remember, the list is sorted
if (dmonth < cl.get(java.util.Calendar.MONTH)) {
return false;
Expand Down Expand Up @@ -190,10 +186,7 @@ private void removeExcludedDay(java.util.Calendar day, boolean isChecked) {

// Since there is no guarantee that the given day is in the arraylist with the exact same year
// search for the object based on month and day of month in the list and remove it
Iterator<java.util.Calendar> iter = excludeDays.iterator();
while (iter.hasNext()) {
java.util.Calendar cl = (java.util.Calendar) iter.next();

for (java.util.Calendar cl : excludeDays) {
if (dmonth != cl.get(java.util.Calendar.MONTH)) {
continue;
}
Expand Down
Loading

0 comments on commit f317075

Please sign in to comment.