Package org.rssowl.contrib.podcast.core.download

Source Code of org.rssowl.contrib.podcast.core.download.DownloadsRetry

/*   **********************************************************************  **
**   Copyright notice                                                       **
**                                                                          **
**   (c) 2005-2006 RSSOwl Development Team                                  **
**   http://www.rssowl.org/                                                 **
**                                                                          **
**   All rights reserved                                                    **
**                                                                          **
**   This program and the accompanying materials are made available under   **
**   the terms of the Eclipse Public License v1.0 which accompanies this    **
**   distribution, and is available at:                                     **
**   http://www.rssowl.org/legal/epl-v10.html                               **
**                                                                          **
**   A copy is found in the file epl-v10.html and important notices to the  **
**   license from the team is found in the textfile LICENSE.txt distributed **
**   in this package.                                                       **
**                                                                          **
**   This copyright notice MUST APPEAR in all copies of the file!           **
**                                                                          **
**   Contributors:                                                          **
**     RSSOwl Development Team - initial API and implementation             **
**                                                                          **
**  **********************************************************************  */

package org.rssowl.contrib.podcast.core.download;

/**
* @author <a href="mailto:christophe@kualasoft.com">Christophe Bouhier </a>
* @author <a href="mailto:andreas.schaefer@madplanet.com">Andreas Schaefer</a>
* @version 1.1
*/

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

/**
* Downloads which fail due to time outs go into automatic retry mode. A
* download attempt which is still in the download list because of failure can
* be retried. Retry mode is initiated after a failed download. The download
* object contains a retry counter.
*
* The retry count is reported to the download table.
*/
public class DownloadsRetry {

//    private Logger mLog = Logger.getLogger(getClass().getName());

    public static long CALMDOWN_PERIOD = 10000;
    public static int RETRY_LIMIT = 3;

    /**
     * Retry a download after a timer expires. Note: This methods could be
     * invoked from within the download thread.
     *
     * @param pDownload
     */
    public void retryLater(final IDownload pDownload) {

        int retries = pDownload.getRetryCounter();
        if (retries <= RETRY_LIMIT) {
            pDownload.setState(DownloadService.RETRYING);
//            mLog.info("Retry timer activated, retries=" + retries);
            Timer t = new Timer((int) CALMDOWN_PERIOD, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        pDownload
                                .setRetryCounter(pDownload.getRetryCounter() + 1);
//                        mLog.info("Retrying"
//                                + pDownload.getAttachment());
//                        DownloadLogic.getInstance().download(pDownload);

                    } catch (Exception e1) {
//                        mLog.info("Retry failed"
//                                + pDownload.getAttachment());
                    }
                }
            });
            t.setInitialDelay((int) CALMDOWN_PERIOD);
            t.setRepeats(false);
            t.start();

        } else {
//            mLog.info("No more retries allowed for"
//                    + pDownload.getAttachment());
//            pDownload.setState(DownloadLogic.ERROR);
//            pDownload.setMessage("");
        }
    }
}
TOP

Related Classes of org.rssowl.contrib.podcast.core.download.DownloadsRetry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.