final JobRegistryBackgroundJobRunner launcher = new JobRegistryBackgroundJobRunner(args[0]); errors.clear(); launcher.register(paths); launcher.destroy(); return; JobRegistryBackgroundJobRunner.class.wait(); launcher.destroy();
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); jobLoader.load(factory); } } }
/** * Test method for * {@link org.springframework.batch.core.launch.support.JobRegistryBackgroundJobRunner#main(java.lang.String[])}. */ @Test public void testMain() throws Exception { JobRegistryBackgroundJobRunner.main( ClassUtils.addResourcePathToPackagePath(getClass(), "test-environment-with-registry.xml"), ClassUtils .addResourcePathToPackagePath(getClass(), "job.xml")); assertEquals(0, JobRegistryBackgroundJobRunner.getErrors().size()); }
@Before public void setUp() throws Exception { JobRegistryBackgroundJobRunner.getErrors().clear(); System.setProperty(JobRegistryBackgroundJobRunner.EMBEDDED, ""); }
@Override public void run() { try { JobRegistryBackgroundJobRunner.main("adhoc-job-launcher-context.xml", "jobs/adhocLoopJob.xml"); } catch (Exception e) { logger.error(e); errors.add(e); } } });
@AfterClass public static void cleanUp() { JobRegistryBackgroundJobRunner.stop(); }
private static boolean isConnected() throws Exception { boolean connected = false; if (!JobRegistryBackgroundJobRunner.getErrors().isEmpty()) { throw JobRegistryBackgroundJobRunner.getErrors().get(0); } if (launcher == null) { MBeanServerConnectionFactoryBean connectionFactory = new MBeanServerConnectionFactoryBean(); try { launcher = (JobOperator) getMBean(connectionFactory, "spring:service=batch,bean=jobOperator", JobOperator.class); loader = (JobLoader) getMBean(connectionFactory, "spring:service=batch,bean=jobLoader", JobLoader.class); } catch (MBeanServerNotFoundException e) { return false; } } try { launcher.getJobNames(); connected = loader.getConfigurations().size() > 0; logger.info("Configurations loaded: " + loader.getConfigurations()); } catch (InvalidInvocationException e) { // ignore } return connected; }
final JobRegistryBackgroundJobRunner launcher = new JobRegistryBackgroundJobRunner(args[0]); errors.clear(); launcher.register(paths); launcher.destroy(); return; JobRegistryBackgroundJobRunner.class.wait(); launcher.destroy();
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); jobLoader.load(factory); } } }
@Test public void testMainWithAutoRegister() throws Exception { JobRegistryBackgroundJobRunner.main( ClassUtils.addResourcePathToPackagePath(getClass(), "test-environment-with-registry-and-auto-register.xml"), ClassUtils .addResourcePathToPackagePath(getClass(), "job.xml")); assertEquals(0, JobRegistryBackgroundJobRunner.getErrors().size()); }
final JobRegistryBackgroundJobRunner launcher = new JobRegistryBackgroundJobRunner(args[0]); errors.clear(); launcher.register(paths); launcher.destroy(); return; JobRegistryBackgroundJobRunner.class.wait(); launcher.destroy();
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); jobLoader.load(factory); } } }
@Test public void testMainWithJobLoader() throws Exception { JobRegistryBackgroundJobRunner.main( ClassUtils.addResourcePathToPackagePath(getClass(), "test-environment-with-loader.xml"), ClassUtils .addResourcePathToPackagePath(getClass(), "job.xml")); assertEquals(0, JobRegistryBackgroundJobRunner.getErrors().size()); }
final JobRegistryBackgroundJobRunner launcher = new JobRegistryBackgroundJobRunner(args[0]); errors.clear(); launcher.register(paths); launcher.destroy(); return; JobRegistryBackgroundJobRunner.class.wait(); launcher.destroy();
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); jobLoader.load(factory); } } }
final JobRegistryBackgroundJobRunner launcher = new JobRegistryBackgroundJobRunner(args[0]); errors.clear(); launcher.register(paths); launcher.destroy(); return; JobRegistryBackgroundJobRunner.class.wait(); launcher.destroy();
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); ClassPathXmlApplicationContextFactory factory = new ClassPathXmlApplicationContextFactory(); factory.setApplicationContext(parentContext); factory.setResource(path); jobLoader.load(factory); } } }