Changeset 35246 for gs3-extensions


Ignore:
Timestamp:
2021-08-04T10:16:02+12:00 (3 years ago)
Author:
davidb
Message:

Cleanup old asynchronous code and fix string comparison

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/services/ReoTuhituhiApiService.java

    r35242 r35246  
    22
    33import java.io.InputStream;
    4 import java.util.ArrayList;
    54import java.util.LinkedList;
    65import java.util.List;
    7 import java.util.Queue;
    8 import java.util.concurrent.Callable;
    9 import java.util.concurrent.ExecutorService;
    10 import java.util.concurrent.Future;
    116
    127import com.google.gson.Gson;
     
    2722    private static final Logger logger = LogManager.getLogger(ReoTuhituhiApiService.class);
    2823
    29     private final ExecutorService threadPool;
    3024    private final Gson jsonSerialiser;
    3125    private final String apiEndpoint;
     
    3731        this.apiEndpoint = apiEndpoint;
    3832        this.apiKey = apiKey;
    39 
    40         threadPool = java.util.concurrent.Executors.newFixedThreadPool(3);
    4133    }
    4234
     
    5244        throws HttpRequestException, JsonSyntaxException, Exception
    5345    {
    54         Queue<Future<AudioFilePart>> apiCalls = new LinkedList<Future<AudioFilePart>>();
    55 
    56         // Queue each transcription request up asynchronously
    57         for (AudioFilePart part : audioFileParts)
    58         {
    59             //Callable<TranscriptionResult> transcriptionTask = getTranscriptionCallable(audioStream);
    60             //apiCalls.add(threadPool.submit(transcriptionTask));
    61             //logger.debug("Adding transcription task to thread pool.");
    62         }
    63 
    64         List<AudioFilePart> apiResults = new ArrayList<AudioFilePart>(apiCalls.size());
     46        List<AudioFilePart> apiResults = new LinkedList<AudioFilePart>();
    6547       
    6648        for (AudioFilePart part : audioFileParts)
     
    7153            apiResults.add(part);
    7254        }
    73 
    74         // Wait on the result of each call
    75         // TODO: Implement proper timeout here
    76         // while (!apiCalls.isEmpty())
    77         // {
    78         //     apiResults.add(apiCalls.remove().get());
    79         //     logger.debug("API call has completed.");
    80         // }
    8155
    8256        return apiResults;
     
    11488
    11589        // Check that the content type is valid
    116         if (request.contentType() != "application/json")
     90        if (!request.contentType().equals("application/json"))
    11791        {
    11892            logger.error
    11993            (
    120                 "The Reo Tuhituhi API returned an invalid content type {}. Provided content was {}",
     94                "The Reo Tuhituhi API returned an invalid content type of {}. Provided content was {}",
    12195                request.contentType(),
    12296                request.body()
     
    130104        return res;
    131105    }
    132 
    133     private Callable<AudioFilePart> getTranscriptionCallable(final AudioFilePart part)
    134     {
    135         return new Callable<AudioFilePart>()
    136         {
    137             @Override
    138             public AudioFilePart call()
    139                 throws Exception
    140             {
    141                 TranscriptionResult res = getTranscription(part.dataStream);
    142                 part.setTranscriptionResult(res);
    143                 return part;
    144             }
    145         };
    146     }
    147106}
Note: See TracChangeset for help on using the changeset viewer.