Dust off JMX demo

This commit is contained in:
dsyer
2008-07-05 07:32:44 +00:00
parent 086fded0cf
commit 3d78c0bcb5
20 changed files with 120 additions and 84 deletions

View File

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

View File

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

View File

@@ -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();
}
}