当前位置: 首页>>代码示例>>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;未经允许,请勿转载。