本文整理匯總了Java中sun.nio.ch.DirectBuffer.attachment方法的典型用法代碼示例。如果您正苦於以下問題:Java DirectBuffer.attachment方法的具體用法?Java DirectBuffer.attachment怎麽用?Java DirectBuffer.attachment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sun.nio.ch.DirectBuffer
的用法示例。
在下文中一共展示了DirectBuffer.attachment方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: recycle
import sun.nio.ch.DirectBuffer; //導入方法依賴的package包/類
public void recycle(ByteBuffer theBuf) {
if(!(theBuf instanceof DirectBuffer)){
theBuf.clear();
return;
}
final long size = theBuf.capacity();
boolean recycled = false;
DirectBuffer thisNavBuf = (DirectBuffer) theBuf;
int chunkCount = theBuf.capacity() / chunkSize;
DirectBuffer parentBuf = (DirectBuffer) thisNavBuf.attachment();
int startChunk = (int) ((thisNavBuf.address() - parentBuf.address()) / this.chunkSize);
for (int i = 0; i < allPages.length; i++) {
if ((recycled = allPages[i].recycleBuffer((ByteBuffer) parentBuf, startChunk, chunkCount) == true)) {
break;
}
}
final long threadId = Thread.currentThread().getId();
if (memoryUsage.containsKey(threadId)){
memoryUsage.put(threadId,memoryUsage.get(threadId)-size);
}
if (recycled == false) {
LOGGER.warn("warning ,not recycled buffer " + theBuf);
}
}
示例2: invokeCleaner
import sun.nio.ch.DirectBuffer; //導入方法依賴的package包/類
/**
* Invokes the given direct byte buffer's cleaner, if any.
*
* @param directBuffer a direct byte buffer
* @throws NullPointerException if {@code directBuffer} is null
* @throws IllegalArgumentException if {@code directBuffer} is non-direct,
* or is a {@link java.nio.Buffer#slice slice}, or is a
* {@link java.nio.Buffer#duplicate duplicate}
* @since 9
*/
public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
if (!directBuffer.isDirect())
throw new IllegalArgumentException("buffer is non-direct");
DirectBuffer db = (DirectBuffer)directBuffer;
if (db.attachment() != null)
throw new IllegalArgumentException("duplicate or slice");
Cleaner cleaner = db.cleaner();
if (cleaner != null) {
cleaner.clean();
}
}
示例3: recycle
import sun.nio.ch.DirectBuffer; //導入方法依賴的package包/類
@Override
public void recycle(ByteBuffer theBuf) {
if(theBuf !=null && (!(theBuf instanceof DirectBuffer) )){
theBuf.clear();
return;
}
final long size = theBuf.capacity();
boolean recycled = false;
DirectBuffer thisNavBuf = (DirectBuffer) theBuf;
int chunkCount = theBuf.capacity() / chunkSize;
DirectBuffer parentBuf = (DirectBuffer) thisNavBuf.attachment();
int startChunk = (int) ((thisNavBuf.address() - parentBuf.address()) / chunkSize);
for (int i = 0; i < allPages.length; i++) {
if ((recycled = allPages[i].recycleBuffer((ByteBuffer) parentBuf, startChunk,chunkCount) == true)) {
break;
}
}
final long threadId = Thread.currentThread().getId();
if (memoryUsage.containsKey(threadId)) {
memoryUsage.put(threadId, memoryUsage.get(threadId) - size);
}
if (recycled == false) {
LOGGER.warn("warning , not recycled buffer " + theBuf);
}
sharedOptsCount++;
}
示例4: recycle
import sun.nio.ch.DirectBuffer; //導入方法依賴的package包/類
public void recycle(ByteBuffer theBuf) {
if (!(theBuf instanceof DirectBuffer)) {
theBuf.clear();
return;
}
final long size = theBuf.capacity();
boolean recycled = false;
DirectBuffer thisNavBuf = (DirectBuffer) theBuf;
int chunkCount = theBuf.capacity() / chunkSize;
DirectBuffer parentBuf = (DirectBuffer) thisNavBuf.attachment();
int startChunk = (int) ((thisNavBuf.address() - parentBuf.address()) / this.chunkSize);
for (ByteBufferPage allPage : allPages) {
if ((recycled = allPage.recycleBuffer((ByteBuffer) parentBuf, startChunk, chunkCount))) {
break;
}
}
final long threadId = Thread.currentThread().getId();
if (memoryUsage.containsKey(threadId)) {
memoryUsage.put(threadId, memoryUsage.get(threadId) - size);
}
if (!recycled) {
LOGGER.info("warning ,not recycled buffer " + theBuf);
}
}