Skip to content

Commit 9fbd3da

Browse files
committed
Polish 117b7d5
* Update year in license headers * Add/Amend Javadocs * Update assertion message to be consistent between the writer and its builder
1 parent 117b7d5 commit 9fbd3da

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,22 +25,42 @@
2525

2626
/**
2727
* An {@link ItemStreamWriter} decorator with a synchronized
28-
* {@link SynchronizedItemStreamWriter#write write()} method
28+
* {@link SynchronizedItemStreamWriter#write write()} method.
29+
*
30+
* This decorator is useful when using a non thread-safe item writer
31+
* in a multi-threaded step. Typical delegate examples are the
32+
* {@link org.springframework.batch.item.json.JsonFileItemWriter JsonFileItemWriter}
33+
* and {@link org.springframework.batch.item.xml.StaxEventItemWriter StaxEventItemWriter}.
34+
*
35+
* <p>
36+
* <strong>It should be noted that synchronizing writes might introduce
37+
* some performance degradation, so this decorator should be used
38+
* wisely and only when necessary. For example, using a
39+
* {@link org.springframework.batch.item.file.FlatFileItemWriter FlatFileItemWriter} in
40+
* a multi-threaded step does NOT require synchronizing writes, so using
41+
* this decorator in such use case might be counter-productive.</strong>
42+
* </p>
2943
*
3044
* @author Dimitrios Liapis
45+
* @author Mahmoud Ben Hassine
3146
*
3247
* @param <T> type of object being written
3348
*/
3449
public class SynchronizedItemStreamWriter<T> implements ItemStreamWriter<T>, InitializingBean {
3550

3651
private ItemStreamWriter<T> delegate;
3752

53+
/**
54+
* Set the delegate {@link ItemStreamWriter}.
55+
*
56+
* @param delegate the delegate to set
57+
*/
3858
public void setDelegate(ItemStreamWriter<T> delegate) {
3959
this.delegate = delegate;
4060
}
4161

4262
/**
43-
* This delegates to the write method of the <code>delegate</code>
63+
* This method delegates to the {@code write} method of the {@code delegate}.
4464
*/
4565
@Override
4666
public synchronized void write(List<? extends T> items) throws Exception {

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamWriterBuilder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,19 +23,31 @@
2323
* Creates a fully qualified {@link SynchronizedItemStreamWriter}.
2424
*
2525
* @author Dimitrios Liapis
26+
* @author Mahmoud Ben Hassine
2627
*/
2728
public class SynchronizedItemStreamWriterBuilder<T> {
2829

2930
private ItemStreamWriter<T> delegate;
3031

32+
/**
33+
* Set the delegate {@link ItemStreamWriter}.
34+
*
35+
* @param delegate the delegate to set
36+
* @return this instance for method chaining
37+
*/
3138
public SynchronizedItemStreamWriterBuilder<T> delegate(ItemStreamWriter<T> delegate) {
3239
this.delegate = delegate;
3340

3441
return this;
3542
}
3643

44+
/**
45+
* Returns a fully constructed {@link SynchronizedItemStreamWriter}.
46+
*
47+
* @return a new {@link SynchronizedItemStreamWriter}
48+
*/
3749
public SynchronizedItemStreamWriter<T> build() {
38-
Assert.notNull(this.delegate, "A delegate is required");
50+
Assert.notNull(this.delegate, "A delegate item writer is required");
3951

4052
SynchronizedItemStreamWriter<T> writer = new SynchronizedItemStreamWriter<>();
4153
writer.setDelegate(this.delegate);

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamWriterBuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ protected SynchronizedItemStreamWriter<Object> createNewSynchronizedItemStreamWr
3737
@Test
3838
public void testBuilderDelegateIsNotNull() {
3939
expectedException.expect(IllegalArgumentException.class);
40-
expectedException.expectMessage("A delegate is required");
40+
expectedException.expectMessage("A delegate item writer is required");
4141
new SynchronizedItemStreamWriterBuilder<>().build();
4242
}
4343
}

0 commit comments

Comments
 (0)