...
The requests can be executed only after EagleML Client API was started using the EagleApi.start() method.
The You can execute the asynchronous requests can be executed in two modes - with an asynchronous callback or by waiting on Future<IEagleApiResult> object.
...
:
- Wait on a Future<IEagleApiResult> object
- Asynchronous execution with a callback
Wait on a Future<IEagleApiResult> object
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// THIS IS A SAMPLE OF THE REQUEST EXECUTION. REQUESTS CAN BE EXECUTED ONLY AFTER THE eaglemlApi.start() is called. Map<String, String> parameters = new HashMap<String, String>(); // Add the parameters required to build an URI // Generate a unique correlationId // Add the attachments for the POST request Future<IEagleApiResult> futureResult = eaglemlApi.executeRestRequestAsync("GET", "/eagle/v2/manager-relationships", parameters, correlationId, null, 600 /* timeout in seconds */); try (IEagleApiResult result = futureResult.get()) { switch(result.getResultStatus()) { case EagleApiResultStatus.SUCCESS: List<IEagleApiResultDataFile> files = result.getDataFiles(); for (IEagleApiResultDataFile file : files) { // See the java doc for the IEagleApiResultDataFile. The file will represent one result. // Currently EaglemlApi will produce only one file. // You can get a stream of uncompressed data: try(InputStream stream = file.getStream()) { // Parse the extract and execute any transformations - for example to JSON } // If needed you can get the compressed data and get access to the file with the file.isInMemory(), file.getData(), file.getFile() // The temporary files (if any) created while processing the extracts will be removed when you close the IEagleApiResult instance. // If you want to preserve you'll have to move/copy them here. } break; case EagleApiResultStatus.TIMEOUT: // TIMEOUT - report an error break; case EagleApiResultStatus.ERROR: // ERROR - use result.getErrorMessage to get the error message break; case EagleApiResultStatus.STOPPED: // The request execution was stopped, when eaglemlApi.stop() is called break; case EagleApiResultStatus.NO_DATA: // The no data result retrieved. Report this back. break; } } |
Asynchronous
...
Execution with a
...
Callback
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
• // THIS IS A SAMPLE OF THE REQUEST EXECUTION. REQUESTS CAN BE EXECUTED ONLY AFTER THE eaglemlApi.start() is called. Map<String, String> parameters = new HashMap<String, String>(); // Add the parameters required to build an URI // Generate a unique correlationId // Add the attachments for the POST request eaglemlApi.executeRestRequestAsync("GET", "/eagle/v2/manager-relationships", parameters, correlationId, businessTaskId, null, 600 /* timeout in seconds */, (result, exception) -> { if(exception != null) { // There was an exception while executing the request. Process it. } else { switch(result.getResultStatus()) { case EagleApiResultStatus.SUCCESS: List<IEagleApiResultDataFile> files = result.getDataFiles(); for (IEagleApiResultDataFile file : files) { // See the java doc for the IEagleApiResultDataFile. The file will represent one extract. // Currently EaglemlApi will produce only one file. // You can get a stream of uncompressed data: try(InputStream stream = file.getStream()) { // Parse the extract and execute any transformations - for example to JSON } // If needed you can get the compressed data and get access to the file with the file.isInMemory(), file.getData(), file.getFile() // The temporary files (if any) created while processing the extracts will be removed when you close the IEagleApiResult instance. // If you want to preserve you'll have to move/copy them here. } break; case EagleApiResultStatus.TIMEOUT: // TIMEOUT - report an error break; case EagleApiResultStatus.ERROR: // ERROR - use result.getErrorMessage to get the error message break; case EagleApiResultStatus.STOPPED: // The request execution was stopped, when eaglemlApi.stop() is called break; case EagleApiResultStatus.NO_DATA: // The extract resulted in no data retrieved. Report this back. break; } } }); |
...
Execute the request Synchronously
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// THIS IS A SAMPLE OF THE REQUEST EXECUTION. REQUESTS CAN BE EXECUTED ONLY AFTER THE eaglemlApi.start() is called. Map<String, String> parameters = new HashMap<String, String>(); // Add the parameters required to build an URI // Generate a unique correlationId // Add the attachments for the POST request try (IEagleApiResult result = eaglemlApi.executeRequestAsync("GET", "/eagle/v2/manager-relationships", parameters, correlationId, null, 600 /* timeout in seconds */)) { switch(result.getResultStatus()) { case EagleApiResultStatus.SUCCESS: List<IEagleApiResultDataFile> files = result.getDataFiles(); for (IEagleApiResultDataFile file : files) { // See the java doc for the IEagleApiResultDataFile. The file will represent one extract. // Currently EaglemlApi will produce only one file. // You can get a stream of uncompressed data: try(InputStream stream = file.getStream()) { // Parse the extract and execute any transformations - for example to JSON } // If needed you can get the compressed data and get access to the file with the file.isInMemory(), file.getData(), file.getFile() // The temporary files (if any) created while processing the extracts will be removed when you close the IEagleApiResult instance. // If you want to preserve you'll have to move/copy them here. } break; case EagleApiResultStatus.TIMEOUT: // TIMEOUT - report an error break; case EagleApiResultStatus.ERROR: // ERROR - use result.getErrorMessage to get the error message break; case EagleApiResultStatus.STOPPED: // The request execution was stopped, when eaglemlApi.stop() is called break; case EagleApiResultStatus.NO_DATA: // The extract resulted in no data retrieved. Report this back. break; } } catch(EagleApiException e) { // Process the exception }; |
...
To enable synchronous mode, enter the following in the console:
No Format |
---|
-execution=sync -rest |
To launch a single request, you can determine all necessary parameters directly in console with the "-data=" option, for . For example:
No Format |
---|
-data="httpMethod|httpPath|basecorrid|contentType|pathToFile" |
The contentType and pathToFile are optional.
When you want to launch several extracts or just want to read all parameters from a file, use the "-file=" option:
No Format |
---|
-file="C:\Users\User\Documents\my_config.txt" |
In synchronous mode, the client works like this:
- Sends a REST request.
...
- Saves the response in the temporary folder with correlation id as its name.
...
- The temporary folder is the system %TEMP%
...
- . For example: C:\Users\admin\AppData\Local\Temp\
...
- . This folder is not purged automatically
...
- .
...
- Moves to the next request on the list.
Asynchronous Mode
To enable asynchronous mode, enter the following in the console:
No Format |
---|
-execution=async -rest |
To launch a single request you can determine all necessary parameters directly in console with the "-data=" option, for . For example:
No Format |
---|
-data="httpMethod|httpPath|basecorrid|contentType|pathToFile" |
When you want to launch several requests or just want to read all parameters from a file, use the "-file=" option:
No Format |
---|
-file="C:\Users\User\Documents\my_config.txt" |
In asynchronous mode, the client works like this:
...
executes the following steps.
- Creates a callback. It is represented by a Jetty HTTP Servlet server which starts to listen on a random free port. You can set a timeout here, when it expires, the callback will be unregistered and the timeout error will be displayed. For example, a 5 min t/o:
No Format |
---|
-timeout=300 |
2. The client then executes REST request. The request will contain x-eagle-rest-callback header with the IP address of the Eagle API client, the communication port and /eagleapicallback suffix, for example:
No Format |
---|
x-eagle-rest-callback: http://99.99.99.999:63345/eagleapicallback |
3. When the server receives a request with x-eagle-rest-callback header, it sends the TaskAcknowledged (ACK) message back to the client, performs the request, archives the result data, then tries to send a multipart message consisting of the TaskStatusResponse and the result data.
4. The client receives the ACK and
...
waits for incoming multiparts (TSR+data).
...
5. On multipart arrival it
...
switches off the callback (the port is free now)
...
.
...
6. Parses the TaskStatusResponse to understand if its task status is SUCCESS, FAILED or NO_DATA.
- If the status is SUCCESS, the result data will be uploaded as an archive file and saved in the temporary folder with correlation id as its name. (temporary folder is the system %TEMP%, e.g., C:\Users\admin\AppData\Local\Temp\ - this folder is not purged automatically)
- If a folder is specified in the “resultsdir” parameter, the result data will be unzipped and stored in this particular folder.
- If “resultsdir” is not specified or empty, the extract remains unzipped in the temp folder.
- If the status is FAILED or NO_DATA, error description will be displayed.
- If the multipart does not arrive before the -timeout expires, the callback will be unregistered and the timeout error will be displayed.
...