Skip to content

Commit

Permalink
Add interface for delegation to Iterator, Iterable, simple item
Browse files Browse the repository at this point in the history
Signed-off-by: Taeik Lim <[email protected]>
  • Loading branch information
acktsap committed Jan 31, 2024
1 parent dfdb746 commit 87a9b7d
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.lang.NonNull;
import reactor.core.publisher.Flux;

/**
* A delegate for {@link ItemStreamReader} which uses {@link Flux<T>}.
*
* @since 1.1.0
*/
public interface ItemStreamFluxReaderDelegate<T> {

/**
* A delegate method for {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onOpenRead(@NonNull ExecutionContext executionContext) {
}

/**
* Read items by reactor flux. Invoked in {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
* @return a flux to read item
*/
@NonNull
Flux<? extends T> readFlux(@NonNull ExecutionContext executionContext);

/**
* A delegate method for {@link ItemStreamReader#update(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onUpdateRead(@NonNull ExecutionContext executionContext) {
}

/**
* A delegate method for {@link ItemStreamReader#close()}.
*/
default void onCloseRead() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.ItemStreamWriter;

/**
* A simple adapter for stream reader, processor, writer. It can represent
* {@link ItemStreamReader}, {@link ItemProcessor}, {@link ItemStreamWriter} in a single class.
*
* @since 1.1.0
*/
public interface ItemStreamFluxReaderProcessorWriter<I, O>
extends ItemStreamFluxReaderDelegate<I>, ItemProcessorDelegate<I, O>, ItemStreamWriterDelegate<O> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.lang.NonNull;

/**
* A delegate for {@link ItemStreamReader} which uses {@link Iterable<T>}.
*
* @since 1.1.0
*/
public interface ItemStreamIterableReaderDelegate<T> {

/**
* A delegate method for {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onOpenRead(@NonNull ExecutionContext executionContext) {
}

/**
* Read items by {@link Iterable<T>}. Invoked in {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
* @return an iterable to read item
*/
@NonNull
Iterable<? extends T> readIterable(@NonNull ExecutionContext executionContext);

/**
* A delegate method for {@link ItemStreamReader#update(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onUpdateRead(@NonNull ExecutionContext executionContext) {
}

/**
* A delegate method for {@link ItemStreamReader#close()}.
*/
default void onCloseRead() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.ItemStreamWriter;

/**
* A simple adapter for stream reader, processor, writer. It can represent
* {@link ItemStreamReader}, {@link ItemProcessor}, {@link ItemStreamWriter} in a single class.
*
* @since 1.1.0
*/
public interface ItemStreamIterableReaderProcessorWriter<I, O>
extends ItemStreamIterableReaderDelegate<I>, ItemProcessorDelegate<I, O>, ItemStreamWriterDelegate<O> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.lang.NonNull;

import java.util.Iterator;

/**
* A delegate for {@link ItemStreamReader} which uses {@link Iterator<T>}.
*
* @since 1.1.0
*/
public interface ItemStreamIteratorReaderDelegate<T> {

/**
* A delegate method for {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onOpenRead(@NonNull ExecutionContext executionContext) {
}

/**
* Read items by {@link Iterator<T>}. Invoked in {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
* @return an iterator to read item
*/
@NonNull
Iterator<? extends T> readIterator(@NonNull ExecutionContext executionContext);

/**
* A delegate method for {@link ItemStreamReader#update(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onUpdateRead(@NonNull ExecutionContext executionContext) {
}

/**
* A delegate method for {@link ItemStreamReader#close()}.
*/
default void onCloseRead() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.ItemStreamWriter;

/**
* A simple adapter for stream reader, processor, writer. It can represent
* {@link ItemStreamReader}, {@link ItemProcessor}, {@link ItemStreamWriter} in a single class.
*
* @since 1.1.0
*/
public interface ItemStreamIteratorReaderProcessorWriter<I, O>
extends ItemStreamIteratorReaderDelegate<I>, ItemProcessorDelegate<I, O>, ItemStreamWriterDelegate<O> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.springframework.batch.item.ItemStreamWriter;

/**
* A simple adaptor for stream reader, processor, writer. It can represent
* A simple adapter for stream reader, processor, writer. It can represent
* {@link ItemStreamReader}, {@link ItemProcessor}, {@link ItemStreamWriter} in a single class.
*
* @since 0.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Spring Batch Plus
*
* Copyright 2022-present NAVER Corp.
*
* 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 com.navercorp.spring.batch.plus.item.adapter;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

/**
* A simple delegate for {@link ItemStreamReader}.
*
* @since 1.1.0
*/
public interface ItemStreamSimpleReaderDelegate<T> {

/**
* A delegate method for {@link ItemStreamReader#open(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onOpenRead(@NonNull ExecutionContext executionContext) {
}

/**
* Read each item. Invoked in {@link ItemStreamReader#open(ExecutionContext)}.
*
* @return an item to read. null if it's end of data.
* Return contract is same as {@link org.springframework.batch.item.ItemReader<T>}
*/
@Nullable
T read();

/**
* A delegate method for {@link ItemStreamReader#update(ExecutionContext)}.
*
* @param executionContext an execution context
*/
default void onUpdateRead(@NonNull ExecutionContext executionContext) {
}

/**
* A delegate method for {@link ItemStreamReader#close()}.
*/
default void onCloseRead() {
}
}
Loading

0 comments on commit 87a9b7d

Please sign in to comment.