/*
 * The MIT License (MIT)
 * <p/>
 * Copyright (c) 2016 Bertrand Martel
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package fr.bmartel.speedtest.examples;

import fr.bmartel.speedtest.IRepeatListener;
import fr.bmartel.speedtest.SpeedTestReport;
import fr.bmartel.speedtest.SpeedTestSocket;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Download a file repeatedly from speed test server during a fixed amount of time.
 *
 * @author Bertrand Martel
 */
public class RepeatDownloadExample {

    /**
     * speed examples server host name.
     */
    private final static String SPEED_TEST_SERVER_HOST = "1.testdebit.info";

    /**
     * spedd examples server uri.
     */
    private final static String SPEED_TEST_SERVER_URI_DL = "/fichiers/10Mo.dat";

    /**
     * speed examples server port.
     */
    private final static int SPEED_TEST_SERVER_PORT = 80;

    /**
     * logger.
     */
    private final static Logger LOGGER = LogManager.getLogger(RepeatDownloadExample.class.getName());

    /**
     * speed test duration set to 11s.
     */
    private static final int SPEED_TEST_DURATION = 11000;

    /**
     * amount of time between each speed test report set to 1s.
     */
    private static final int REPORT_INTERVAL = 1000;

    /**
     * Repeat download example main.
     *
     * @param args no args required
     */
    public static void main(final String[] args) {

        final SpeedTestSocket speedTestSocket = new SpeedTestSocket();

        speedTestSocket.startDownloadRepeat(SPEED_TEST_SERVER_HOST, SPEED_TEST_SERVER_PORT, SPEED_TEST_SERVER_URI_DL,
                SPEED_TEST_DURATION, REPORT_INTERVAL, new
                        IRepeatListener() {
                            @Override
                            public void onFinish(final SpeedTestReport report) {

                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug(LogUtils.LOG_REPORT_SEPARATOR);
                                    LOGGER.debug("---------------------DOWNLOAD FINISHED------------------");
                                    LOGGER.debug(LogUtils.LOG_REPORT_SEPARATOR);
                                }
                                LogUtils.logReport(report, LOGGER);
                            }

                            @Override
                            public void onReport(final SpeedTestReport report) {
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug("---------------current download report------------------");
                                }
                                LogUtils.logReport(report, LOGGER);
                            }
                        });
    }
}

@@ -1234,113 +1234,9 @@
 est.
-IRepeatListener;%0Aimport fr.bmartel.speedtest.SpeedTestReport;%0Aimport fr.bmartel.speedtest.SpeedTestSocket
+*
 ;%0A%0Ai
@@ -2381,24 +2381,24 @@
 %5B%5D args) %7B%0A%0A
-
         fina
@@ -2453,24 +2453,1593 @@
 tSocket();%0A%0A
+        //set socket timeout to 3s%0A        speedTestSocket.setSocketTimeout(3000);%0A%0A        speedTestSocket.addSpeedTestListener(new ISpeedTestListener() %7B%0A%0A            @Override%0A            public void onDownloadPacketsReceived(final long packetSize, final float transferRateBitPerSeconds, final%0A            float%0A                    transferRateOctetPerSeconds) %7B%0A                //called when download is finished%0A            %7D%0A%0A            @Override%0A            public void onDownloadError(final SpeedTestError speedTestError, final String errorMessage) %7B%0A%0A                if (LOGGER.isErrorEnabled()) %7B%0A                    LOGGER.error(errorMessage);%0A                %7D%0A            %7D%0A%0A            @Override%0A            public void onUploadPacketsReceived(final long packetSize, final float transferRateBitPerSeconds, final%0A            float transferRateOctetPerSeconds) %7B%0A                //called when upload is finished%0A            %7D%0A%0A            @Override%0A            public void onUploadError(final SpeedTestError speedTestError, final String errorMessage) %7B%0A%0A                if (LOGGER.isErrorEnabled()) %7B%0A                    LOGGER.error(errorMessage);%0A                %7D%0A            %7D%0A%0A            @Override%0A            public void onDownloadProgress(final float percent, final SpeedTestReport downloadReport) %7B%0A                //notify download progress%0A            %7D%0A%0A            @Override%0A            public void onUploadProgress(final float percent, final SpeedTestReport uploadReport) %7B%0A                //notify upload progress%0A            %7D%0A        %7D);%0A%0A
         spee

add timeout & print error for repeat download example task