Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a WorkerImpl subclass to validate the jobType #29

Merged
merged 1 commit into from
Feb 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions src/main/java/net/greghaines/jesque/worker/WorkerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,7 @@ public Map<String,Class<?>> getJobTypes()

public void addJobType(final String jobName, final Class<?> jobType)
{
if (jobName == null)
{
throw new IllegalArgumentException("jobName must not be null");
}
if (jobType == null)
{
throw new IllegalArgumentException("jobType must not be null");
}
if (!(Runnable.class.isAssignableFrom(jobType)) && !(Callable.class.isAssignableFrom(jobType)))
{
throw new IllegalArgumentException("jobType must implement either Runnable or Callable: " + jobType);
}
checkJobType(jobName, jobType);
this.jobTypes.put(jobName, jobType);
}

Expand Down Expand Up @@ -800,22 +789,38 @@ protected void checkJobTypes(final Map<String,? extends Class<?>> jobTypes)
}
for (final Entry<String,? extends Class<?>> entry : jobTypes.entrySet())
{
if (entry.getKey() == null)
{
throw new IllegalArgumentException("jobType's keys must not be null: " + jobTypes);
}
final Class<?> jobType = entry.getValue();
if (jobType == null)
try
{
throw new IllegalArgumentException("jobType's values must not be null: " + jobTypes);
checkJobType( entry.getKey(), entry.getValue() );
}
if (!(Runnable.class.isAssignableFrom(jobType)) && !(Callable.class.isAssignableFrom(jobType)))
catch(IllegalArgumentException iae)
{
throw new IllegalArgumentException("jobType's values must implement either Runnable or Callable: " + jobTypes);
throw new IllegalArgumentException("jobTypes contained invalid value", iae);
}
}
}

/**
* determine if a job name and job type is valid
* @param jobName the name of the job
* @param jobType the class of the job
*/
protected void checkJobType(final String jobName, final Class<?> jobType)
{
if (jobName == null)
{
throw new IllegalArgumentException("jobName must not be null");
}
if (jobType == null)
{
throw new IllegalArgumentException("jobType must not be null");
}
if (!(Runnable.class.isAssignableFrom(jobType)) && !(Callable.class.isAssignableFrom(jobType)))
{
throw new IllegalArgumentException("jobType must implement either Runnable or Callable: " + jobType);
}
}

@Override
public String toString()
{
Expand Down