Dust off JMX demo
This commit is contained in:
@@ -29,7 +29,7 @@ import org.springframework.jmx.export.notification.NotificationPublisherAware;
|
||||
* JMX notification broadcaster
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.1
|
||||
* @since 1.0
|
||||
*/
|
||||
public class JobExecutionNotificationPublisher implements ApplicationListener, NotificationPublisherAware {
|
||||
|
||||
|
||||
@@ -17,16 +17,18 @@
|
||||
package org.springframework.batch.sample.advice;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
|
||||
/**
|
||||
* Wraps calls for 'Processing' methods which output a single Object to write
|
||||
* the string representation of the object to the log.
|
||||
* Wraps calls for methods taking {@link StepExecution} as an argument and
|
||||
* publishes notifications in the form of {@link ApplicationEvent}.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class MethodExecutionApplicationEventAdvice implements ApplicationEventPublisherAware {
|
||||
public class StepExecutionApplicationEventAdvice implements ApplicationEventPublisherAware {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@@ -38,21 +40,21 @@ public class MethodExecutionApplicationEventAdvice implements ApplicationEventPu
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
public void before(JoinPoint jp) {
|
||||
String msg = "Before: "+jp.toShortString();
|
||||
public void before(JoinPoint jp, StepExecution stepExecution) {
|
||||
String msg = "Before: " + jp.toShortString() + " with: " + stepExecution;
|
||||
publish(jp.getTarget(), msg);
|
||||
}
|
||||
|
||||
public void after(JoinPoint jp) {
|
||||
String msg = "After: "+jp.toShortString();
|
||||
public void after(JoinPoint jp, StepExecution stepExecution) {
|
||||
String msg = "After: " + jp.toShortString() + " with: " + stepExecution;
|
||||
publish(jp.getTarget(), msg);
|
||||
}
|
||||
|
||||
public void onError(JoinPoint jp, Throwable t) {
|
||||
String msg = "Error in: "+jp.toShortString()+"("+t.getClass()+":"+t.getMessage()+")";
|
||||
public void onError(JoinPoint jp, StepExecution stepExecution, Throwable t) {
|
||||
String msg = "Error in: " + jp.toShortString() + " with: " + stepExecution + " (" + t.getClass() + ":" + t.getMessage() + ")";
|
||||
publish(jp.getTarget(), msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Publish a {@link RepeatOperationsApplicationEvent} with the given
|
||||
* parameters.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
@@ -52,9 +53,10 @@ public class InfiniteLoopTasklet extends StepExecutionListenerSupport implements
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Job interrupted.");
|
||||
}
|
||||
count++;
|
||||
stepExecution.setItemCount(++count);
|
||||
logger.info("Executing infinite loop, at count="+count);
|
||||
}
|
||||
stepExecution.setStatus(BatchStatus.STOPPING);
|
||||
return ExitStatus.FAILED;
|
||||
}
|
||||
|
||||
@@ -64,5 +66,15 @@ public class InfiniteLoopTasklet extends StepExecutionListenerSupport implements
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.stepExecution = stepExecution;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.listener.StepExecutionListenerSupport#afterStep(org.springframework.batch.core.StepExecution)
|
||||
*/
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
if (stepExecution.isTerminateOnly()) {
|
||||
stepExecution.setStatus(BatchStatus.STOPPED);
|
||||
}
|
||||
return stepExecution.getExitStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
<import resource="simple-job-launcher-context.xml" />
|
||||
|
||||
<!-- For Java 1.4 we need to ceate teh mbean server explicitly -->
|
||||
<!-- For Java 1.4 we need to ceate the mbean server explicitly -->
|
||||
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
|
||||
<property name="locateExistingServerIfPossible" value="true" />
|
||||
</bean>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Placeholders batch.*
|
||||
# for HSQLDB:
|
||||
batch.jdbc.driver=org.hsqldb.jdbcDriver
|
||||
batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true
|
||||
# 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.url=jdbc:hsqldb:hsql://localhost:9005/samples
|
||||
batch.jdbc.user=sa
|
||||
batch.jdbc.password=
|
||||
batch.schema=
|
||||
|
||||
@@ -21,29 +21,18 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="logAdvice"
|
||||
class="org.springframework.batch.sample.advice.MethodExecutionLogAdvice" />
|
||||
|
||||
<bean id="eventAdvice"
|
||||
class="org.springframework.batch.sample.advice.MethodExecutionApplicationEventAdvice" />
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect ref="logAdvice">
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.sample..InfiniteLoopTasklet+.execute(..))"
|
||||
method="doBasicLogging" />
|
||||
</aop:aspect>
|
||||
<aop:aspect ref="eventAdvice">
|
||||
<aop:before
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
method="before" />
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
method="after" />
|
||||
<aop:after-throwing throwing="t"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
method="onError" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect ref="eventAdvice">
|
||||
<aop:before
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="before" />
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="after" />
|
||||
<aop:after-throwing throwing="t"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="onError" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -119,18 +119,18 @@
|
||||
</aop:aspect>
|
||||
<aop:aspect ref="eventAdvice">
|
||||
<aop:before
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="before" />
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="after" />
|
||||
<aop:after-throwing throwing="t"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
|
||||
method="onError" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="footbalProperties"
|
||||
<bean id="footballProperties"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="properties">
|
||||
<value>
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<!-- This input source is injected into the test case to verify the output - not used by the job at all -->
|
||||
<bean id="testItemReader"
|
||||
class="org.springframework.batch.item.file.MultiResourceItemReader">
|
||||
<property name="resources"
|
||||
value="classpath:data/multiResourceJob/input/file-*.txt" />
|
||||
<property name="delegate" ref="flatFileItemReader" />
|
||||
</bean>
|
||||
|
||||
<bean id="testItemReader"
|
||||
class="org.springframework.batch.item.file.MultiResourceItemReader">
|
||||
<property name="resources"
|
||||
value="classpath:data/multiResourceJob/input/file-*.txt" />
|
||||
<property name="delegate" ref="flatFileItemReader" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileItemReader" parent="testItemReader"
|
||||
autowire-candidate="false" />
|
||||
|
||||
|
||||
@@ -71,19 +71,6 @@
|
||||
|
||||
<bean id="logAdvice" class="org.springframework.batch.sample.advice.ProcessorLogAdvice" />
|
||||
|
||||
<bean id="eventAdvice" class="org.springframework.batch.sample.advice.MethodExecutionApplicationEventAdvice" />
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect ref="logAdvice">
|
||||
<aop:after pointcut="execution( * org.springframework.batch.sample..InfiniteLoopTasklet+.execute(..))"
|
||||
method="doBasicLogging" />
|
||||
</aop:aspect>
|
||||
<aop:aspect ref="eventAdvice">
|
||||
<aop:before pointcut="execution( * org.springframework.batch..Step+.execute(..))" method="before" />
|
||||
<aop:after pointcut="execution( * org.springframework.batch..Step+.execute(..))" method="after" />
|
||||
<aop:after-throwing throwing="t" pointcut="execution( * org.springframework.batch..Step+.execute(..))"
|
||||
method="onError" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
<bean id="eventAdvice" class="org.springframework.batch.sample.advice.StepExecutionApplicationEventAdvice" />
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user