1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.federatedcompute;
18 
19 import android.annotation.NonNull;
20 import android.os.Bundle;
21 
22 import java.io.Closeable;
23 
24 /**
25  * Iterator interface that client apps implement to return training examples. When FederatedCompute
26  * runs a computation, it will call into this interface to fetech training examples to feed to the
27  * computation.
28  *
29  * @hide
30  */
31 public interface ExampleStoreIterator extends Closeable {
32     /** Called when FederatedCompute needs another example. */
next(@onNull IteratorCallback callback)33     void next(@NonNull IteratorCallback callback);
34     /** Called by FederatedCompute when it is done using this iterator instance. */
35     @Override
close()36     void close();
37     /** The client app must implement this callback return training examples. */
38     public interface IteratorCallback {
39         /**
40          * Called when the result for {@link ExampleStoreIterator#next} is available, or when the
41          * end of the collection has been reached.
42          */
onIteratorNextSuccess(Bundle result)43         boolean onIteratorNextSuccess(Bundle result);
44         /** Called when an error occurred and the result cannot be returned. */
onIteratorNextFailure(int errorCode)45         void onIteratorNextFailure(int errorCode);
46     }
47 }
48