package transfer.download.logic;
import transfer.download.FileDownloadConnection;
import transfer.download.FileDownloadConnector;
import common.connection.AbstractConnection;
import common.connection.client.AbstractClientSideConnector;
import common.connection.client.ConnectionAttempt;
import common.connection.client.ConnectionAttempterInterface;
import common.info.FileSource;
public class DownloadAttempter implements ConnectionAttempterInterface
{
private AttemptManagerInterface manager;
private AbstractConnection connection = null;
public DownloadAttempter(AttemptManagerInterface manager, FileSource source)
{
this.manager = manager;
new ConnectionAttempt(this, source.getAddress());
}
public AbstractClientSideConnector getConnector()
{
return new FileDownloadConnector(manager.getDownload(), this);
}
public void notifyConnected(FileDownloadConnection connection)
{
this.connection = connection;
connection.requestFile();
}
public void notifyFullSuccess(FileDownloadConnection connection)
{
manager.notifyFullSuccess(connection);
}
public void notifyFailure()
{
manager.notifyFailure(this);
}
public void notifyInvalidFile()
{
manager.notifyFailure(this);
}
public void cancel()
{
if (connection != null)
{
connection.terminate();
}
}
}