Search in sources :

Example 6 with Profiler

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);
            }
        }
    }
}
Also used : Profiler(eu.fthevenet.util.logging.Profiler) InputStreamReader(java.io.InputStreamReader) ZonedDateTime(java.time.ZonedDateTime) BufferedReader(java.io.BufferedReader) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 7 with Profiler

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);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) KeyStoreException(java.security.KeyStoreException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) Profiler(eu.fthevenet.util.logging.Profiler)

Example 8 with Profiler

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();
    }
}
Also used : Profiler(eu.fthevenet.util.logging.Profiler) Parent(javafx.scene.Parent) Image(javafx.scene.image.Image) Scene(javafx.scene.Scene)

Aggregations

Profiler (eu.fthevenet.util.logging.Profiler)8 ZonedDateTime (java.time.ZonedDateTime)5 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Parent (javafx.scene.Parent)2 Scene (javafx.scene.Scene)2 MainViewController (eu.fthevenet.binjr.controllers.MainViewController)1 DataAdapter (eu.fthevenet.binjr.data.adapters.DataAdapter)1 TimeSeriesBinding (eu.fthevenet.binjr.data.adapters.TimeSeriesBinding)1 AsyncTaskManager (eu.fthevenet.binjr.data.async.AsyncTaskManager)1 NoAdapterFoundException (eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException)1 TimeSeriesProcessor (eu.fthevenet.binjr.data.timeseries.TimeSeriesProcessor)1 eu.fthevenet.binjr.data.workspace (eu.fthevenet.binjr.data.workspace)1 Chart (eu.fthevenet.binjr.data.workspace.Chart)1 TimeSeriesInfo (eu.fthevenet.binjr.data.workspace.TimeSeriesInfo)1 Dialogs (eu.fthevenet.binjr.dialogs.Dialogs)1 GlobalPreferences (eu.fthevenet.binjr.preferences.GlobalPreferences)1 BindingManager (eu.fthevenet.util.javafx.bindings.BindingManager)1 eu.fthevenet.util.javafx.charts (eu.fthevenet.util.javafx.charts)1