Skip to content

Commit

Permalink
added Mnemonic infra. as an alternative backed allocation mechanism, …
Browse files Browse the repository at this point in the history
…note that move allocator services to the service-dist folder as the properties indicated in pom.xml.
  • Loading branch information
Wang, Gang(Gary) committed Oct 26, 2017
1 parent 8148b6d commit c03c4d2
Show file tree
Hide file tree
Showing 11 changed files with 3,637 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ cpp/.idea/
python/.eggs/
.vscode
.idea/

2 changes: 2 additions & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
*.dat
?/

4 changes: 4 additions & 0 deletions java/memory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.mnemonic</groupId>
<artifactId>mnemonic-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.buffer;

import io.netty.util.internal.PlatformDependent;

import org.apache.mnemonic.CommonAllocator;

/**
* Simplistic {@link ByteBufAllocator} implementation that does not pool anything.
*/
public final class MnemonicUnpooledByteBufAllocator<A extends CommonAllocator<A>> extends AbstractByteBufAllocator {

private A mcalloc;

/**
* Default instance
*/
// public static final UnpooledByteBufAllocator DEFAULT =
// new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred());

/**
* Create a new instance
*
* @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
* a heap buffer
*/
public MnemonicUnpooledByteBufAllocator(boolean preferDirect, A mcallocator) {
super(preferDirect);
this.mcalloc = mcallocator;
}

public A getAllocator() {
return this.mcalloc;
}

@Override
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
return new UnpooledHeapByteBuf(this, initialCapacity, maxCapacity);
}

@Override
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
assert null != this.mcalloc;
ByteBuf buf;
if (PlatformDependent.hasUnsafe()) {
buf = new MnemonicUnpooledUnsafeDirectByteBuf<A>(this, initialCapacity, maxCapacity);
} else {
buf = new MnemonicUnpooledDirectByteBuf<A>(this, initialCapacity, maxCapacity);
}

return toLeakAwareBuffer(buf);
}

@Override
public boolean isDirectBufferPooled() {
return false;
}
}
Loading

0 comments on commit c03c4d2

Please sign in to comment.