|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.glassfish.grizzly.memory.AbstractMemoryManager<HeapBuffer>
org.glassfish.grizzly.memory.HeapMemoryManager
public class HeapMemoryManager
A WrapperAware
MemoryManager
implementation for
managing HeapBuffer
instances.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.glassfish.grizzly.memory.AbstractMemoryManager |
---|
AbstractMemoryManager.TrimAware |
Field Summary |
---|
Fields inherited from class org.glassfish.grizzly.memory.AbstractMemoryManager |
---|
DEFAULT_MAX_BUFFER_SIZE, maxBufferSize, monitoringConfig |
Fields inherited from interface org.glassfish.grizzly.memory.MemoryManager |
---|
DEFAULT_MEMORY_MANAGER |
Constructor Summary | |
---|---|
HeapMemoryManager()
|
|
HeapMemoryManager(int maxBufferSize)
|
Method Summary | |
---|---|
HeapBuffer |
allocate(int size)
Allocated Buffer of the required size. |
HeapBuffer |
allocateAtLeast(int size)
Allocated Buffer at least of the provided size. |
protected HeapBuffer |
allocateHeapBuffer(int size)
|
protected HeapBuffer |
allocateHeapBufferAtLeast(int size)
|
protected JmxObject |
createJmxManagementObject()
|
ThreadLocalPool |
createThreadLocalPool()
|
JmxMonitoringConfig<MemoryProbe> |
getMonitoringConfig()
Return the object associated JmxMonitoringConfig . |
HeapBuffer |
reallocate(HeapBuffer oldBuffer,
int newSize)
Reallocate Buffer to a required size. |
protected HeapBuffer |
reallocateHeapBuffer(HeapBuffer oldHeapBuffer,
int newSize)
|
void |
release(HeapBuffer buffer)
Release Buffer . |
protected void |
releaseHeapBuffer(HeapBuffer heapBuffer)
|
boolean |
willAllocateDirect(int size)
Return true if next MemoryManager.allocate(int) or MemoryManager.allocateAtLeast(int) call,
made in the current thread for the given memory size, going to return a Buffer based
on direct ByteBuffer , or false otherwise. |
HeapBuffer |
wrap(byte[] data)
Returns Buffer , which wraps the byte array. |
HeapBuffer |
wrap(byte[] data,
int offset,
int length)
Returns Buffer , which wraps the part of byte array with
specific offset and length. |
Buffer |
wrap(ByteBuffer byteBuffer)
Returns Buffer , which wraps the ByteBuffer . |
HeapBuffer |
wrap(String s)
Returns Buffer , which wraps the String . |
HeapBuffer |
wrap(String s,
Charset charset)
Returns Buffer , which wraps the String with the specific
Charset . |
Methods inherited from class org.glassfish.grizzly.memory.AbstractMemoryManager |
---|
allocateFromPool, getMaxBufferSize, getReadyThreadBufferSize, getThreadLocalPool |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HeapMemoryManager()
public HeapMemoryManager(int maxBufferSize)
Method Detail |
---|
public HeapBuffer allocate(int size)
Buffer
of the required size.
allocate
in interface MemoryManager<HeapBuffer>
size
- Buffer
size to be allocated.
Buffer
.public HeapBuffer allocateAtLeast(int size)
Buffer
at least of the provided size.
This could be useful for usecases like Socket.read(...), where
we're not sure how many bytes are available, but want to read as
much as possible.
allocateAtLeast
in interface MemoryManager<HeapBuffer>
size
- the min Buffer
size to be allocated.
Buffer
.public HeapBuffer reallocate(HeapBuffer oldBuffer, int newSize)
Buffer
to a required size.
Implementation may choose the way, how reallocation could be done, either
by allocating new Buffer
of required size and copying old
Buffer
content there, or perform more complex logic related to
memory pooling etc.
reallocate
in interface MemoryManager<HeapBuffer>
oldBuffer
- old Buffer
to be reallocated.newSize
- new Buffer
required size.
Buffer
.public void release(HeapBuffer buffer)
Buffer
.
Implementation may ignore releasing and let JVM Garbage collector to take
care about the Buffer
, or return Buffer
to pool, in case
of more complex MemoryManager implementation.
release
in interface MemoryManager<HeapBuffer>
buffer
- Buffer
to be released.public boolean willAllocateDirect(int size)
MemoryManager.allocate(int)
or MemoryManager.allocateAtLeast(int)
call,
made in the current thread for the given memory size, going to return a Buffer
based
on direct ByteBuffer
, or false otherwise.
willAllocateDirect
in interface MemoryManager<HeapBuffer>
public JmxMonitoringConfig<MemoryProbe> getMonitoringConfig()
JmxMonitoringConfig
.
getMonitoringConfig
in interface JmxMonitoringAware<MemoryProbe>
getMonitoringConfig
in interface MonitoringAware<MemoryProbe>
JmxMonitoringConfig
.public ThreadLocalPool createThreadLocalPool()
createThreadLocalPool
in interface ThreadLocalPoolProvider
ThreadLocalPool
implementation. This method
must return a new ThreadLocalPool
instance per invocation.protected JmxObject createJmxManagementObject()
createJmxManagementObject
in class AbstractMemoryManager<HeapBuffer>
JmxObject
used to register/deregister with the
JMX runtime.public HeapBuffer wrap(byte[] data)
Buffer
, which wraps the byte array.
wrap
in interface WrapperAware
data
- byte array to wrap
Buffer
wrapper on top of passed byte array.public HeapBuffer wrap(byte[] data, int offset, int length)
Buffer
, which wraps the part of byte array with
specific offset and length.
wrap
in interface WrapperAware
data
- byte array to wrapoffset
- byte buffer offsetlength
- byte buffer length
Buffer
wrapper on top of passed byte array.public HeapBuffer wrap(String s)
Buffer
, which wraps the String
.
wrap
in interface WrapperAware
s
- String
Buffer
wrapper on top of passed String
.public HeapBuffer wrap(String s, Charset charset)
Buffer
, which wraps the String
with the specific
Charset
.
wrap
in interface WrapperAware
s
- String
charset
- Charset
, which will be used, when converting
String
to byte array.
Buffer
wrapper on top of passed String
.public Buffer wrap(ByteBuffer byteBuffer)
Buffer
, which wraps the ByteBuffer
.
wrap
in interface WrapperAware
byteBuffer
- ByteBuffer
to wrap
Buffer
wrapper on top of passed ByteBuffer
.protected HeapBuffer allocateHeapBuffer(int size)
protected HeapBuffer allocateHeapBufferAtLeast(int size)
protected HeapBuffer reallocateHeapBuffer(HeapBuffer oldHeapBuffer, int newSize)
protected final void releaseHeapBuffer(HeapBuffer heapBuffer)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |