Search in sources :

Example 1 with RingSequence

use of com.firenio.concurrent.RingSequence in project baseio by generallycloud.

the class NioEventLoopGroup method doStart.

@Override
protected void doStart() throws Exception {
    this.channelIds = new RingSequence(0x1000, Integer.MAX_VALUE);
    if (isEnableMemoryPool() && getAllocatorGroup() == null) {
        if (!Native.EPOLL_AVAILABLE && Unsafe.UNSAFE_BUF_AVAILABLE) {
            throw new IllegalArgumentException("Java(Nio) mode can not use unsafe memory");
        }
        if (memoryCapacity == 0) {
            memoryCapacity = Runtime.getRuntime().maxMemory() / 64;
        }
        int memoryTypeId = preferHeap ? Unsafe.BUF_HEAP : Unsafe.getMemoryTypeId();
        this.memoryCapacity = calcSuitableMemoryCapacity(memoryCapacity);
        this.allocatorGroup = new ByteBufAllocatorGroup(getEventLoopSize(), memoryCapacity, memoryUnit, memoryTypeId);
    }
    Util.start(getAllocatorGroup());
    super.doStart();
}
Also used : ByteBufAllocatorGroup(com.firenio.buffer.ByteBufAllocatorGroup) RingSequence(com.firenio.concurrent.RingSequence)

Example 2 with RingSequence

use of com.firenio.concurrent.RingSequence in project baseio by generallycloud.

the class TestRingSequence method test.

@Test
public void test() {
    RingSequence s = new RingSequence(2, 5);
    for (int i = 0; i < 4; i++) {
        s.next();
    }
    Assert.expectTrue(s.next() == 3);
}
Also used : RingSequence(com.firenio.concurrent.RingSequence) Test(org.junit.Test)

Aggregations

RingSequence (com.firenio.concurrent.RingSequence)2 ByteBufAllocatorGroup (com.firenio.buffer.ByteBufAllocatorGroup)1 Test (org.junit.Test)1