Updated Observation code to use the updates offered by the Micrometer snapshot

This commit is contained in:
Glenn Renfro
2022-08-30 14:28:54 -04:00
parent e4581420b0
commit 3609e53751
13 changed files with 84 additions and 90 deletions

View File

@@ -16,12 +16,11 @@
package org.springframework.cloud.task.batch.listener;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.batch.item.Chunk;
import org.springframework.cloud.task.batch.listener.support.BatchJobHeaders;
import org.springframework.cloud.task.batch.listener.support.MessagePublisher;
import org.springframework.cloud.task.batch.listener.support.TaskEventProperties;
@@ -33,7 +32,7 @@ import org.springframework.util.Assert;
* channel.
*
* Each method provides an informational message.
* {@link ItemWriteListener#onWriteError(Exception, List)} provides a message as well as
* {@link ItemWriteListener#onWriteError(Exception, Chunk)} provides a message as well as
* the exception's message via the {@link BatchJobHeaders#BATCH_EXCEPTION} message header.
*
* @author Glenn Renfro
@@ -64,13 +63,13 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
}
@Override
public void beforeWrite(List items) {
public void beforeWrite(Chunk items) {
this.messagePublisher.publish(this.properties.getItemWriteEventBindingName(),
items.size() + " items to be written.");
}
@Override
public void afterWrite(List items) {
public void afterWrite(Chunk items) {
if (logger.isDebugEnabled()) {
logger.debug("Executing afterWrite: " + items);
}
@@ -79,7 +78,7 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
}
@Override
public void onWriteError(Exception exception, List items) {
public void onWriteError(Exception exception, Chunk items) {
if (logger.isDebugEnabled()) {
logger.debug("Executing onWriteError: " + exception.getMessage(), exception);
}

View File

@@ -33,6 +33,7 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.scope.context.StepContext;
import org.springframework.batch.item.Chunk;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -285,12 +286,12 @@ public class EventListenerTests {
return new JobExecution(jobInstance, 1L, new JobParameters());
}
private List<String> getSampleList() {
private Chunk<String> getSampleList() {
List<String> testList = new ArrayList<>(3);
testList.add("Hello");
testList.add("World");
testList.add("foo");
return testList;
return new Chunk<String>(testList);
}
private ChunkContext getChunkContext() {