FileDocCategorySizeDatePackage
ReferenceCountedDirectByteBuffer.javaAPI DocAzureus 3.0.3.43022Tue Jan 30 18:52:48 GMT 2007org.gudy.azureus2.core3.util

ReferenceCountedDirectByteBuffer

public class ReferenceCountedDirectByteBuffer extends DirectByteBuffer

Fields Summary
private DirectByteBuffer
basis
private int
ref_count
Constructors Summary
protected ReferenceCountedDirectByteBuffer(DirectByteBuffer _basis)

	
	
	
			 
	
		this( _basis.getBufferInternal());
		
		basis	= _basis;
	
protected ReferenceCountedDirectByteBuffer(ByteBuffer _buffer)

		super( _buffer );
	
Methods Summary
public voiddecrementReferenceCount()

		synchronized( this ){
				
			ref_count--;
			
			// System.out.println( "" + this + ": rc=" + ref_count );
			
			if ( ref_count == 0 ){
				
				basis.returnToPool();
			}
		}	
	
public org.gudy.azureus2.core3.util.ReferenceCountedDirectByteBufferduplicate(int offset, int length)

		ByteBuffer	duplicate = getBufferInternal().duplicate();
		
		duplicate.position( duplicate.position() + offset );
		
		duplicate.limit(  duplicate.position() + length );
		
		ReferenceCountedDirectByteBuffer res = new ReferenceCountedDirectByteBufferDuplicate( duplicate );
		
		return( res );
	
public intgetReferenceCount()

		return( ref_count );
	
public voidincrementReferenceCount()

		synchronized( this ){
			
			ref_count++;
			
			// System.out.println( "" + this + ": rc=" + ref_count );
		}
	
public voidreturnToPool()

		decrementReferenceCount();