📄 downloadmanagerstateimpl.java
字号:
public int getIntAttribute(String name) {
return (int)getLongAttribute(name);
}
public void setBooleanAttribute(String name, boolean value) {
setLongAttribute(name, (value ? 1 : 0));
}
public boolean getBooleanAttribute(String name) {
return getLongAttribute(name) != 0;
}
public static DownloadManagerState
getDownloadState(
DownloadManager dm )
{
return( new nullState(dm));
}
protected void
informWritten(
final String attribute_name )
{
for (int i=0;i<listeners.size();i++){
try{
((DownloadManagerStateListener)listeners.get(i)).stateChanged(
this,
new DownloadManagerStateEvent()
{
public int
getType()
{
return( DownloadManagerStateEvent.ET_ATTRIBUTE_WRITTEN );
}
public Object
getData()
{
return( attribute_name );
}
});
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
protected void
informWillRead(
final String attribute_name )
{
// avoid potential recursion will a will-be-read causing a write that then
// causes a further will-be-read...
boolean do_it = false;
try{
try{
this_mon.enter();
if ( !will_be_read_list.contains( attribute_name )){
do_it = true;
will_be_read_list.add( attribute_name );
}
}finally{
this_mon.exit();
}
if ( do_it ){
for (int i=0;i<listeners.size();i++){
try{
((DownloadManagerStateListener)listeners.get(i)).stateChanged(
this,
new DownloadManagerStateEvent()
{
public int
getType()
{
return( DownloadManagerStateEvent.ET_ATTRIBUTE_WILL_BE_READ );
}
public Object
getData()
{
return( attribute_name );
}
});
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
}finally{
if ( do_it ){
try{
this_mon.enter();
will_be_read_list.remove( attribute_name );
}finally{
this_mon.exit();
}
}
}
}
public void
addListener(
DownloadManagerStateListener l )
{
listeners.add( l );
}
public void
removeListener(
DownloadManagerStateListener l )
{
listeners.remove(l);
}
public void
generateEvidence(
IndentWriter writer)
{
writer.println( "DownloadManagerState" );
try{
writer.indent();
writer.println( "parameters=" + parameters );
}finally{
writer.exdent();
}
}
protected static class
nullState
implements DownloadManagerState
{
protected DownloadManager download_manager;
protected
nullState(
DownloadManager _dm )
{
download_manager = _dm;
}
public TOTorrent
getTorrent()
{
return( null );
}
public File
getStateFile(
String name )
{
return( null );
}
public DownloadManager
getDownloadManager()
{
return( download_manager );
}
public void
clearResumeData()
{
}
public Map
getResumeData()
{
return( new HashMap());
}
public void
setResumeData(
Map data )
{
}
public boolean
isResumeDataComplete()
{
return( false );
}
public void
clearTrackerResponseCache()
{
}
public Map
getTrackerResponseCache()
{
return( new HashMap());
}
public void
setTrackerResponseCache(
Map value )
{
}
public void
setFlag(
long flag,
boolean set )
{
}
public boolean
getFlag(
long flag )
{
return( false );
}
public void
setParameterDefault(
String name )
{
}
public long
getLongParameter(
String name )
{
return( 0 );
}
public void
setLongParameter(
String name,
long value )
{
}
public int
getIntParameter(
String name )
{
return( 0 );
}
public void
setIntParameter(
String name,
int value )
{
}
public boolean
getBooleanParameter(
String name )
{
return( false );
}
public void
setBooleanParameter(
String name,
boolean value )
{
}
public void
setAttribute(
String name,
String value )
{
}
public String
getAttribute(
String name )
{
return( null );
}
public String
getTrackerClientExtensions()
{
return( null );
}
public void
setTrackerClientExtensions(
String value )
{
}
public void
setListAttribute(
String name,
String[] values )
{
}
public String[]
getListAttribute(
String name )
{
return( null );
}
public void
setMapAttribute(
String name,
Map value )
{
}
public Map
getMapAttribute(
String name )
{
return( null );
}
public boolean hasAttribute(String name) {return false;}
public int getIntAttribute(String name) {return 0;}
public long getLongAttribute(String name) {return 0L;}
public boolean getBooleanAttribute(String name) {return false;}
public void setIntAttribute(String name, int value) {}
public void setLongAttribute(String name, long value) {}
public void setBooleanAttribute(String name, boolean value) {}
public Category
getCategory()
{
return( null );
}
public void
setCategory(
Category cat )
{
}
public String[]
getNetworks()
{
return( new String[0] );
}
public boolean isNetworkEnabled(String network) {
return false;
}
public void
setNetworks(
String[] networks )
{
}
public void setNetworkEnabled(
String network,
boolean enabled) {
}
public String[]
getPeerSources()
{
return( new String[0] );
}
public boolean
isPeerSourcePermitted(
String peerSource )
{
return( false );
}
public boolean
isPeerSourceEnabled(
String peerSource) {
return false;
}
public void
setPeerSources(
String[] networks )
{
}
public void
setPeerSourceEnabled(
String source,
boolean enabled) {
}
public void
setFileLink(
File link_source,
File link_destination )
{
}
public void
clearFileLinks()
{
}
public File
getFileLink(
File link_source )
{
return( null );
}
public CaseSensitiveFileMap
getFileLinks()
{
return( new CaseSensitiveFileMap());
}
public void
save()
{
}
public void
delete()
{
}
public void
addListener(
DownloadManagerStateListener l )
{}
public void
removeListener(
DownloadManagerStateListener l )
{}
public void setDisplayName(String name) {}
public String getDisplayName() {return null;}
public void setUserComment(String name) {}
public String getUserComment() {return null;}
public void setRelativeSavePath(String name) {}
public String getRelativeSavePath() {return null;}
public boolean parameterExists(String name) {
// TODO Auto-generated method stub
return false;
}
public void
generateEvidence(
IndentWriter writer)
{
writer.println( "DownloadManagerState: broken torrent" );
}
public boolean isOurContent() {
// TODO Auto-generated method stub
return false;
}
// @see org.gudy.azureus2.core3.download.DownloadManagerState#getPrimaryFile()
public String getPrimaryFile() {
// TODO Auto-generated method stub
return null;
}
// @see org.gudy.azureus2.core3.download.DownloadManagerState#setPrimaryFile(java.lang.String)
public void setPrimaryFile(String relativeFile) {
// TODO Auto-generated method stub
}
}
protected static class
CachedStateWrapper
extends LogRelation
implements TOTorrent
{
private DownloadManagerImpl download_manager;
private String torrent_file;
private HashWrapper torrent_hash_wrapper;
private Map cache;
private Map cache_attributes;
private TOTorrent delegate;
private TOTorrentException fixup_failure;
private boolean discard_pieces;
private boolean logged_failure;
protected
CachedStateWrapper(
DownloadManagerImpl _download_manager,
String _torrent_file,
byte[] _torrent_hash,
Map _cache,
boolean _force_piece_discard )
{
download_manager = _download_manager;
torrent_file = _torrent_file;
torrent_hash_wrapper = new HashWrapper( _torrent_hash );
cache = _cache;
cache_attributes = (Map)cache.get( "attributes" );
if ( _force_piece_discard ){
discard_pieces = true;
}else{
Long l_fp = (Long)cache.get( "dp" );
if ( l_fp != null ){
discard_pieces = l_fp.longValue() == 1;
}
}
}
protected static Map
export(
DownloadManagerState dms )
throws TOTorrentException
{
Map cache = new HashMap();
TOTorrent state = dms.getTorrent();
cache.put( "hash", state.getHash());
cache.put( "name", state.getName());
cache.put( "comment", state.getComment());
cache.put( "createdby", state.getCreatedBy());
cache.put( "size", new Long( state.getSize()));
cache.put( "encoding", state.getAdditionalStringProperty( "encoding" ));
cache.put( "torrent filename", state.getAdditionalStringProperty( "torrent filename" ));
cache.put( "attributes", state.getAdditionalMapProperty( ATTRIBUTE_KEY ));
boolean discard_pieces = dms.isResumeDataComplete();
if ( !discard_pieces ){
TOTorrent t = dms.getTorrent();
// discard pieces if they are currently discarded
if ( t instanceof CachedStateWrapper ){
discard_pieces = ((CachedStateWrapper)t).peekPieces() == null;
}
}
cache.put( "dp", new Long( discard_pieces?1:0 ));
return( cache );
}
protected void
clearCache()
{
cache = null;
}
protected boolean
fixup()
{
try{
if ( delegate == null ){
if ( fixup_failure != null ){
throw( fixup_failure );
}
delegate = loadRealState();
if ( cache != null ){
Debug.out( "Cache miss forced fixup" );
}
cache = null;
// join cache view back up with real state to save memory as the one
// we've just read is irrelevant due to the cache values being
// used
if ( cache_attributes != null ){
delegate.setAdditionalMapProperty( ATTRIBUTE_KEY, cache_attributes );
cache_attributes = null;
}
}
return( true );
}catch( TOTorrentException e ){
fixup_failure = e;
if ( download_manager != null ){
download_manager.setTorrentInvalid( Debug.getNestedExceptionMessage( e ));
}else{
if ( !logged_failure ){
logged_failure = true;
Debug.out( "Torrent can't be loaded: " + Debug.getNestedExceptionMessage( e ));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -