2323 * Entry point for the Mindee **V2** API features.
2424 */
2525public class MindeeClient {
26+ private static final System .Logger logger = System .getLogger (MindeeClient .class .getName ());
27+
2628 private final MindeeApiV2 mindeeApi ;
2729
2830 /** Uses an API key read from the environment variables. */
@@ -50,6 +52,7 @@ public JobResponse enqueue(
5052 LocalInputSource inputSource ,
5153 BaseProductParameters params
5254 ) throws IOException {
55+ logger .log (System .Logger .Level .INFO , "Enqueuing: local source" );
5356 return mindeeApi .reqPostEnqueue (inputSource , params );
5457 }
5558
@@ -63,6 +66,7 @@ public JobResponse enqueue(
6366 URLInputSource inputSource ,
6467 BaseProductParameters params
6568 ) throws IOException {
69+ logger .log (System .Logger .Level .INFO , "Enqueuing: URL source" );
6670 inputSource .validateSecure ();
6771 return mindeeApi .reqPostEnqueue (inputSource , params );
6872 }
@@ -72,6 +76,7 @@ public JobResponse enqueue(
7276 * Can be used for polling.
7377 */
7478 public JobResponse getJob (String jobId ) {
79+ logger .log (System .Logger .Level .INFO , "Getting job ID: {0}" , jobId );
7580 if (jobId == null || jobId .trim ().isEmpty ()) {
7681 throw new IllegalArgumentException ("jobId must not be null or blank." );
7782 }
@@ -86,6 +91,7 @@ public <TResponse extends CommonResponse> TResponse getResult(
8691 Class <TResponse > responseClass ,
8792 String inferenceId
8893 ) {
94+ logger .log (System .Logger .Level .INFO , "Getting result with ID: {0}" , inferenceId );
8995 if (inferenceId == null || inferenceId .trim ().isEmpty ()) {
9096 throw new IllegalArgumentException ("inferenceId must not be null or blank." );
9197 }
@@ -100,6 +106,7 @@ public <TResponse extends CommonResponse> TResponse getResultFromUrl(
100106 Class <TResponse > responseClass ,
101107 String inferenceUrl
102108 ) {
109+ logger .log (System .Logger .Level .INFO , "Getting result at: {0}" , inferenceUrl );
103110 if (inferenceUrl == null || inferenceUrl .trim ().isEmpty ()) {
104111 throw new IllegalArgumentException ("inferenceUrl must not be null or blank." );
105112 }
@@ -147,7 +154,13 @@ public <TResponse extends CommonResponse> TResponse enqueueAndGetResult(
147154 PollingOptions pollingOptions
148155 ) throws IOException , InterruptedException {
149156 JobResponse job = enqueue (inputSource , params );
150- return pollAndFetch (responseClass , job , pollingOptions );
157+ logger
158+ .log (
159+ System .Logger .Level .INFO ,
160+ "Successfully enqueued document with job ID {0}" ,
161+ job .getJob ().getId ()
162+ );
163+ return pollForResult (responseClass , job , pollingOptions );
151164 }
152165
153166 /**
@@ -192,7 +205,13 @@ public <TResponse extends CommonResponse> TResponse enqueueAndGetResult(
192205 ) throws IOException , InterruptedException {
193206 inputSource .validateSecure ();
194207 JobResponse job = enqueue (inputSource , params );
195- return pollAndFetch (responseClass , job , pollingOptions );
208+ logger
209+ .log (
210+ System .Logger .Level .INFO ,
211+ "Successfully enqueued document with job ID {0}" ,
212+ job .getJob ().getId ()
213+ );
214+ return pollForResult (responseClass , job , pollingOptions );
196215 }
197216
198217 /**
@@ -251,11 +270,17 @@ public SearchResponse searchModels(String modelName, String modelType) {
251270 * @return an instance of {@link ExtractionResponse}.
252271 * @throws InterruptedException Throws if interrupted.
253272 */
254- private <TResponse extends CommonResponse > TResponse pollAndFetch (
273+ private <TResponse extends CommonResponse > TResponse pollForResult (
255274 Class <TResponse > responseClass ,
256275 JobResponse initialJob ,
257276 PollingOptions pollingOptions
258277 ) throws InterruptedException {
278+ logger
279+ .log (
280+ System .Logger .Level .DEBUG ,
281+ "Waiting {0} seconds before attempting to retrieve the result..." ,
282+ pollingOptions .getInitialDelaySec ()
283+ );
259284 interruptibleSleep ((long ) (pollingOptions .getInitialDelaySec () * 1000 ), pollingOptions );
260285
261286 JobResponse resp = initialJob ;
@@ -265,12 +290,20 @@ private <TResponse extends CommonResponse> TResponse pollAndFetch(
265290
266291 while (attempts < max ) {
267292 interruptibleSleep (intervalMillis , pollingOptions );
293+ logger .log (System .Logger .Level .DEBUG , "Poll attempt {0} of {1}" , attempts + 1 , max );
268294 resp = getJob (initialJob .getJob ().getId ());
269295
270296 if (resp .getJob ().getStatus ().equals ("Failed" )) {
271297 attempts = max ;
272298 }
273299 if (resp .getJob ().getStatus ().equals ("Processed" )) {
300+ logger
301+ .log (
302+ System .Logger .Level .DEBUG ,
303+ "Job ID {0} completed processing at: {1}" ,
304+ resp .getJob ().getId (),
305+ resp .getJob ().getCompletedAt ()
306+ );
274307 return getResult (responseClass , resp .getJob ().getId ());
275308 }
276309 attempts ++;
0 commit comments