Sync with L2jServer HighFive Mar 1st 2015.

This commit is contained in:
mobius
2015-03-01 22:48:14 +00:00
parent f14af24b41
commit 6fa0ed56e3
116 changed files with 971 additions and 676 deletions

View File

@ -28,12 +28,13 @@ import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* @author KenM<BR>
* Parts of design based on networkcore from WoodenGil
* Parts of design based on network core from WoodenGil
* @param <T>
* @author KenM, Zoey76
*/
public final class SelectorThread<T extends MMOClient<?>> extends Thread
{
@ -62,7 +63,7 @@ public final class SelectorThread<T extends MMOClient<?>> extends Thread
// String Buffer
private final NioNetStringBuffer STRING_BUFFER;
// ByteBuffers General Purpose Pool
private final LinkedList<ByteBuffer> _bufferPool;
private final Queue<ByteBuffer> _bufferPool;
// Pending Close
private final NioNetStackList<MMOConnection<T>> _pendingClose;
@ -86,11 +87,11 @@ public final class SelectorThread<T extends MMOClient<?>> extends Thread
STRING_BUFFER = new NioNetStringBuffer(64 * 1024);
_pendingClose = new NioNetStackList<>();
_bufferPool = new LinkedList<>();
_bufferPool = new ConcurrentLinkedQueue<>();
for (int i = 0; i < HELPER_BUFFER_COUNT; i++)
{
_bufferPool.addLast(ByteBuffer.wrap(new byte[HELPER_BUFFER_SIZE]).order(BYTE_ORDER));
_bufferPool.add(ByteBuffer.wrap(new byte[HELPER_BUFFER_SIZE]).order(BYTE_ORDER));
}
_acceptFilter = acceptFilter;
@ -126,15 +127,15 @@ public final class SelectorThread<T extends MMOClient<?>> extends Thread
return ByteBuffer.wrap(new byte[HELPER_BUFFER_SIZE]).order(BYTE_ORDER);
}
return _bufferPool.removeFirst();
return _bufferPool.remove();
}
final void recycleBuffer(final ByteBuffer buf)
final void recycleBuffer(ByteBuffer buf)
{
if (_bufferPool.size() < HELPER_BUFFER_COUNT)
{
buf.clear();
_bufferPool.addLast(buf);
_bufferPool.add(buf);
}
}