Package com.biglybt.core.util
Class DirectByteBuffer
- java.lang.Object
-
- com.biglybt.core.util.DirectByteBuffer
-
- Direct Known Subclasses:
DirectByteBufferPoolReal.sliceDBB
,ReferenceCountedDirectByteBuffer
public class DirectByteBuffer extends java.lang.Object
Virtual direct byte buffer given out and tracker by the buffer pool.
-
-
Field Summary
Fields Modifier and Type Field Description static byte
AL_BT_PIECE
static byte
AL_CACHE_READ
static byte
AL_CACHE_WRITE
static java.lang.String[]
AL_DESCS
static byte
AL_DM_CHECK
static byte
AL_DM_READ
static byte
AL_DM_ZERO
static byte
AL_EXTERNAL
static byte
AL_FILE
static byte
AL_MSG
static byte
AL_MSG_AZ_HAND
static byte
AL_MSG_AZ_HEADER
static byte
AL_MSG_AZ_METADATA
static byte
AL_MSG_AZ_PAYLOAD
static byte
AL_MSG_AZ_PEX
static byte
AL_MSG_BT_ALLOWED_FAST
static byte
AL_MSG_BT_CANCEL
static byte
AL_MSG_BT_DHT_PORT
static byte
AL_MSG_BT_HAND
static byte
AL_MSG_BT_HASH_REJECT
static byte
AL_MSG_BT_HASH_REQUEST
static byte
AL_MSG_BT_HASHES
static byte
AL_MSG_BT_HAVE
static byte
AL_MSG_BT_HEADER
static byte
AL_MSG_BT_KEEPALIVE
static byte
AL_MSG_BT_PAYLOAD
static byte
AL_MSG_BT_PIECE
static byte
AL_MSG_BT_REJECT_REQUEST
static byte
AL_MSG_BT_REQUEST
static byte
AL_MSG_BT_SUGGEST_PIECE
static byte
AL_MSG_LT_EXT_MESSAGE
static byte
AL_MSG_LT_HANDSHAKE
static byte
AL_MSG_UT_METADATA
static byte
AL_MSG_UT_PEX
static byte
AL_MSG_UT_UPLOAD_ONLY
static byte
AL_NET_CRYPT
static byte
AL_NONE
static byte
AL_OTHER
static byte
AL_PROXY_RELAY
static byte
AL_PT_LENGTH
static byte
AL_PT_READ
private byte
allocator
private java.nio.ByteBuffer
buffer
static byte
FL_CONTAINS_TRANSIENT_DATA
static byte
FL_NONE
private byte
flags
static byte
OP_CAPACITY
static byte
OP_CLEAR
static java.lang.String[]
OP_DESCS
static byte
OP_FLIP
static byte
OP_GET
static byte
OP_GET_BYTEARRAY
static byte
OP_GET_INT
static byte
OP_GETBUFFER
static byte
OP_GETINT
static byte
OP_GETINT_INT
static byte
OP_GETSHORT
static byte
OP_HASREMAINING
static byte
OP_LIMIT
static byte
OP_LIMIT_INT
static byte
OP_POSITION
static byte
OP_POSITION_INT
static byte
OP_PUT_BB
static byte
OP_PUT_BYTE
static byte
OP_PUT_BYTEARRAY
static byte
OP_PUT_DBB
static byte
OP_PUTINT
static byte
OP_PUTSHORT
static byte
OP_READ_FC
static byte
OP_READ_SC
static byte
OP_REMANING
static byte
OP_WRITE_FC
static byte
OP_WRITE_SC
private DirectByteBufferPool
pool
static byte
SS_BT
static byte
SS_CACHE
static java.lang.String[]
SS_DESCS
static byte
SS_DR
static byte
SS_DW
static byte
SS_EXTERNAL
static byte
SS_FILE
static byte
SS_MSG
static byte
SS_NET
static byte
SS_NONE
static byte
SS_OTHER
static byte
SS_PEER
static byte
SS_PROXY
protected static boolean
TRACE
protected static int
TRACE_BUFFER_SIZE
-
Constructor Summary
Constructors Modifier Constructor Description DirectByteBuffer(byte _allocator, java.nio.ByteBuffer _buffer, DirectByteBufferPool _pool)
protected
DirectByteBuffer(DirectByteBuffer basis)
constructor for reference counted versionDirectByteBuffer(java.nio.ByteBuffer _buffer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
capacity(byte subsystem)
void
clear(byte subsystem)
protected void
dumpTrace(java.lang.Throwable e)
void
flip(byte subsystem)
byte
get(byte subsystem)
void
get(byte subsystem, byte[] data)
byte
get(byte subsystem, int x)
protected byte
getAllocator()
java.nio.ByteBuffer
getBuffer(byte subsystem)
protected java.nio.ByteBuffer
getBufferInternal()
boolean
getFlag(byte flag)
int
getInt(byte subsystem)
int
getInt(byte subsystem, int x)
ReferenceCountedDirectByteBuffer
getReferenceCountedBuffer()
short
getShort(byte subsystem)
protected java.lang.String
getTraceString()
boolean
hasBeenReturnedToPool()
boolean
hasRemaining(byte subsystem)
int
limit(byte subsystem)
void
limit(byte subsystem, int l)
int
position(byte subsystem)
void
position(byte subsystem, int l)
void
put(byte subsystem, byte data)
void
put(byte subsystem, byte[] data)
void
put(byte subsystem, byte[] data, int offset, int length)
void
put(byte subsystem, DirectByteBuffer data)
void
put(byte subsystem, java.nio.ByteBuffer data)
void
putInt(byte subsystem, int data)
void
putShort(byte subsystem, short x)
int
read(byte subsystem, java.nio.channels.FileChannel chan)
int
read(byte subsystem, java.nio.channels.SocketChannel chan)
int
remaining(byte subsystem)
void
returnToPool()
void
returnToPoolIfNotFree()
Normally you should know when a buffer is/isn't free and NOT CALL THIS METHOD However, there are some error situations where the existing code doesn't correctly manage things - we know this and don't want spurious logs occuring as per the above normal methodvoid
setFlag(byte flag)
protected void
traceUsage(byte subsystem, byte operation)
int
write(byte subsystem, java.nio.channels.FileChannel chan)
int
write(byte subsystem, java.nio.channels.SocketChannel chan)
-
-
-
Field Detail
-
AL_NONE
public static final byte AL_NONE
- See Also:
- Constant Field Values
-
AL_EXTERNAL
public static final byte AL_EXTERNAL
- See Also:
- Constant Field Values
-
AL_OTHER
public static final byte AL_OTHER
- See Also:
- Constant Field Values
-
AL_PT_READ
public static final byte AL_PT_READ
- See Also:
- Constant Field Values
-
AL_PT_LENGTH
public static final byte AL_PT_LENGTH
- See Also:
- Constant Field Values
-
AL_CACHE_READ
public static final byte AL_CACHE_READ
- See Also:
- Constant Field Values
-
AL_DM_READ
public static final byte AL_DM_READ
- See Also:
- Constant Field Values
-
AL_DM_ZERO
public static final byte AL_DM_ZERO
- See Also:
- Constant Field Values
-
AL_DM_CHECK
public static final byte AL_DM_CHECK
- See Also:
- Constant Field Values
-
AL_BT_PIECE
public static final byte AL_BT_PIECE
- See Also:
- Constant Field Values
-
AL_CACHE_WRITE
public static final byte AL_CACHE_WRITE
- See Also:
- Constant Field Values
-
AL_PROXY_RELAY
public static final byte AL_PROXY_RELAY
- See Also:
- Constant Field Values
-
AL_MSG
public static final byte AL_MSG
- See Also:
- Constant Field Values
-
AL_MSG_AZ_HAND
public static final byte AL_MSG_AZ_HAND
- See Also:
- Constant Field Values
-
AL_MSG_AZ_PEX
public static final byte AL_MSG_AZ_PEX
- See Also:
- Constant Field Values
-
AL_MSG_BT_CANCEL
public static final byte AL_MSG_BT_CANCEL
- See Also:
- Constant Field Values
-
AL_MSG_BT_HAND
public static final byte AL_MSG_BT_HAND
- See Also:
- Constant Field Values
-
AL_MSG_BT_HAVE
public static final byte AL_MSG_BT_HAVE
- See Also:
- Constant Field Values
-
AL_MSG_BT_PIECE
public static final byte AL_MSG_BT_PIECE
- See Also:
- Constant Field Values
-
AL_MSG_BT_REQUEST
public static final byte AL_MSG_BT_REQUEST
- See Also:
- Constant Field Values
-
AL_MSG_BT_KEEPALIVE
public static final byte AL_MSG_BT_KEEPALIVE
- See Also:
- Constant Field Values
-
AL_MSG_BT_HEADER
public static final byte AL_MSG_BT_HEADER
- See Also:
- Constant Field Values
-
AL_MSG_AZ_HEADER
public static final byte AL_MSG_AZ_HEADER
- See Also:
- Constant Field Values
-
AL_MSG_BT_PAYLOAD
public static final byte AL_MSG_BT_PAYLOAD
- See Also:
- Constant Field Values
-
AL_MSG_AZ_PAYLOAD
public static final byte AL_MSG_AZ_PAYLOAD
- See Also:
- Constant Field Values
-
AL_FILE
public static final byte AL_FILE
- See Also:
- Constant Field Values
-
AL_NET_CRYPT
public static final byte AL_NET_CRYPT
- See Also:
- Constant Field Values
-
AL_MSG_LT_EXT_MESSAGE
public static final byte AL_MSG_LT_EXT_MESSAGE
- See Also:
- Constant Field Values
-
AL_MSG_LT_HANDSHAKE
public static final byte AL_MSG_LT_HANDSHAKE
- See Also:
- Constant Field Values
-
AL_MSG_UT_PEX
public static final byte AL_MSG_UT_PEX
- See Also:
- Constant Field Values
-
AL_MSG_BT_DHT_PORT
public static final byte AL_MSG_BT_DHT_PORT
- See Also:
- Constant Field Values
-
AL_MSG_BT_REJECT_REQUEST
public static final byte AL_MSG_BT_REJECT_REQUEST
- See Also:
- Constant Field Values
-
AL_MSG_BT_SUGGEST_PIECE
public static final byte AL_MSG_BT_SUGGEST_PIECE
- See Also:
- Constant Field Values
-
AL_MSG_BT_ALLOWED_FAST
public static final byte AL_MSG_BT_ALLOWED_FAST
- See Also:
- Constant Field Values
-
AL_MSG_UT_METADATA
public static final byte AL_MSG_UT_METADATA
- See Also:
- Constant Field Values
-
AL_MSG_AZ_METADATA
public static final byte AL_MSG_AZ_METADATA
- See Also:
- Constant Field Values
-
AL_MSG_UT_UPLOAD_ONLY
public static final byte AL_MSG_UT_UPLOAD_ONLY
- See Also:
- Constant Field Values
-
AL_MSG_BT_HASH_REQUEST
public static final byte AL_MSG_BT_HASH_REQUEST
- See Also:
- Constant Field Values
-
AL_MSG_BT_HASHES
public static final byte AL_MSG_BT_HASHES
- See Also:
- Constant Field Values
-
AL_MSG_BT_HASH_REJECT
public static final byte AL_MSG_BT_HASH_REJECT
- See Also:
- Constant Field Values
-
AL_DESCS
public static final java.lang.String[] AL_DESCS
-
SS_NONE
public static final byte SS_NONE
- See Also:
- Constant Field Values
-
SS_EXTERNAL
public static final byte SS_EXTERNAL
- See Also:
- Constant Field Values
-
SS_OTHER
public static final byte SS_OTHER
- See Also:
- Constant Field Values
-
SS_CACHE
public static final byte SS_CACHE
- See Also:
- Constant Field Values
-
SS_FILE
public static final byte SS_FILE
- See Also:
- Constant Field Values
-
SS_NET
public static final byte SS_NET
- See Also:
- Constant Field Values
-
SS_BT
public static final byte SS_BT
- See Also:
- Constant Field Values
-
SS_DR
public static final byte SS_DR
- See Also:
- Constant Field Values
-
SS_DW
public static final byte SS_DW
- See Also:
- Constant Field Values
-
SS_PEER
public static final byte SS_PEER
- See Also:
- Constant Field Values
-
SS_PROXY
public static final byte SS_PROXY
- See Also:
- Constant Field Values
-
SS_MSG
public static final byte SS_MSG
- See Also:
- Constant Field Values
-
SS_DESCS
public static final java.lang.String[] SS_DESCS
-
OP_LIMIT
public static final byte OP_LIMIT
- See Also:
- Constant Field Values
-
OP_LIMIT_INT
public static final byte OP_LIMIT_INT
- See Also:
- Constant Field Values
-
OP_POSITION
public static final byte OP_POSITION
- See Also:
- Constant Field Values
-
OP_POSITION_INT
public static final byte OP_POSITION_INT
- See Also:
- Constant Field Values
-
OP_CLEAR
public static final byte OP_CLEAR
- See Also:
- Constant Field Values
-
OP_FLIP
public static final byte OP_FLIP
- See Also:
- Constant Field Values
-
OP_REMANING
public static final byte OP_REMANING
- See Also:
- Constant Field Values
-
OP_CAPACITY
public static final byte OP_CAPACITY
- See Also:
- Constant Field Values
-
OP_PUT_BYTEARRAY
public static final byte OP_PUT_BYTEARRAY
- See Also:
- Constant Field Values
-
OP_PUT_DBB
public static final byte OP_PUT_DBB
- See Also:
- Constant Field Values
-
OP_PUT_BB
public static final byte OP_PUT_BB
- See Also:
- Constant Field Values
-
OP_PUTINT
public static final byte OP_PUTINT
- See Also:
- Constant Field Values
-
OP_PUT_BYTE
public static final byte OP_PUT_BYTE
- See Also:
- Constant Field Values
-
OP_GET
public static final byte OP_GET
- See Also:
- Constant Field Values
-
OP_GET_INT
public static final byte OP_GET_INT
- See Also:
- Constant Field Values
-
OP_GET_BYTEARRAY
public static final byte OP_GET_BYTEARRAY
- See Also:
- Constant Field Values
-
OP_GETINT
public static final byte OP_GETINT
- See Also:
- Constant Field Values
-
OP_GETINT_INT
public static final byte OP_GETINT_INT
- See Also:
- Constant Field Values
-
OP_HASREMAINING
public static final byte OP_HASREMAINING
- See Also:
- Constant Field Values
-
OP_READ_FC
public static final byte OP_READ_FC
- See Also:
- Constant Field Values
-
OP_WRITE_FC
public static final byte OP_WRITE_FC
- See Also:
- Constant Field Values
-
OP_READ_SC
public static final byte OP_READ_SC
- See Also:
- Constant Field Values
-
OP_WRITE_SC
public static final byte OP_WRITE_SC
- See Also:
- Constant Field Values
-
OP_GETBUFFER
public static final byte OP_GETBUFFER
- See Also:
- Constant Field Values
-
OP_GETSHORT
public static final byte OP_GETSHORT
- See Also:
- Constant Field Values
-
OP_PUTSHORT
public static final byte OP_PUTSHORT
- See Also:
- Constant Field Values
-
OP_DESCS
public static final java.lang.String[] OP_DESCS
-
FL_NONE
public static final byte FL_NONE
- See Also:
- Constant Field Values
-
FL_CONTAINS_TRANSIENT_DATA
public static final byte FL_CONTAINS_TRANSIENT_DATA
- See Also:
- Constant Field Values
-
TRACE
protected static final boolean TRACE
- See Also:
- Constant Field Values
-
TRACE_BUFFER_SIZE
protected static final int TRACE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
buffer
private java.nio.ByteBuffer buffer
-
pool
private DirectByteBufferPool pool
-
allocator
private byte allocator
-
flags
private byte flags
-
-
Constructor Detail
-
DirectByteBuffer
public DirectByteBuffer(java.nio.ByteBuffer _buffer)
-
DirectByteBuffer
public DirectByteBuffer(byte _allocator, java.nio.ByteBuffer _buffer, DirectByteBufferPool _pool)
-
DirectByteBuffer
protected DirectByteBuffer(DirectByteBuffer basis)
constructor for reference counted version- Parameters:
basis
-
-
-
Method Detail
-
getReferenceCountedBuffer
public ReferenceCountedDirectByteBuffer getReferenceCountedBuffer()
-
setFlag
public void setFlag(byte flag)
-
getFlag
public boolean getFlag(byte flag)
-
traceUsage
protected void traceUsage(byte subsystem, byte operation)
-
getTraceString
protected java.lang.String getTraceString()
-
dumpTrace
protected void dumpTrace(java.lang.Throwable e)
-
getBufferInternal
protected java.nio.ByteBuffer getBufferInternal()
-
getAllocator
protected byte getAllocator()
-
limit
public int limit(byte subsystem)
-
limit
public void limit(byte subsystem, int l)
-
position
public int position(byte subsystem)
-
position
public void position(byte subsystem, int l)
-
clear
public void clear(byte subsystem)
-
flip
public void flip(byte subsystem)
-
remaining
public int remaining(byte subsystem)
-
capacity
public int capacity(byte subsystem)
-
put
public void put(byte subsystem, byte[] data)
-
put
public void put(byte subsystem, byte[] data, int offset, int length)
-
put
public void put(byte subsystem, DirectByteBuffer data)
-
put
public void put(byte subsystem, java.nio.ByteBuffer data)
-
put
public void put(byte subsystem, byte data)
-
putShort
public void putShort(byte subsystem, short x)
-
putInt
public void putInt(byte subsystem, int data)
-
get
public byte get(byte subsystem)
-
get
public byte get(byte subsystem, int x)
-
get
public void get(byte subsystem, byte[] data)
-
getShort
public short getShort(byte subsystem)
-
getInt
public int getInt(byte subsystem)
-
getInt
public int getInt(byte subsystem, int x)
-
hasRemaining
public boolean hasRemaining(byte subsystem)
-
read
public int read(byte subsystem, java.nio.channels.FileChannel chan) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public int write(byte subsystem, java.nio.channels.FileChannel chan) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public int read(byte subsystem, java.nio.channels.SocketChannel chan) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public int write(byte subsystem, java.nio.channels.SocketChannel chan) throws java.io.IOException
- Throws:
java.io.IOException
-
getBuffer
public java.nio.ByteBuffer getBuffer(byte subsystem)
-
returnToPool
public void returnToPool()
-
hasBeenReturnedToPool
public boolean hasBeenReturnedToPool()
-
returnToPoolIfNotFree
public void returnToPoolIfNotFree()
Normally you should know when a buffer is/isn't free and NOT CALL THIS METHOD However, there are some error situations where the existing code doesn't correctly manage things - we know this and don't want spurious logs occuring as per the above normal method
-
-