FreewayDownload.java

Index Score
org.xnap.plugin.freeway
XNap 3

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
/* * XNap - A P2P framework and client. * * See the file AUTHORS for copyright information. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.xnap.plugin.freeway; import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; import javax.swing.Action; import javax.swing.Icon; import org.apache.log4j.Logger; import org.gnu.freeway.protocol.afs.esed2.DownloadUtil; import org.gnu.freeway.protocol.afs.esed2.ProgressModel; import org.gnu.freeway.protocol.afs.esed2.ProgressStats; import org.gnu.freeway.protocol.afs.esed2.RequestManager; import org.gnu.freeway.protocol.afs.esed2.RootNode; import org.gnu.freeway.util.AbstractAction; import org.gnu.freeway.util.ConfigurationService; import org.gnu.freeway.util.CronService; import org.gnu.freeway.util.Task; import org.xnap.XNap; import org.xnap.peer.Peer; import org.xnap.plugin.Plugin; import org.xnap.transfer.AbstractDownload; import org.xnap.transfer.action.AbstractDeleteAction; import org.xnap.util.FileHelper; /** * */ public class FreewayDownload extends AbstractDownload implements ProgressModel { private RootNode node; private long startTime; private RequestManager reqMan = null; private FreewayPlugin plugin = FreewayPlugin.getInstance(); private Task downloader = null; private File file; private long bytesTransferred = 0; private long filesize; private boolean done = false; private static Logger logger = Logger.getLogger(FreewayDownload.class); /** * @param node */ public FreewayDownload(RootNode node) { this.node = node; filesize = node.getFileIdentifier().getFileLength(); try { file = FileHelper.createIncompleteFile(node.getFileName()); } catch (IOException ie) { logger.debug("Could not create incomplete file", ie); } downloader = new Task("GNUNet Download", new DownloadJob()); downloader.launch(); transferStarted(); } /* * @see org.xnap.transfer.AbstractTransfer#getBytesTransferred() */ protected long getBytesTransferred() { return bytesTransferred; } /* * @see org.xnap.transfer.Transfer#getActions() */ public Action[] getActions() { return new Action[] { new FreewayDeleteAction() }; } /* * @see org.xnap.transfer.Transfer#getFile() */ public File getFile() { return file; } public long getFilesize() { return filesize; } /* * @see org.xnap.transfer.Transfer#getPeer() */ public Peer getPeer() { return null; } /* * @see org.xnap.transfer.Transfer#getPlugin() */ public Plugin getPlugin() { return plugin; } /* * @see org.xnap.transfer.Transfer#getStatus() */ public String getStatus() { return done ? XNap.tr("Finished") : XNap.tr("Running"); } public Icon getIcon() { return FreewayPlugin.ICON_16; } /* * @see org.xnap.transfer.Transfer#getTotalBytesTransferred() */ public long getTotalBytesTransferred() { return bytesTransferred; } /* * @see org.xnap.transfer.Transfer#isDone() */ public boolean isDone() { return done; } public void transferStopped() { if (reqMan != null) { reqMan.destroy(); } super.transferStopped(); } /* * @see org.xnap.transfer.Transfer#isRunning() */ public boolean isRunning() { return !done; } public void progress(ProgressStats stats, Object obj) { bytesTransferred = stats.progress; if (filesize != stats.filesize) { logger.debug("Inconsistent filesizes"); } if (stats.filesize == stats.progress) { done = true; transferStopped(); } } private class DownloadJob extends AbstractAction { public void perform() throws Throwable { /* this starts the "real" download thread in the background, with "modelCallback" called back to tell us about the progress */ reqMan = new DownloadUtil().downloadFile (plugin.getPreferences(), (ConfigurationService)plugin.service(ConfigurationService.class), (CronService)plugin.service(CronService.class), plugin.getPolicy(), node.getFileIdentifier(), file.getAbsolutePath(), FreewayDownload.this, this); if (reqMan == null) { logger.debug("Download could not be started"); done = true; return; } } } private class FreewayDeleteAction extends AbstractDeleteAction { public FreewayDeleteAction() { setEnabled(false); } public void actionPerformed(ActionEvent e) { // if (downloader != null) { // downloader. // } // // if (reqMan != null) { // reqMan.destroy(); // file.delete(); // } } } }

The table below shows all metrics for FreewayDownload.java.

MetricValueDescription