1 /* 2 * Created on 08-Oct-2004 3 * Created by Paul Gardner 4 * Copyright (C) Azureus Software, Inc, All Rights Reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 package org.gudy.azureus2.core3.disk; 21 22 23 /** 24 * Represents a DiskManager Piece 25 * 26 * @author parg 27 * @author MjrTom 28 * 2005/Oct/08: priority handling 29 * 2006/Jan/2: refactoring, mostly to base Piece interface 30 */ 31 32 public interface 33 DiskManagerPiece 34 { getManager()35 public DiskManager getManager(); 36 getLength()37 public int getLength(); getPieceNumber()38 public int getPieceNumber(); getNbBlocks()39 public int getNbBlocks(); getBlockSize( int block_index )40 public int getBlockSize( int block_index ); 41 getReadCount()42 public short getReadCount(); setReadCount(short c)43 public void setReadCount(short c); 44 calcNeeded()45 public boolean calcNeeded(); clearNeeded()46 public void clearNeeded(); 47 48 /** @return true if any file the piece covers is neither Do Not Download nor Delete. 49 * This is not a real-time indicator. Also, the results are not reliable for pieces that are Done. 50 * Use calcNeeded() for guaranteed correct and up to date results 51 * @see calcNeeded(), clearNeeded(), setNeeded(), setNeeded(boolean) 52 */ isNeeded()53 public boolean isNeeded(); setNeeded()54 public void setNeeded(); setNeeded(boolean b)55 public void setNeeded(boolean b); 56 57 // a piece is Written if data has been written to storage for every block (without concern for if it's checked) isWritten()58 public boolean isWritten(); getNbWritten()59 public int getNbWritten(); getWritten()60 public boolean[] getWritten(); 61 62 /** 63 * @param blockNumber int 64 * @return true if the given blockNumber has already been written to disk 65 */ isWritten(int blockNumber)66 public boolean isWritten(int blockNumber); setWritten(int blockNumber)67 public void setWritten(int blockNumber); 68 69 // a piece is Checking if a hash check has been setup and the hash check hasn't finalized the result yet 70 // this flag is asynch, so be careful, and it's also transitory (comapared to most of the others being kinda sticky) 71 setChecking()72 public void setChecking(); isChecking()73 public boolean isChecking(); 74 isNeedsCheck()75 public boolean isNeedsCheck(); 76 spansFiles()77 public boolean spansFiles(); 78 calcDone()79 public boolean calcDone(); 80 /** @return true when the hash check has passed and the DiskManager has asyncronously updated the Done status. 81 * There is nothing further to be done regarding downloading for pieces that are Done. 82 */ isDone()83 public boolean isDone(); setDone(boolean b)84 public void setDone(boolean b); 85 86 /** 87 * @return true if a piece is Needed and not Done 88 */ isInteresting()89 public boolean isInteresting(); 90 91 /** This must not be used to qualify pieces in End Game Mode. 92 * @return true if a piece is Needed but is not fully; Requested, Downloaded, Written, Checking, or Done. 93 */ isDownloadable()94 public boolean isDownloadable(); setDownloadable()95 public void setDownloadable(); 96 97 /** 98 * returns true if all the files that the piece spans are skipped 99 * @return 100 */ isSkipped()101 public boolean isSkipped(); 102 reDownloadBlock(int blockNumber)103 public void reDownloadBlock(int blockNumber); reset()104 public void reset(); 105 106 public String getString()107 getString(); 108 } 109