use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class CsvDecoder method decode.
/**
* Decodes data from the provided stream and invoke the provided {@link Consumer} for each decoded record.
*
* @param in the {@link InputStream} for the CSV file
* @param headers a list of the headers to keep from decoded records
* @param mapToResult the function to invoke for reach decoded record
* @throws IOException in the event of an I/O error.
* @throws DecodingDataFromAdapterException if an error occurred while decoding the CSV file.
*/
public void decode(InputStream in, List<String> headers, Consumer<DataSample<T>> mapToResult) throws IOException, DecodingDataFromAdapterException {
try (Profiler ignored = Profiler.start("Building time series from csv data", logger::trace)) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, encoding))) {
CSVFormat csvFormat = CSVFormat.DEFAULT.withAllowMissingColumnNames(false).withFirstRecordAsHeader().withSkipHeaderRecord().withDelimiter(delimiter);
Iterable<CSVRecord> records = csvFormat.parse(reader);
for (CSVRecord csvRecord : records) {
ZonedDateTime timeStamp = dateParser.apply(csvRecord.get(0));
DataSample<T> tRecord = new DataSample<>(timeStamp);
for (String h : headers) {
tRecord.getCells().put(h, numberParser.apply(csvRecord.get(h)));
}
mapToResult.accept(tRecord);
}
}
}
}
use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class HttpDataAdapterBase method doHttpGet.
// endregion
protected <R> R doHttpGet(URI requestUri, ResponseHandler<R> responseHandler) throws DataAdapterException {
try (Profiler p = Profiler.start("Executing HTTP request: [" + requestUri.toString() + "]", logger::trace)) {
logger.debug(() -> "requestUri = " + requestUri);
HttpGet httpget = new HttpGet(requestUri);
// Set user-agent pattern to workaround CAS server not proposing SPNEGO authentication unless it thinks agent can handle it.
httpget.setHeader("User-Agent", "binjr/" + AppEnvironment.getInstance().getVersion() + " (Authenticates like: Firefox/Safari/Internet Explorer)");
R result = httpClient.execute(httpget, responseHandler);
if (result == null) {
throw new FetchingDataFromAdapterException("Response entity to \"" + requestUri.toString() + "\" is null.");
}
return result;
} catch (HttpResponseException e) {
String msg;
switch(e.getStatusCode()) {
case 401:
msg = "Authentication failed while trying to access \"" + requestUri.toString() + "\"";
break;
case 403:
msg = "Access to the resource at \"" + requestUri.toString() + "\" is denied.";
break;
case 404:
msg = "The resource at \"" + requestUri.toString() + "\" could not be found.";
break;
case 500:
msg = "A server-side error has occurred while trying to access the resource at \"" + requestUri.toString() + "\": " + e.getMessage();
break;
default:
msg = "Error executing HTTP request \"" + requestUri.toString() + "\": " + e.getMessage();
break;
}
throw new SourceCommunicationException(msg, e);
} catch (ConnectException e) {
throw new SourceCommunicationException(e.getMessage(), e);
} catch (UnknownHostException e) {
throw new SourceCommunicationException("Host \"" + baseAddress.getHost() + (baseAddress.getPort() > 0 ? ":" + baseAddress.getPort() : "") + "\" could not be found.", e);
} catch (SSLHandshakeException e) {
throw new SourceCommunicationException("An error occurred while negotiating connection security: " + e.getMessage(), e);
} catch (IOException e) {
throw new SourceCommunicationException("IO error while communicating with host \"" + baseAddress.getHost() + (baseAddress.getPort() > 0 ? ":" + baseAddress.getPort() : "") + "\": " + e.getMessage(), e);
} catch (Exception e) {
throw new SourceCommunicationException("Unexpected error in HTTP GET: " + e.getMessage(), e);
}
}
use of eu.fthevenet.util.logging.Profiler in project selenium_java by sergueik.
the class About method start.
@Override
public void start(Stage primaryStage) throws Exception {
logger.info(() -> "Starting binjr");
Parent root = FXMLLoader.load(getClass().getResource("/views/AboutBoxView.fxml"));
primaryStage.setTitle("binjr");
primaryStage.getIcons().addAll(new Image(getClass().getResourceAsStream("/icons/binjr_16.png")), new Image(getClass().getResourceAsStream("/icons/binjr_32.png")), new Image(getClass().getResourceAsStream("/icons/binjr_48.png")), new Image(getClass().getResourceAsStream("/icons/binjr_128.png")), new Image(getClass().getResourceAsStream("/icons/binjr_256.png")));
try (Profiler p = Profiler.start("Set scene", logger::trace)) {
primaryStage.setScene(new Scene(root));
}
try (Profiler p = Profiler.start("show", logger::trace)) {
primaryStage.show();
}
SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null) {
splash.close();
}
}
Aggregations