Changeset 35246 for gs3-extensions
- Timestamp:
- 2021-08-04T10:16:02+12:00 (3 years ago)
- 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 2 2 3 3 import java.io.InputStream; 4 import java.util.ArrayList;5 4 import java.util.LinkedList; 6 5 import 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;11 6 12 7 import com.google.gson.Gson; … … 27 22 private static final Logger logger = LogManager.getLogger(ReoTuhituhiApiService.class); 28 23 29 private final ExecutorService threadPool;30 24 private final Gson jsonSerialiser; 31 25 private final String apiEndpoint; … … 37 31 this.apiEndpoint = apiEndpoint; 38 32 this.apiKey = apiKey; 39 40 threadPool = java.util.concurrent.Executors.newFixedThreadPool(3);41 33 } 42 34 … … 52 44 throws HttpRequestException, JsonSyntaxException, Exception 53 45 { 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>(); 65 47 66 48 for (AudioFilePart part : audioFileParts) … … 71 53 apiResults.add(part); 72 54 } 73 74 // Wait on the result of each call75 // TODO: Implement proper timeout here76 // while (!apiCalls.isEmpty())77 // {78 // apiResults.add(apiCalls.remove().get());79 // logger.debug("API call has completed.");80 // }81 55 82 56 return apiResults; … … 114 88 115 89 // Check that the content type is valid 116 if ( request.contentType() != "application/json")90 if (!request.contentType().equals("application/json")) 117 91 { 118 92 logger.error 119 93 ( 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 {}", 121 95 request.contentType(), 122 96 request.body() … … 130 104 return res; 131 105 } 132 133 private Callable<AudioFilePart> getTranscriptionCallable(final AudioFilePart part)134 {135 return new Callable<AudioFilePart>()136 {137 @Override138 public AudioFilePart call()139 throws Exception140 {141 TranscriptionResult res = getTranscription(part.dataStream);142 part.setTranscriptionResult(res);143 return part;144 }145 };146 }147 106 }
Note:
See TracChangeset
for help on using the changeset viewer.