From 5545925e178cefaf7e36f621bbad95fdb1947d18 Mon Sep 17 00:00:00 2001 From: dsyer Date: Sun, 10 Oct 2010 16:06:20 +0000 Subject: [PATCH] BATCH-1636: add Ordered interface --- .../support/AutomaticJobRegistrar.java | 18 +++++++++++++++++- .../support/AutomaticJobRegistrarTests.java | 11 +++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java index 5937af919..2d5d7c7db 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java @@ -30,6 +30,7 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.Lifecycle; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.core.Ordered; import org.springframework.util.Assert; /** @@ -44,7 +45,7 @@ import org.springframework.util.Assert; * * @since 2.1 */ -public class AutomaticJobRegistrar implements Lifecycle, ApplicationListener, ApplicationContextAware, InitializingBean { +public class AutomaticJobRegistrar implements Ordered, Lifecycle, ApplicationListener, ApplicationContextAware, InitializingBean { private Collection applicationContextFactories = new ArrayList(); @@ -55,6 +56,8 @@ public class AutomaticJobRegistrar implements Lifecycle, ApplicationListener, Ap private volatile boolean running = false; private Object lifecycleMonitor = new Object(); + + private int order = Ordered.LOWEST_PRECEDENCE; /** * The enclosing application context, which can be used to check if @@ -89,6 +92,19 @@ public class AutomaticJobRegistrar implements Lifecycle, ApplicationListener, Ap this.jobLoader = jobLoader; } + public int getOrder() { + return order; + } + + /** + * The order to start up and shutdown. + * @param order the order (default {@link Ordered#LOWEST_PRECEDENCE}). + * @see Ordered + */ + public void setOrder(int order) { + this.order = order; + } + /** * @throws Exception */ diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java index 26fbd9a38..a957dfba2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrarTests.java @@ -17,6 +17,7 @@ import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.Ordered; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -39,6 +40,16 @@ public class AutomaticJobRegistrarTests { registrar.setJobLoader(jobLoader); } + @Test + public void testOrderedImplemented() throws Exception { + + assertTrue(registrar instanceof Ordered); + assertEquals(Ordered.LOWEST_PRECEDENCE, registrar.getOrder()); + registrar.setOrder(1); + assertEquals(1, registrar.getOrder()); + + } + @Test public void testLocateJob() throws Exception {