001/*-
002 * #%L
003 * HAPI FHIR JPA Server - Batch2 Task Processor
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.batch2.api;
021
022import ca.uhn.fhir.batch2.model.WorkChunkData;
023import ca.uhn.fhir.model.api.IModelJson;
024
025public interface IJobDataSink<OT extends IModelJson> {
026
027        /**
028         * Step workers may call this 0..* times in order to provide output work chunks that
029         * will be passed to subsequent steps. Multiple invocations will result in multiple
030         * discrete chunks of work, each of which will be processed separately (and potentially
031         * in parallel) by the next step in the job definition.
032         * <p>
033         * This method may not be called by the final step worker and will result in an
034         * error.
035         * </p>
036         *
037         * @param theData The data to pass to the next step worker
038         */
039        default void accept(OT theData) {
040                accept(new WorkChunkData<>(theData));
041        }
042
043        /**
044         * Step workers may call this 0..* times in order to provide output work chunks that
045         * will be passed to subsequent steps. Multiple invocations will result in multiple
046         * discrete chunks of work, each of which will be processed separately (and potentially
047         * in parallel) by the next step in the job definition.
048         * <p>
049         * This method is not currently any different to calling {@link #accept(IModelJson)} other than
050         * the fact that it adds a wrapper object, but additional fields may be added to the
051         * wrapper in the future.
052         * </p>
053         * <p>
054         * This method may not be called by the final step worker and will result in an
055         * error.
056         * </p>
057         *
058         * @param theData The data to pass to the next step worker
059         */
060        void accept(WorkChunkData<OT> theData);
061
062        /**
063         * Step workers may invoke this method to indicate that an error occurred during
064         * processing but that it was successfully recovered, or it does not need to be
065         * recovered, or at least that it does not mean that processing should stop.
066         *
067         * @param theMessage An error message. This will be logged, and in the future it may be stored
068         */
069        void recoveredError(String theMessage);
070
071        /**
072         * Step workers may invoke this method to indicate that a warning message processor
073         *
074         * @param theWarningProcessor The processor for the warning.
075         */
076        void setWarningProcessor(IWarningProcessor theWarningProcessor);
077}