BATCH-1636: add Ordered interface

This commit is contained in:
dsyer
2010-10-10 16:06:20 +00:00
parent abd66edb30
commit 5545925e17
2 changed files with 28 additions and 1 deletions

View File

@@ -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<ApplicationContextFactory> applicationContextFactories = new ArrayList<ApplicationContextFactory>();
@@ -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
*/

View File

@@ -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 {