當前位置: 首頁>>代碼示例>>Java>>正文


Java DirectBuffer.attachment方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:28,代碼來源:DirectByteBufferPool.java

示例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();
    }
}
 
開發者ID:stone100,項目名稱:source-code,代碼行數:24,代碼來源:Unsafe.java

示例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++;	
  }
 
開發者ID:variflight,項目名稱:feeyo-redisproxy,代碼行數:32,代碼來源:ByteBufferPagePool.java

示例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);
    }
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:28,代碼來源:DirectByteBufferPool.java


注:本文中的sun.nio.ch.DirectBuffer.attachment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。