📄 rpdownload.java
字号:
/*
* File : PRDownload.java
* Created : 28-Jan-2004
* By : parg
*
* Azureus - a Java Bittorrent client
*
* 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; either version 2 of the License.
*
* 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 ( see the LICENSE file ).
*
* 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.gudy.azureus2.pluginsimpl.remote.download;
/**
* @author parg
*
*/
import java.io.File;
import java.util.Map;
import org.gudy.azureus2.plugins.disk.DiskManager;
import org.gudy.azureus2.plugins.disk.DiskManagerFileInfo;
import org.gudy.azureus2.plugins.download.*;
import org.gudy.azureus2.plugins.download.session.SessionAuthenticator;
import org.gudy.azureus2.plugins.peers.PeerManager;
import org.gudy.azureus2.plugins.torrent.*;
import org.gudy.azureus2.pluginsimpl.remote.*;
import org.gudy.azureus2.pluginsimpl.remote.disk.RPDiskManagerFileInfo;
import org.gudy.azureus2.pluginsimpl.remote.ipfilter.RPIPRange;
import org.gudy.azureus2.pluginsimpl.remote.torrent.*;
public class
RPDownload
extends RPObject
implements Download
{
protected transient Download delegate;
// don't change these field names as they are visible on XML serialisation
public RPTorrent torrent;
public RPDownloadStats stats;
public RPDownloadAnnounceResult announce_result;
public RPDownloadScrapeResult scrape_result;
public int position;
public boolean force_start;
public static RPDownload
create(
Download _delegate )
{
RPDownload res =(RPDownload)_lookupLocal( _delegate );
if ( res == null ){
res = new RPDownload( _delegate );
}
return( res );
}
protected
RPDownload(
Download _delegate )
{
super( _delegate );
// torrent can be null if broken
if ( delegate.getTorrent() != null ){
torrent = (RPTorrent)_lookupLocal( delegate.getTorrent());
if ( torrent == null ){
torrent = RPTorrent.create( delegate.getTorrent());
}
}
stats = (RPDownloadStats)_lookupLocal( delegate.getStats());
if ( stats == null ){
stats = RPDownloadStats.create( delegate.getStats());
}
announce_result = (RPDownloadAnnounceResult)_lookupLocal( delegate.getLastAnnounceResult());
if ( announce_result == null ){
announce_result = RPDownloadAnnounceResult.create( delegate.getLastAnnounceResult());
}
scrape_result = (RPDownloadScrapeResult)_lookupLocal( delegate.getLastScrapeResult());
if ( scrape_result == null ){
scrape_result = RPDownloadScrapeResult.create( delegate.getLastScrapeResult());
}
}
protected void
_setDelegate(
Object _delegate )
{
delegate = (Download)_delegate;
position = delegate.getPosition();
force_start = delegate.isForceStart();
}
public Object
_setLocal()
throws RPException
{
Object res = _fixupLocal();
if ( torrent != null ){
torrent._setLocal();
}
stats._setLocal();
announce_result._setLocal();
scrape_result._setLocal();
return( res );
}
public void
_setRemote(
RPRequestDispatcher dispatcher )
{
super._setRemote( dispatcher );
if ( torrent != null ){
torrent._setRemote( dispatcher );
}
stats._setRemote( dispatcher );
announce_result._setRemote( dispatcher );
scrape_result._setRemote( dispatcher );
}
public RPReply
_process(
RPRequest request )
{
String method = request.getMethod();
if ( method.equals( "initialize")){
try{
delegate.initialize();
}catch( DownloadException e ){
return( new RPReply(e));
}
return( null );
}else if ( method.equals( "start")){
try{
delegate.start();
}catch( DownloadException e ){
return( new RPReply(e));
}
return( null );
}else if ( method.equals( "restart")){
try{
delegate.restart();
}catch( DownloadException e ){
return( new RPReply(e));
}
return( null );
}else if ( method.equals( "stop")){
try{
delegate.stop();
}catch( DownloadException e ){
return( new RPReply(e));
}
return( null );
}else if ( method.equals( "remove")){
try{
delegate.remove();
}catch( Throwable e ){
return( new RPReply(e));
}
return( null );
}else if ( method.equals( "setForceStart[boolean]")){
boolean b = ((Boolean)request.getParams()[0]).booleanValue();
delegate.setForceStart( b );
return( null );
}else if ( method.equals( "setPosition[int]")){
int p = ((Integer)request.getParams()[0]).intValue();
delegate.setPosition( p );
return( null );
}else if ( method.equals( "moveUp")){
delegate.moveUp();
return( null );
}else if ( method.equals( "moveDown")){
delegate.moveDown();
return( null );
}else if ( method.equals( "moveTo[int]")){
int p = ((Integer)request.getParams()[0]).intValue();
delegate.setPosition( p );
return( null );
}else if ( method.equals( "setPriority[int]")){
delegate.setPriority(((Integer)request.getParams()[0]).intValue());
return( null );
}else if ( method.equals( "requestTrackerAnnounce")){
delegate.requestTrackerAnnounce();
return( null );
}else if ( method.equals( "getDiskManagerFileInfo")){
DiskManagerFileInfo[] info = delegate.getDiskManagerFileInfo();
RPDiskManagerFileInfo[] rp_info = new RPDiskManagerFileInfo[info.length];
for (int i=0;i<rp_info.length;i++){
rp_info[i] = RPDiskManagerFileInfo.create( info[i] );
}
return( new RPReply( rp_info ));
}
throw( new RPException( "Unknown method: " + method ));
}
// ***************************************************
public int
getState()
{
notSupported();
return(0);
}
public int
getSubState()
{
notSupported();
return(0);
}
public String
getErrorStateDetails()
{
notSupported();
return( null );
}
public boolean
getFlag(
long flag )
{
notSupported();
return( false );
}
public int
getIndex()
{
notSupported();
return( 0 );
}
public Torrent
getTorrent()
{
return( torrent );
}
public byte[] getDownloadPeerId() {
return delegate.getDownloadPeerId();
}
public boolean isMessagingEnabled() { return delegate.isMessagingEnabled(); }
public void setMessagingEnabled( boolean enabled ) {
delegate.setMessagingEnabled( enabled );
}
public void
initialize()
throws DownloadException
{
try{
_dispatcher.dispatch( new RPRequest( this, "initialize", null )).getResponse();
}catch( RPException e ){
if ( e.getCause() instanceof DownloadException ){
throw((DownloadException)e.getCause());
}
throw( e );
}
}
public void
start()
throws DownloadException
{
try{
_dispatcher.dispatch( new RPRequest( this, "start", null )).getResponse();
}catch( RPException e ){
if ( e.getCause() instanceof DownloadException ){
throw((DownloadException)e.getCause());
}
throw( e );
}
}
public void
stop()
throws DownloadException
{
try{
_dispatcher.dispatch( new RPRequest( this, "stop", null )).getResponse();
}catch( RPException e ){
if ( e.getCause() instanceof DownloadException ){
throw((DownloadException)e.getCause());
}
throw( e );
}
}
public void
restart()
throws DownloadException
{
try{
_dispatcher.dispatch( new RPRequest( this, "restart", null )).getResponse();
}catch( RPException e ){
if ( e.getCause() instanceof DownloadException ){
throw((DownloadException)e.getCause());
}
throw( e );
}
}
public boolean
isStartStopLocked()
{
notSupported();
return( false );
}
public boolean
isPaused()
{
notSupported();
return( false );
}
public void
pause()
{
notSupported();
}
public void
resume()
{
notSupported();
}
public int
getPriority()
{
//do nothing deprecated
return 0;
}
public void
setPriority(
int priority )
{
//Do nothing, deprecated
}
/**
* @deprecated
*/
public boolean
isPriorityLocked()
{
// Do nothing, deprecated
return( false );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -