OPEN - issue BATCH-398: That old stateful / stateless thing again....
http://jira.springframework.org/browse/BATCH-398 Fix delegate job (duplicate job regsitry).
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.repository;
|
||||
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
|
||||
/**
|
||||
* Strategy for creating a single job.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface JobFactory {
|
||||
|
||||
Job createJob();
|
||||
|
||||
String getJobName();
|
||||
|
||||
}
|
||||
@@ -29,18 +29,18 @@ public interface JobRegistry extends JobLocator {
|
||||
/**
|
||||
* Registers a {@link Job} at runtime.
|
||||
*
|
||||
* @param jobConfiguration the {@link Job} to be registered
|
||||
* @param job the {@link Job} to be registered
|
||||
*
|
||||
* @throws DuplicateJobException if a configuration with the
|
||||
* same name has already been registered.
|
||||
*/
|
||||
void register(Job jobConfiguration) throws DuplicateJobException;
|
||||
void register(Job job) throws DuplicateJobException;
|
||||
|
||||
/**
|
||||
* Unregisters a previously registered {@link Job}. If it was
|
||||
* not previously registered there is no error.
|
||||
*
|
||||
* @param jobConfiguration the {@link Job} to unregister.
|
||||
* @param job the {@link Job} to unregister.
|
||||
*/
|
||||
void unregister(Job jobConfiguration);
|
||||
void unregister(Job job);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.batch.core.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
|
||||
/**
|
||||
* A listable extension of {@link JobRegistry}.
|
||||
*
|
||||
@@ -28,11 +26,10 @@ import org.springframework.batch.core.domain.Job;
|
||||
public interface ListableJobRegistry extends JobRegistry {
|
||||
|
||||
/**
|
||||
* Provides the currently registered configurations. The return value is
|
||||
* Provides the currently registered job names. The return value is
|
||||
* unmodifiable and disconnected from the underlying registry storage.
|
||||
*
|
||||
* @return a collection of {@link Job} instances. Empty if none
|
||||
* are registered.
|
||||
* @return a collection of String. Empty if none are registered.
|
||||
*/
|
||||
Collection getJobConfigurations();
|
||||
Collection getJobNames();
|
||||
}
|
||||
|
||||
@@ -88,9 +88,9 @@ public class MapJobRegistry implements ListableJobRegistry {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.container.common.configuration.ListableJobConfigurationRegistry#getJobConfigurations()
|
||||
*/
|
||||
public Collection getJobConfigurations() {
|
||||
public Collection getJobNames() {
|
||||
synchronized (map) {
|
||||
return Collections.unmodifiableCollection(new HashSet(map.values()));
|
||||
return Collections.unmodifiableCollection(new HashSet(map.keySet()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class JobRegistryBeanPostProcessorTests extends TestCase {
|
||||
"test-context.xml", getClass());
|
||||
MapJobRegistry registry = (MapJobRegistry) context
|
||||
.getBean("registry");
|
||||
Collection configurations = registry.getJobConfigurations();
|
||||
Collection configurations = registry.getJobNames();
|
||||
// System.err.println(configurations);
|
||||
String[] names = context.getBeanNamesForType(JobSupport.class);
|
||||
int count = names.length;
|
||||
|
||||
@@ -81,16 +81,16 @@ public class MapJobRegistryTests extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.configuration.MapJobRegistry#getJobConfigurations()}.
|
||||
* Test method for {@link org.springframework.batch.execution.configuration.MapJobRegistry#getJobNames()}.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testGetJobConfigurations() throws Exception {
|
||||
Job configuration = new JobSupport("foo");
|
||||
registry.register(configuration);
|
||||
registry.register(new JobSupport("bar"));
|
||||
Collection configurations = registry.getJobConfigurations();
|
||||
Collection configurations = registry.getJobNames();
|
||||
assertEquals(2, configurations.size());
|
||||
assertTrue(configurations.contains(configuration));
|
||||
assertTrue(configurations.contains(configuration.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,7 @@
|
||||
integrated into a batch job.
|
||||
</description>
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.execution.configuration.JobRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry"
|
||||
ref="jobConfigurationRegistry" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<bean id="delegateJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="itemReader">
|
||||
|
||||
@@ -36,12 +36,17 @@ public class DefaultJobLoader implements JobLoader,
|
||||
|
||||
public Map getConfigurations() {
|
||||
Map result = new HashMap(configurations);
|
||||
for (Iterator iterator = registry.getJobConfigurations().iterator(); iterator
|
||||
for (Iterator iterator = registry.getJobNames().iterator(); iterator
|
||||
.hasNext();) {
|
||||
Job configuration = (Job) iterator.next();
|
||||
String name = configuration.getName();
|
||||
if (!configurations.containsKey(name)) {
|
||||
result.put(name, "<unknown path>: " + configuration);
|
||||
try {
|
||||
Job configuration = (Job) registry.getJob((String) iterator.next());
|
||||
String name = configuration.getName();
|
||||
if (!configurations.containsKey(name)) {
|
||||
result.put(name, "<unknown path>: " + configuration);
|
||||
}
|
||||
}
|
||||
catch (NoSuchJobException e) {
|
||||
throw new IllegalStateException("Registry could not locate its own job (NoSuchJobException).");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.core.repository.JobRegistry;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -23,11 +24,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
*
|
||||
*/
|
||||
public class TaskExecutorLauncher {
|
||||
|
||||
private JobRegistry registry;
|
||||
|
||||
private void register(String[] paths) {
|
||||
// registry.register(jobConfiguration)
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// Paths to individual job configurations. Each one must include the
|
||||
// step scope and the jobConfigurationRegistryBeanPostProcessor.
|
||||
// Paths to individual job configurations.
|
||||
final String[] paths = new String[] { "jobs/adhocLoopJob.xml",
|
||||
"jobs/footballJob.xml" };
|
||||
|
||||
@@ -39,6 +45,8 @@ public class TaskExecutorLauncher {
|
||||
// included in the paths above.
|
||||
final ApplicationContext parent = new ClassPathXmlApplicationContext(
|
||||
"adhoc-job-launcher-context.xml");
|
||||
// parent.getAutowireCapableBeanFactory().autowireBeanProperties(
|
||||
// this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
Reference in New Issue
Block a user