View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
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   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.azureus;
21  
22  import org.gudy.azureus2.core3.peer.PEPeerManager;
23  import org.gudy.azureus2.core3.peer.PEPiece;
24  import org.gudy.azureus2.plugins.peers.PeerManager;
25  import org.xnap.transfer.Segment;
26  
27  /***
28   * <p>The end of the segment can change through a split.
29   */
30  public class AzureusSegment implements Segment {
31  
32  	//--- Constant(s) ---
33  
34  	/***
35  	 * The minimun size for a single segment.
36  	 */
37  	public static final long MIN_SEGEMENT_SIZE = 100 * 1024;
38  
39  	//--- Data Field(s) ---
40  
41  	private AzureusDownloadContainer parent;
42  	private PEPiece piece;
43  	
44      //--- Constructor(s) ---
45  
46      public AzureusSegment(AzureusDownloadContainer parent, PEPiece piece) 
47      {
48      	this.parent = parent;
49      	this.piece = piece;
50  	}
51  
52  	public int getAvailability()
53  	{
54  		return 128;
55  	}
56  
57  	/***
58  	 *  @see org.xnap.transfer.Segment#getEnd()
59  	 */
60  	public long getEnd() 
61  	{
62  		return piece.getLength();
63  	}
64  
65  	/***
66  	 *  @see org.xnap.transfer.Segment#getStart()
67  	 */
68  	public long getStart() 
69  	{
70  		return piece.getPieceNumber() * PEPeerManager.BLOCK_SIZE;
71  	}
72  
73  	/***
74  	 *  @see org.xnap.transfer.Segment#getTotal()
75  	 */
76  	public long getTotal() 
77  	{
78  		return parent.getFilesize();
79  	}
80  
81  	/***
82  	 *  @see org.xnap.transfer.Segment#getTransferred()
83  	 */
84  	public long getTransferred() 
85  	{
86  		return piece.getCompleted() * PEPeerManager.BLOCK_SIZE;
87  	}
88  
89      //--- Methods ---
90  
91  }