Permalink
Browse files

adding the code together.

  • Loading branch information...
1 parent b4a14d0 commit 46ae58e17c9f6f988734c6c0a0c108b34c95da81 @joshlong committed Apr 11, 2012
View
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>batchadmindemo</artifactId>
+ <description>A sample web application (WAR project) for Spring Batch Admin console.</description>
+ <parent>
+ <artifactId>spring-batch-admin-parent</artifactId>
+ <groupId>org.springframework.batch</groupId>
+ <version>1.0.0.M1</version>
+ <relativePath>../spring-batch-admin-parent</relativePath>
+ </parent>
+ <packaging>war</packaging>
+ <name>Web Sample</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.freemarker</groupId>
+ <artifactId>freemarker</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.webflow</groupId>
+ <artifactId>spring-js</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-taglibs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-infrastructure</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-admin-manager</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-admin-resources</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <configuration>
+ <contextPath>/contributor</contextPath>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>spring-milestones</id>
+ <name>Spring Maven Milestone Repository</name>
+ <url>http://s3.amazonaws.com/maven.springframework.org/milestone</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+</project>
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2009-2010 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.admin.sample;
+
+import org.springframework.batch.item.ItemReader;
+
+/**
+ * {@link ItemReader} with hard-coded input data.
+ */
+public class ExampleItemReader implements ItemReader<String> {
+
+ private static final int MAX_OUTER = 0;
+
+ private String[] input = { "Hello", "world!", "Wow", "that's", "cool!" };
+
+ private int index = 0;
+
+ private int outer = 0;
+
+ /**
+ * Reads next record from input
+ */
+ public synchronized String read() throws Exception {
+ if (index >= input.length) {
+ outer++;
+ if (outer > MAX_OUTER) {
+ return null;
+ } else {
+ index = 0;
+ }
+ }
+ return input[index++];
+ }
+
+}
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2009-2010 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.admin.sample;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.batch.item.ItemWriter;
+
+/**
+ * Dummy {@link ItemWriter} which only logs data it receives.
+ */
+public class ExampleItemWriter implements ItemWriter<Object> {
+
+ private static final Log log = LogFactory.getLog(ExampleItemWriter.class);
+ private boolean fail = false;
+
+ public void setFail(boolean fail) {
+ this.fail = fail;
+ }
+
+ /**
+ * @see ItemWriter#write(Object)
+ */
+ public void write(List<? extends Object> data) throws Exception {
+ log.info(data);
+ if (fail ) {
+ throw new RuntimeException("Planned failure");
+ }
+ }
+
+}
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2009-2010 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.admin.sample;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.batch.core.JobParameter;
+import org.springframework.batch.core.JobParameters;
+import org.springframework.batch.core.JobParametersIncrementer;
+
+public class TrivialJobParametersIncrementer implements
+ JobParametersIncrementer {
+
+ public JobParameters getNext(JobParameters parameters) {
+ Map<String, JobParameter> map = new HashMap<String, JobParameter>(
+ parameters.getParameters());
+ map.put("run.count", new JobParameter(parameters
+ .getLong("run.count", -1)+1));
+ return new JobParameters(map);
+ }
+
+}
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
+ http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
+
+ <job id="job1" parent="simpleJob" xmlns="http://www.springframework.org/schema/batch" incrementer="incrementer">
+ <step id="j1.s1" parent="step1" />
+ </job>
+
+ <job id="job2" parent="simpleJob" xmlns="http://www.springframework.org/schema/batch">
+ <step id="j2.s1" parent="step1:master" />
+ </job>
+
+ <job id="infinite" parent="simpleJob" xmlns="http://www.springframework.org/schema/batch" incrementer="incrementer">
+ <!-- To allow this job to be stopped we need it to actually execute the step multiple times -->
+ <step id="infinite.s1" parent="step1.allow.start" next="infinite.s1"/>
+ </job>
+
+ <bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
+ <property name="jobRepository" ref="jobRepository" />
+ <property name="restartable" value="true" />
+ </bean>
+
+ <bean id="simpleStep"
+ class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"
+ abstract="true">
+ <property name="transactionManager" ref="transactionManager" />
+ <property name="jobRepository" ref="jobRepository" />
+ <property name="startLimit" value="100" />
+ <property name="commitInterval" value="1" />
+ </bean>
+
+ <bean id="incrementer" class="org.springframework.batch.admin.sample.TrivialJobParametersIncrementer"/>
+
+ <bean name="step1:master" class="org.springframework.batch.core.partition.support.PartitionStep">
+ <property name="partitionHandler">
+ <bean class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler">
+ <property name="step" ref="remoteStep1" />
+ <property name="gridSize" value="${batch.grid.size}" />
+ <property name="taskExecutor" ref="taskExecutor" />
+ </bean>
+ </property>
+ <property name="stepExecutionSplitter">
+ <bean class="org.springframework.batch.core.partition.support.SimpleStepExecutionSplitter">
+ <constructor-arg ref="jobRepository" />
+ <constructor-arg ref="step1" />
+ </bean>
+ </property>
+ <property name="jobRepository" ref="jobRepository" />
+ </bean>
+
+ <bean id="taskExecutor" parent="throttledTaskExecutor">
+ <property name="throttleLimit" value="100"/>
+ </bean>
+
+ <bean id="step1" parent="simpleStep">
+ <property name="itemReader" ref="itemReader" />
+ <property name="itemWriter" ref="itemWriter" />
+ </bean>
+
+ <bean id="step1.allow.start" parent="step1">
+ <property name="allowStartIfComplete" value="true"/>
+ </bean>
+
+ <bean id="itemWriter" class="org.springframework.batch.admin.sample.ExampleItemWriter" p:fail="#{jobParameters['fail']}" scope="step" />
+
+ <bean id="itemReader" class="org.springframework.batch.admin.sample.ExampleItemReader" scope="step" />
+
+ <bean id="remoteStep1" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
+ <property name="serviceInterface" value="org.springframework.batch.core.Step" />
+ <property name="serviceUrl" value="${batch.remote.base.url}/steps/step1" />
+ </bean>
+
+</beans>
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+ <import resource="../batch/module-context.xml"/>
+
+ <bean parent="placeholderProperties"/>
+
+ <bean name="/steps/step1" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
+ <property name="serviceInterface" value="org.springframework.batch.core.Step" />
+ <property name="service" ref="step1" />
+ </bean>
+
+</beans>
@@ -0,0 +1,18 @@
+# Placeholders batch.*
+# for HSQLDB:
+batch.jdbc.driver=org.hsqldb.jdbcDriver
+batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true
+# use this one for a separate server process so you can inspect the results
+# (or add it to system properties with -D to override at run time).
+# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
+batch.jdbc.user=sa
+batch.jdbc.password=
+batch.jdbc.testWhileIdle=false
+batch.jdbc.validationQuery=
+batch.schema.script=classpath:/org/springframework/batch/core/schema-hsqldb.sql
+batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql
+batch.business.schema.script=classpath:/business-schema-hsqldb.sql
+batch.data.source.init=true
+batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer
+batch.grid.size=2
+batch.remote.base.url=http://localhost:8080/batchadmindemo/batch
@@ -0,0 +1,14 @@
+log4j.rootCategory=INFO, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
+
+log4j.category.com.springsource.batch=DEBUG
+log4j.category.org.springframework.batch=DEBUG
+log4j.category.org.springframework.jdbc=DEBUG
+log4j.category.org.springframework.transaction=INFO
+
+log4j.category.org.hibernate.SQL=DEBUG
+# for debugging datasource initialization
+#log4j.category.test.jdbc=DEBUG
Oops, something went wrong.

0 comments on commit 46ae58e

Please sign in to comment.