Browse Source

Updated MMOCore Source. Tnx Forsaiken again.

nBd 16 years ago
parent
commit
335a97c677
25 changed files with 664 additions and 2290 deletions
  1. 3 18
      MMOCore/src/org/mmocore/network/AbstractPacket.java
  2. 0 45
      MMOCore/src/org/mmocore/network/HeaderHandler.java
  3. 0 114
      MMOCore/src/org/mmocore/network/HeaderInfo.java
  4. 2 2
      MMOCore/src/org/mmocore/network/IClientFactory.java
  5. 1 1
      MMOCore/src/org/mmocore/network/IMMOExecutor.java
  6. 1 1
      MMOCore/src/org/mmocore/network/IPacketHandler.java
  7. 0 40
      MMOCore/src/org/mmocore/network/ISocket.java
  8. 8 29
      MMOCore/src/org/mmocore/network/MMOClient.java
  9. 93 310
      MMOCore/src/org/mmocore/network/MMOConnection.java
  10. 100 0
      MMOCore/src/org/mmocore/network/NioNetStackList.java
  11. 39 0
      MMOCore/src/org/mmocore/network/NioNetStringBuffer.java
  12. 24 31
      MMOCore/src/org/mmocore/network/ReceivablePacket.java
  13. 16 119
      MMOCore/src/org/mmocore/network/SelectorConfig.java
  14. 346 867
      MMOCore/src/org/mmocore/network/SelectorThread.java
  15. 31 41
      MMOCore/src/org/mmocore/network/SendablePacket.java
  16. 0 48
      MMOCore/src/org/mmocore/network/TCPHeaderHandler.java
  17. 0 79
      MMOCore/src/org/mmocore/network/TCPSocket.java
  18. 0 51
      MMOCore/src/org/mmocore/network/UDPHeaderHandler.java
  19. 0 79
      MMOCore/src/org/mmocore/network/UDPSocket.java
  20. 0 76
      MMOCore/src/org/mmocore/test/testserver/SelectorHelper.java
  21. 0 48
      MMOCore/src/org/mmocore/test/testserver/ServerClient.java
  22. 0 35
      MMOCore/src/org/mmocore/test/testserver/TestRecvPacket.java
  23. 0 42
      MMOCore/src/org/mmocore/test/testserver/TestSendPacket.java
  24. 0 39
      MMOCore/src/org/mmocore/test/testserver/TestServer.java
  25. 0 175
      MMOCore/src/org/mmocore/util/collections/concurrent/SemiConcurrentLinkedList.java

+ 3 - 18
MMOCore/src/org/mmocore/network/AbstractPacket.java

@@ -24,29 +24,14 @@ import java.nio.ByteBuffer;
  * @author KenM
  *
  */
-public abstract class AbstractPacket<T extends MMOClient>
+public abstract class AbstractPacket<T extends MMOClient<?>>
 {
     protected ByteBuffer _buf;
     
-    protected T _client;
+    T _client;
     
-    protected void setClient(T client)
-    {
-        _client = client;
-    }
-    
-    public T getClient()
+    public final T getClient()
     {
         return _client;
     }
-    
-    protected void setByteBuffer(ByteBuffer buf)
-    {
-        _buf = buf;
-    }
-    
-    protected ByteBuffer getByteBuffer()
-    {
-        return _buf;
-    }
 }

+ 0 - 45
MMOCore/src/org/mmocore/network/HeaderHandler.java

@@ -1,45 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-/**
- * @author KenM
- *
- */
-public abstract class HeaderHandler<T extends MMOClient, H extends HeaderHandler<T,H>>
-{
-    private final H _subHeaderHandler;
-    
-    public HeaderHandler(H subHeaderHandler)
-    {
-        _subHeaderHandler = subHeaderHandler;
-    }
-
-    /**
-     * @return the subHeaderHandler
-     */
-    public final H getSubHeaderHandler()
-    {
-        return _subHeaderHandler;
-    }
-    
-    public final boolean isChildHeaderHandler()
-    {
-        return this.getSubHeaderHandler() == null;
-    }
-}

+ 0 - 114
MMOCore/src/org/mmocore/network/HeaderInfo.java

@@ -1,114 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-public final class HeaderInfo<T>
-{
-    private int _headerPending;
-    private int _dataPending;
-    private boolean _multiPacket;
-    private T _client;
-    
-    public HeaderInfo()
-    {
-        
-    }
-    
-    public HeaderInfo<T> set(int headerPending, int dataPending, boolean multiPacket, T client)
-    {
-        this.setHeaderPending(headerPending);
-        this.setDataPending(dataPending);
-        this.setMultiPacket(multiPacket);
-        this.setClient(client);
-        return this;
-    }
-    
-    protected boolean headerFinished()
-    {
-        return getHeaderPending() == 0;
-    }
-    
-    protected boolean packetFinished()
-    {
-        return getDataPending() == 0;
-    }
-    
-    /**
-     * @param dataPending the dataPending to set
-     */
-    private void setDataPending(int dataPending)
-    {
-        _dataPending = dataPending;
-    }
-    
-    /**
-     * @return the dataPending
-     */
-    protected int getDataPending()
-    {
-        return _dataPending;
-    }
-
-    /**
-     * @param headerPending the headerPending to set
-     */
-    private void setHeaderPending(int headerPending)
-    {
-        _headerPending = headerPending;
-    }
-
-    /**
-     * @return the headerPending
-     */
-    protected int getHeaderPending()
-    {
-        return _headerPending;
-    }
-
-    /**
-     * @param client the client to set
-     */
-    protected void setClient(T client)
-    {
-        _client = client;
-    }
-
-    /**
-     * @return the client
-     */
-    protected T getClient()
-    {
-        return _client;
-    }
-
-    /**
-     * @param multiPacket the multiPacket to set
-     */
-    private void setMultiPacket(boolean multiPacket)
-    {
-        _multiPacket = multiPacket;
-    }
-
-    /**
-     * @return the multiPacket
-     */
-    public boolean isMultiPacket()
-    {
-        return _multiPacket;
-    }
-}

+ 2 - 2
MMOCore/src/org/mmocore/network/IClientFactory.java

@@ -21,7 +21,7 @@ package org.mmocore.network;
  * @author KenM
  *
  */
-public interface IClientFactory<T extends MMOClient>
+public interface IClientFactory<T extends MMOClient<?>>
 {
-    public T create(MMOConnection<T> con);
+    public T create(final MMOConnection<T> con);
 }

+ 1 - 1
MMOCore/src/org/mmocore/network/IMMOExecutor.java

@@ -22,7 +22,7 @@ package org.mmocore.network;
  * @author KenM
  *
  */
-public interface IMMOExecutor<T extends MMOClient>
+public interface IMMOExecutor<T extends MMOClient<?>>
 {
     public void execute(ReceivablePacket<T> packet);
 }

+ 1 - 1
MMOCore/src/org/mmocore/network/IPacketHandler.java

@@ -24,7 +24,7 @@ import java.nio.ByteBuffer;
  * @author KenM
  *
  */
-public interface IPacketHandler<T extends MMOClient>
+public interface IPacketHandler<T extends MMOClient<?>>
 {
     public ReceivablePacket<T> handlePacket(ByteBuffer buf, T client);
 }

+ 0 - 40
MMOCore/src/org/mmocore/network/ISocket.java

@@ -1,40 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-
-/**
- * @author KenM
- *
- */
-public interface ISocket
-{
-    public void close() throws IOException;
-    
-    public WritableByteChannel getWritableByteChannel();
-    
-    public ReadableByteChannel getReadableByteChannel();
-    
-    public InetAddress getInetAddress();
-    
-    public int getPort();
-}

+ 8 - 29
MMOCore/src/org/mmocore/network/MMOClient.java

@@ -25,44 +25,23 @@ import java.nio.ByteBuffer;
  */
 public abstract class MMOClient<T extends MMOConnection>
 {
-    private T _connection;
+    private final T _con;
     
-    @SuppressWarnings("unchecked")
-    public MMOClient(T con)
+    public MMOClient(final T con)
     {
-        this.setConnection(con);
-        con.setClient(this);
-    }
-    
-    protected void setConnection(T con)
-    {
-        _connection = con;
+    	_con = con;
     }
     
     public T getConnection()
     {
-        return _connection;
+        return _con;
     }
     
-    public void closeNow()
-    {
-        this.getConnection().closeNow();
-    }
+    public abstract boolean decrypt(final ByteBuffer buf, final int size);
     
-    public void closeLater()
-    {
-        this.getConnection().closeLater();
-    }
+    public abstract boolean encrypt(final ByteBuffer buf, final int size);
     
-    public abstract boolean decrypt(ByteBuffer buf, int size);
+    protected abstract void onDisconnection();
     
-    public abstract boolean encrypt(ByteBuffer buf, int size);
-    
-    protected void onDisconnection()
-    {
-    }
-    
-    protected void onForcedDisconnection()
-    {
-    }
+    protected abstract void onForcedDisconnection();
 }

+ 93 - 310
MMOCore/src/org/mmocore/network/MMOConnection.java

@@ -17,213 +17,137 @@
  */
 package org.mmocore.network;
 
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
 import java.nio.ByteBuffer;
 import java.nio.channels.CancelledKeyException;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.WritableByteChannel;
 
-import javolution.util.FastList;
-
-
 /**
  * @author KenM
  *
  */
-public class MMOConnection<T extends MMOClient>
+public final class MMOConnection<T extends MMOClient<?>>
 {
     private final SelectorThread<T> _selectorThread;
-    private T _client;
     
-    private ISocket _socket;
-    private WritableByteChannel _writableByteChannel;
-    private ReadableByteChannel _readableByteChannel;
+    private final Socket _socket;
+    private final InetAddress _address;
+    private final ReadableByteChannel _readableByteChannel;
+    private final WritableByteChannel _writableByteChannel;
+    private final int _port;
     
-    private FastList<SendablePacket<T>> _sendQueue = new FastList<SendablePacket<T>>();
-    private SelectionKey _selectionKey;
+    private final NioNetStackList<SendablePacket<T>> _sendQueue;
+    private final SelectionKey _selectionKey;
+    private SendablePacket<T> _closePacket;
     
-    private int _readHeaderPending;
     private ByteBuffer _readBuffer;
-    
     private ByteBuffer _primaryWriteBuffer;
     private ByteBuffer _secondaryWriteBuffer;
-    
     private boolean _pendingClose;
+    private T _client;
     
-    public MMOConnection(SelectorThread<T> selectorThread, ISocket socket, SelectionKey key)
+	public MMOConnection(final SelectorThread<T> selectorThread, final Socket socket, final SelectionKey key)
     {
         _selectorThread = selectorThread;
-        this.setSocket(socket);
-        this.setWritableByteChannel(socket.getWritableByteChannel());
-        this.setReadableByteChannel(socket.getReadableByteChannel());
-        this.setSelectionKey(key);
-    }
-    
-    public MMOConnection(T client, SelectorThread<T> selectorThread, ISocket socket, SelectionKey key)
-    {
-        this(selectorThread, socket, key);
-        this.setClient(client);
+        _socket = socket;
+        _address = socket.getInetAddress();
+        _readableByteChannel = socket.getChannel();
+        _writableByteChannel = socket.getChannel();
+        _port = socket.getPort();
+        _selectionKey = key;
+        
+        _sendQueue = new NioNetStackList<SendablePacket<T>>();
     }
     
-    protected void setClient(T client)
+    final void setClient(final T client)
     {
-        _client = client;
+    	_client = client;
     }
     
-    public T getClient()
+    public final T getClient()
     {
         return _client;
     }
     
-    public void sendPacket(SendablePacket<T> sp)
+    public final void sendPacket(final SendablePacket<T> sp)
     {
-        sp.setClient(this.getClient());
-        synchronized (this.getSendQueue())
+        sp._client = _client;
+        
+        synchronized (getSendQueue())
+    	{
+    		if (!_pendingClose)
+    		{
+    			_sendQueue.addLast(sp);
+    		}
+    	}
+        
+        if (!_sendQueue.isEmpty())
         {
-            if (!_pendingClose)
+        	try
             {
-                try
-                {
-                    this.getSelectionKey().interestOps(this.getSelectionKey().interestOps() | SelectionKey.OP_WRITE);
-                    this.getSendQueue().addLast(sp);
-                }
-                catch (CancelledKeyException e)
-                {
-                    // ignore
-                }
+            	_selectionKey.interestOps(_selectionKey.interestOps() | SelectionKey.OP_WRITE);
+            }
+            catch (CancelledKeyException e)
+            {
+                // ignore
             }
         }
     }
     
-    protected SelectorThread<T> getSelectorThread()
-    {
-        return _selectorThread;
-    }
-    
-    protected void setSelectionKey(SelectionKey key)
-    {
-        _selectionKey = key;
-    }
-    
-    protected SelectionKey getSelectionKey()
+    final SelectionKey getSelectionKey()
     {
         return _selectionKey;
     }
     
-    protected void enableReadInterest()
-    {
-        try
-        {
-            this.getSelectionKey().interestOps(this.getSelectionKey().interestOps() | SelectionKey.OP_READ);
-        }
-        catch (CancelledKeyException e)
-        {
-            // ignore
-        }
-    }
-    
-    protected void disableReadInterest()
-    {
-        try
-        {
-            this.getSelectionKey().interestOps(this.getSelectionKey().interestOps() & ~SelectionKey.OP_READ);
-        }
-        catch (CancelledKeyException e)
-        {
-            // ignore
-        }
-    }
-    
-    protected void enableWriteInterest()
+    public final InetAddress getInetAddress()
     {
-        try
-        {
-            this.getSelectionKey().interestOps(this.getSelectionKey().interestOps() | SelectionKey.OP_WRITE);
-        }
-        catch (CancelledKeyException e)
-        {
-            // ignore
-        }
+    	return _address;
     }
     
-    protected void disableWriteInterest()
+    public final int getPort()
     {
-        try
-        {
-            this.getSelectionKey().interestOps(this.getSelectionKey().interestOps() & ~SelectionKey.OP_WRITE);
-        }
-        catch (CancelledKeyException e)
-        {
-            // ignore
-        }
+    	return _port;
     }
     
-    /**
-     * @param socket the socket to set
-     */
-    protected void setSocket(ISocket socket)
+    final void close() throws IOException
     {
-        _socket = socket;
-    }
-
-    /**
-     * @return the socket
-     */
-    public ISocket getSocket()
-    {
-        return _socket;
-    }
-
-    protected void setWritableByteChannel(WritableByteChannel wbc)
-    {
-        _writableByteChannel = wbc;
-    }
-    
-    public WritableByteChannel getWritableChannel()
-    {
-        return _writableByteChannel;
-    }
-    
-    protected void setReadableByteChannel(ReadableByteChannel rbc)
-    {
-        _readableByteChannel = rbc;
+    	_socket.close();
     }
     
-    public ReadableByteChannel getReadableByteChannel()
+    final int read(final ByteBuffer buf) throws IOException
     {
-        return _readableByteChannel;
+    	return _readableByteChannel.read(buf);
     }
     
-    protected FastList<SendablePacket<T>> getSendQueue()
+    final int write(final ByteBuffer buf) throws IOException
     {
-        return _sendQueue;
+    	return _writableByteChannel.write(buf);
     }
     
-    protected void createWriteBuffer(ByteBuffer buf)
+    final void createWriteBuffer(final ByteBuffer buf)
     {
         if (_primaryWriteBuffer == null)
         {
-            //System.err.println("APPENDING FOR NULL");
-            //System.err.flush();
-            _primaryWriteBuffer = this.getSelectorThread().getPooledBuffer();
+            _primaryWriteBuffer = _selectorThread.getPooledBuffer();
             _primaryWriteBuffer.put(buf);
         }
         else
         {
-            //System.err.println("PREPENDING ON EXISTING");
-            //System.err.flush();
-            
-            ByteBuffer temp = this.getSelectorThread().getPooledBuffer();
+            final ByteBuffer temp = _selectorThread.getPooledBuffer();
             temp.put(buf);
             
-            int remaining = temp.remaining();
+            final int remaining = temp.remaining();
             _primaryWriteBuffer.flip();
-            int limit = _primaryWriteBuffer.limit();
+            final int limit = _primaryWriteBuffer.limit();
             
             if (remaining >= _primaryWriteBuffer.remaining())
             {
                 temp.put(_primaryWriteBuffer);
-                this.getSelectorThread().recycleBuffer(_primaryWriteBuffer);
+                _selectorThread.recycleBuffer(_primaryWriteBuffer);
                 _primaryWriteBuffer = temp;
             }
             else
@@ -238,227 +162,86 @@ public class MMOConnection<T extends MMOClient>
         }
     }
     
-    /*
-    protected void appendIntoWriteBuffer(ByteBuffer buf)
-    {
-        // if we already have a buffer
-        if (_secondaryWriteBuffer != null && (_primaryWriteBuffer != null && !_primaryWriteBuffer.hasRemaining()))
-        {
-            _secondaryWriteBuffer.put(buf);
-            
-            if (MMOCore.ASSERTIONS_ENABLED)
-            {
-                // correct state
-                assert _primaryWriteBuffer == null || !_primaryWriteBuffer.hasRemaining();
-                // full write
-                assert !buf.hasRemaining();
-            }
-        }
-        else if (_primaryWriteBuffer != null)
-        {
-            int size = Math.min(buf.limit(), _primaryWriteBuffer.remaining());
-            _primaryWriteBuffer.put(buf.array(), buf.position(), size);
-            buf.position(buf.position() + size);
-            
-            // primary wasnt enough
-            if (buf.hasRemaining())
-            {
-                _secondaryWriteBuffer = this.getSelectorThread().getPooledBuffer();
-                _secondaryWriteBuffer.put(buf);
-            }
-            
-            if (MMOCore.ASSERTIONS_ENABLED)
-            {
-                // full write
-                assert !buf.hasRemaining();
-            }
-        }
-        else
-        {
-            // a single empty buffer should be always enough by design
-            _primaryWriteBuffer = this.getSelectorThread().getPooledBuffer();
-            _primaryWriteBuffer.put(buf);
-            System.err.println("ESCREVI "+_primaryWriteBuffer.position());
-            if (MMOCore.ASSERTIONS_ENABLED)
-            {
-                // full write
-                assert !buf.hasRemaining();
-            }
-        }
-    }*/
-    
-    /*protected void prependIntoPendingWriteBuffer(ByteBuffer buf)
-    {
-        int remaining = buf.remaining();
-        
-        //do we already have some buffer
-        if (_primaryWriteBuffer != null && _primaryWriteBuffer.hasRemaining())
-        {
-            if (remaining == _primaryWriteBuffer.capacity())
-            {
-                if (MMOCore.ASSERTIONS_ENABLED)
-                {
-                    assert _secondaryWriteBuffer == null;
-                }
-                
-                _secondaryWriteBuffer = _primaryWriteBuffer;
-                _primaryWriteBuffer = this.getSelectorThread().getPooledBuffer();
-                _primaryWriteBuffer.put(buf);
-            }
-            else if (remaining < _primaryWriteBuffer.remaining())
-            {
-                
-            }
-        }
-        else
-        {
-            
-        }
-    }*/
-    
-    protected boolean hasPendingWriteBuffer()
+    final boolean hasPendingWriteBuffer()
     {
         return _primaryWriteBuffer != null;
     }
     
-    protected void movePendingWriteBufferTo(ByteBuffer dest)
+    final void movePendingWriteBufferTo(final ByteBuffer dest)
     {
-        //System.err.println("PRI SIZE: "+_primaryWriteBuffer.position());
-        //System.err.flush();
         _primaryWriteBuffer.flip();
         dest.put(_primaryWriteBuffer);
-        this.getSelectorThread().recycleBuffer(_primaryWriteBuffer);
+        _selectorThread.recycleBuffer(_primaryWriteBuffer);
         _primaryWriteBuffer = _secondaryWriteBuffer;
         _secondaryWriteBuffer = null;
     }
     
-    /*protected void finishPrepending(int written)
-    {
-        _primaryWriteBuffer.position(Math.min(written, _primaryWriteBuffer.limit()));
-        // discard only the written bytes
-        _primaryWriteBuffer.compact();
-        
-        if (_secondaryWriteBuffer != null)
-        {
-            _secondaryWriteBuffer.flip();
-            _primaryWriteBuffer.put(_secondaryWriteBuffer);
-            
-            if (!_secondaryWriteBuffer.hasRemaining())
-            {
-                this.getSelectorThread().recycleBuffer(_secondaryWriteBuffer);
-                _secondaryWriteBuffer = null;
-            }
-            else
-            {
-                _secondaryWriteBuffer.compact();
-            }
-        }
-    }*/
-    
-    protected ByteBuffer getWriteBuffer()
-    {
-        ByteBuffer ret = _primaryWriteBuffer;
-        if (_secondaryWriteBuffer != null)
-        {
-            _primaryWriteBuffer = _secondaryWriteBuffer;
-            _secondaryWriteBuffer = null;
-        }
-        return ret;
-    }
-
-    protected void setPendingHeader(int size)
-    {
-        _readHeaderPending = size;
-    }
-    
-    protected int getPendingHeader()
-    {
-        return _readHeaderPending;
-    }
-    
-    protected void setReadBuffer(ByteBuffer buf)
+    final void setReadBuffer(final ByteBuffer buf)
     {
         _readBuffer = buf;
     }
     
-    protected ByteBuffer getReadBuffer()
+    final ByteBuffer getReadBuffer()
     {
         return _readBuffer;
     }
     
-    public boolean isClosed()
+    public final boolean isClosed()
     {
         return _pendingClose;
     }
     
-    protected void closeNow()
+    final NioNetStackList<SendablePacket<T>> getSendQueue()
     {
-        synchronized (this.getSendQueue())
-        {
-            if (!this.isClosed())
-            {
-                _pendingClose = true;
-                this.getSendQueue().clear();
-                this.disableWriteInterest();
-                this.getSelectorThread().closeConnection(this);
-            }
-        }
-        
+    	return _sendQueue;
     }
     
-    public void close(SendablePacket<T> sp)
+    final SendablePacket<T> getClosePacket()
     {
-        synchronized (this.getSendQueue())
-        {
-            if (!this.isClosed())
-            {
-                this.getSendQueue().clear();
-                this.sendPacket(sp);
-                _pendingClose = true;
-                this.getSelectorThread().closeConnection(this);
-            }
-        }
+    	return _closePacket;
     }
     
-    protected void closeLater()
+    public final void close(final SendablePacket<T> sp)
     {
-        synchronized (this.getSendQueue())
+    	synchronized (getSendQueue())
+    	{
+    		if (!_pendingClose)
+    			_pendingClose = true;
+    		
+    		_sendQueue.clear();
+    	}
+    	
+    	try
         {
-            if (!this.isClosed())
-            {
-                _pendingClose = true;
-                this.getSelectorThread().closeConnection(this);
-            }
+			_selectionKey.interestOps(_selectionKey.interestOps() & ~SelectionKey.OP_WRITE);
+        }
+        catch (CancelledKeyException e)
+        {
+            // ignore
         }
         
+        _closePacket = sp;
+    	_selectorThread.closeConnection(this);
     }
     
-    protected void releaseBuffers()
+    final void releaseBuffers()
     {
         if (_primaryWriteBuffer != null)
         {
-            this.getSelectorThread().recycleBuffer(_primaryWriteBuffer);
+        	_selectorThread.recycleBuffer(_primaryWriteBuffer);
             _primaryWriteBuffer = null;
+            
             if (_secondaryWriteBuffer != null)
             {
-                this.getSelectorThread().recycleBuffer(_secondaryWriteBuffer);
+            	_selectorThread.recycleBuffer(_secondaryWriteBuffer);
                 _secondaryWriteBuffer = null;
             }
         }
+        
         if (_readBuffer != null)
         {
-            this.getSelectorThread().recycleBuffer(_readBuffer);
+        	_selectorThread.recycleBuffer(_readBuffer);
             _readBuffer = null;
         }
     }
-    
-    protected void onDisconnection()
-    {
-        this.getClient().onDisconnection();
-    }
-    
-    protected void onForcedDisconnection()
-    {
-        this.getClient().onForcedDisconnection();
-    }
 }

+ 100 - 0
MMOCore/src/org/mmocore/network/NioNetStackList.java

@@ -0,0 +1,100 @@
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+package org.mmocore.network;
+
+/**
+ * @author Forsaiken
+ */
+public final class NioNetStackList<E>
+{
+    private final NioNetStackNode _start = new NioNetStackNode();
+    private final NioNetStackNodeBuf _buf = new NioNetStackNodeBuf();
+    private NioNetStackNode _end = new NioNetStackNode();
+    
+    public NioNetStackList()
+    {
+        clear();
+    }
+    
+    public final void addLast(final E elem)
+    {
+    	 final NioNetStackNode newEndNode = _buf.removeFirst();
+    	_end._value = elem;
+        _end._next = newEndNode;
+        _end = newEndNode;
+    }
+    
+    public final E removeFirst()
+    {
+    	final NioNetStackNode old = _start._next;
+    	final E value = old._value;
+    	_start._next = old._next;
+    	_buf.addLast(old);
+        return value;
+    }
+    
+    public final boolean isEmpty()
+    {
+        return _start._next == _end;
+    }
+    
+    public final void clear()
+    {
+        _start._next = _end;
+    }
+    
+    private final class NioNetStackNode
+    {
+    	private NioNetStackNode _next;
+    	private E _value;
+        
+    	private NioNetStackNode()
+        {
+        	
+        }
+    }
+    
+    private final class NioNetStackNodeBuf
+    {
+    	private final NioNetStackNode _start = new NioNetStackNode();
+        private NioNetStackNode _end = new NioNetStackNode();
+        
+        NioNetStackNodeBuf()
+        {
+        	_start._next = _end;
+        }
+        
+        final void addLast(final NioNetStackNode node)
+        {
+        	node._next = null;
+        	node._value = null;
+            _end._next = node;
+            _end = node;
+        }
+        
+        final NioNetStackNode removeFirst()
+        {
+        	if (_start._next == _end)
+        		return new NioNetStackNode();
+        	
+        	final NioNetStackNode old = _start._next;
+        	_start._next = old._next;
+            return old;
+        }
+    }
+}

+ 39 - 0
MMOCore/src/org/mmocore/network/NioNetStringBuffer.java

@@ -0,0 +1,39 @@
+package org.mmocore.network;
+
+import java.nio.BufferOverflowException;
+
+/**
+ * @author Forsaiken
+ */
+public final class NioNetStringBuffer
+{
+	private final char[] _buf;
+	private final int _size;
+	private int _len;
+	
+	public NioNetStringBuffer(final int size)
+	{
+		_buf = new char[size];
+		_size = size;
+		_len = 0;
+	}
+	
+	public final void clear()
+	{
+		_len = 0;
+	}
+	
+	public final void append(final char c)
+	{
+		if (_len < _size)
+			_buf[_len++] = c;
+		else
+			throw new BufferOverflowException();
+	}
+	
+	@Override
+	public final String toString()
+	{
+		return new String(_buf, 0, _len);
+	}
+}

+ 24 - 31
MMOCore/src/org/mmocore/network/ReceivablePacket.java

@@ -17,75 +17,68 @@
  */
 package org.mmocore.network;
 
-
-import javolution.text.TextBuilder;
-
 /**
  * @author KenM
  *
  */
-public abstract class ReceivablePacket<T extends MMOClient> extends AbstractPacket<T> implements Runnable
+public abstract class ReceivablePacket<T extends MMOClient<?>> extends AbstractPacket<T> implements Runnable
 {
+	NioNetStringBuffer _sbuf;
+	
     protected ReceivablePacket()
     {
         
     }
     
-    protected int getAvaliableBytes()
-    {
-        return this.getByteBuffer().remaining();
-    }
-    
     protected abstract boolean read();
     
     public abstract void run();
     
-    protected void readB(byte[] dst)
+    protected final void readB(final byte[] dst)
     {
-        this.getByteBuffer().get(dst);
+        _buf.get(dst);
     }
     
-    protected void readB(byte[] dst, int offset, int len)
+    protected final void readB(final byte[] dst, final int offset, final int len)
     {
-        this.getByteBuffer().get(dst, offset, len);
+    	_buf.get(dst, offset, len);
     }
     
-    protected int readC()
+    protected final int readC()
     {
-        return this.getByteBuffer().get() & 0xFF;
+        return _buf.get() & 0xFF;
     }
     
-    protected int readH()
+    protected final int readH()
     {
-        return this.getByteBuffer().getShort() & 0xFFFF;
+        return _buf.getShort() & 0xFFFF;
     }
     
-    protected int readD()
+    protected final int readD()
     {
-        return this.getByteBuffer().getInt();
+        return _buf.getInt();
     }
     
-    protected long readQ()
+    protected final long readQ()
     {
-        return this.getByteBuffer().getLong();
+        return _buf.getLong();
     }
     
-    protected double readF()
+    protected final double readF()
     {
-        return this.getByteBuffer().getDouble();
+        return _buf.getDouble();
     }
     
-    protected String readS()
+    protected final String readS()
     {
-        TextBuilder tb = TextBuilder.newInstance();
+    	_sbuf.clear();
+    	
         char ch;
-        
-        while ((ch = this.getByteBuffer().getChar()) != 0)
+        while ((ch = _buf.getChar()) != 0)
         {
-            tb.append(ch);
+        	_sbuf.append(ch);
         }
-        String str = tb.toString();
-        TextBuilder.recycle(tb);
-        return str;
+        
+        return _sbuf.toString();
     }
 }

+ 16 - 119
MMOCore/src/org/mmocore/network/SelectorConfig.java

@@ -17,121 +17,30 @@
  */
 package org.mmocore.network;
 
-import java.nio.ByteOrder;
-
 /**
  * @author KenM
  *
  */
-public class SelectorConfig<T extends MMOClient>
+public final class SelectorConfig
 {
-    // UDP
-    private final UDPHeaderHandler<T> UDP_HEADER_HANDLER;
-    private final IPacketHandler<T> UDP_PACKET_HANDLER;
-    
-    // TCP
-    private final TCPHeaderHandler<T> TCP_HEADER_HANDLER;
-    private final IPacketHandler<T> TCP_PACKET_HANDLER;
-    
-    private int READ_BUFFER_SIZE = 64*1024;
-    private int WRITE_BUFFER_SIZE = 64*1024;
-    private int MAX_SEND_PER_PASS = 1;
-    private int SLEEP_TIME = 10;
-    private HeaderSize HEADER_TYPE = HeaderSize.SHORT_HEADER;
-    private int HELPER_BUFFER_SIZE = 64*1024;
-    private int HELPER_BUFFER_COUNT = 20;
-    private ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN;
-    
+	public int READ_BUFFER_SIZE = 64 * 1024;
+	public int WRITE_BUFFER_SIZE = 64 * 1024;
+	
+	public int HELPER_BUFFER_COUNT = 20;
+	public int HELPER_BUFFER_SIZE = 64 * 1024;
+	
     /**
-     * BYTE_HEADER: unsigned byte, max size: 255 <BR>
-     * SHORT_HEADER: unsigned short, max size: 65535<BR>
-     * INT_HEADER: signed integer, max size: Integer.MAX_SIZE<BR>
-     * @author KenM
+     * Server will try to send MAX_SEND_PER_PASS packets per socket write call<br>
+     * however it may send less if the write buffer was filled before achieving this value.
      */
-    public static enum HeaderSize
-    { 
-        BYTE_HEADER,
-        SHORT_HEADER,
-        INT_HEADER,
-    }
-    
-    public SelectorConfig(UDPHeaderHandler<T> udpHeaderHandler, IPacketHandler<T> udpPacketHandler, TCPHeaderHandler<T> tcpHeaderHandler, IPacketHandler<T> tcpPacketHandler)
-    {
-        UDP_HEADER_HANDLER = udpHeaderHandler;
-        UDP_PACKET_HANDLER = udpPacketHandler;
-        
-        TCP_HEADER_HANDLER = tcpHeaderHandler;
-        TCP_PACKET_HANDLER = tcpPacketHandler;
-    }
-    
-    public int getReadBufferSize()
-    {
-        return READ_BUFFER_SIZE;
-    }
-    
-    public int getWriteBufferSize()
-    {
-        return WRITE_BUFFER_SIZE;
-    }
-    
-    public int getHelperBufferSize()
-    {
-        return HELPER_BUFFER_SIZE;
-    }
-    
-    public int getHelperBufferCount()
-    {
-        return HELPER_BUFFER_COUNT;
-    }
-    
-    public ByteOrder getByteOrder()
-    {
-        return BYTE_ORDER;
-    }
-    
-    public HeaderSize getHeaderType()
-    {
-        return HEADER_TYPE;
-    }
-
-    public UDPHeaderHandler<T> getUDPHeaderHandler()
-    {
-        return UDP_HEADER_HANDLER;
-    }
+    public int MAX_SEND_PER_PASS = 10;
     
-    public IPacketHandler<T> getUDPPacketHandler()
-    {
-        return UDP_PACKET_HANDLER;
-    }
-    
-    public TCPHeaderHandler<T> getTCPHeaderHandler()
-    {
-        return TCP_HEADER_HANDLER;
-    }
-    
-    public IPacketHandler<T> getTCPPacketHandler()
-    {
-        return TCP_PACKET_HANDLER;
-    }
-
-    /**
-     * Server will try to send maxSendPerPass packets per socket write call however it may send less if the write buffer was filled before achieving this value.
-     * 
-     * @param The maximum number of packets to be sent on a single socket write call
-     */
-    public void setMaxSendPerPass(int maxSendPerPass)
-    {
-        MAX_SEND_PER_PASS = maxSendPerPass;
-    }
-
     /**
-     * @return The maximum number of packets sent in an socket write call
+     * Server will try to read MAX_READ_PER_PASS packets per socket read call<br>
+     * however it may read less if the read buffer was empty before achieving this value.
      */
-    public int getMaxSendPerPass()
-    {
-        return MAX_SEND_PER_PASS;
-    }
-
+    public int MAX_READ_PER_PASS = 10;
+    
     /**
      * Defines how much time (in milis) should the selector sleep, an higher value increases throughput but also increases latency(to a max of the sleep value itself).<BR>
      * Also an extremely high value(usually > 100) will decrease throughput due to the server not doing enough sends per second (depends on max sends per pass).<BR>
@@ -139,18 +48,6 @@ public class SelectorConfig<T extends MMOClient>
      * Recommended values:<BR>
      * 1 for minimal latency.<BR>
      * 10-30 for an latency/troughput trade-off based on your needs.<BR>
-     * @param sleepTime the sleepTime to set
-     */
-    public void setSelectorSleepTime(int sleepTime)
-    {
-        SLEEP_TIME = sleepTime;
-    }
-
-    /**
-     * @return the sleepTime setting for the selector
      */
-    public int getSelectorSleepTime()
-    {
-        return SLEEP_TIME;
-    }
-}
+    public int SLEEP_TIME = 10;
+}

File diff suppressed because it is too large
+ 346 - 867
MMOCore/src/org/mmocore/network/SelectorThread.java


+ 31 - 41
MMOCore/src/org/mmocore/network/SendablePacket.java

@@ -21,76 +21,66 @@ package org.mmocore.network;
  * @author KenM
  *
  */
-public abstract class SendablePacket<T extends MMOClient> extends AbstractPacket<T>
+public abstract class SendablePacket<T extends MMOClient<?>> extends AbstractPacket<T>
 {
-    protected void putShort(int value)
+    protected final void putInt(final int value)
     {
-        this.getByteBuffer().putShort((short) value);
+    	_buf.putInt(value);
     }
     
-    protected void putInt(int value)
+    protected final void putDouble(final double value)
     {
-        this.getByteBuffer().putInt(value);
+    	_buf.putDouble(value);
     }
     
-    protected void putDouble(double value)
+    protected final void putFloat(final float value)
     {
-        this.getByteBuffer().putDouble(value);
+    	_buf.putFloat(value);
     }
     
-    protected void putFloat(float value)
+    protected final void writeC(final int data)
     {
-        this.getByteBuffer().putFloat(value);
+    	_buf.put((byte)data);
     }
     
-    protected void writeC(int data)
+    protected final void writeF(final double value)
     {
-        this.getByteBuffer().put((byte) data);
+    	_buf.putDouble(value);
     }
     
-    protected void writeF(double value)
+    protected final void writeH(final int value)
     {
-        this.getByteBuffer().putDouble(value);
+    	_buf.putShort((short)value);
     }
     
-    protected void writeH(int value)
+    protected final void writeD(final int value)
     {
-        this.getByteBuffer().putShort((short) value);
+    	_buf.putInt(value);
     }
     
-    protected void writeD(int value)
+    protected final void writeQ(final long value)
     {
-        this.getByteBuffer().putInt(value);
+    	_buf.putLong(value);
     }
     
-    protected void writeQ(long value)
+    protected final void writeB(final byte[] data)
     {
-        this.getByteBuffer().putLong(value);
+    	_buf.put(data);
     }
     
-    protected void writeB(byte[] data)
+    protected final void writeS(final String text)
     {
-        this.getByteBuffer().put(data);
-    }
-    
-    protected void writeS(CharSequence charSequence)
-    {
-        if (charSequence == null)
-        {
-            charSequence = "";
-        }
-        
-        int length = charSequence.length();
-        for (int i = 0; i < length; i++)
-        {
-            this.getByteBuffer().putChar(charSequence.charAt(i));
-        }
-        this.getByteBuffer().putChar('\000');
+    	if (text != null)
+    	{
+    		final int len = text.length();
+    		for (int i = 0; i < len; i++)
+    		{
+    			_buf.putChar(text.charAt(i));
+    		}
+    	}
+    	
+    	_buf.putChar('\000');
     }
     
     protected abstract void write();
-    
-    protected abstract int getHeaderSize();
-    
-    protected abstract void writeHeader(int dataSize);
-}
+}

+ 0 - 48
MMOCore/src/org/mmocore/network/TCPHeaderHandler.java

@@ -1,48 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
-
-/**
- * @author KenM
- *
- */
-public abstract class TCPHeaderHandler<T extends MMOClient> extends HeaderHandler<T, TCPHeaderHandler<T>>
-{
-    /**
-     * @param subHeaderHandler
-     */
-    public TCPHeaderHandler(TCPHeaderHandler<T> subHeaderHandler)
-    {
-        super(subHeaderHandler);
-    }
-
-    private final HeaderInfo<T> _headerInfoReturn = new HeaderInfo<T>();
-    
-    public abstract HeaderInfo handleHeader(SelectionKey key, ByteBuffer buf);
-    
-    /**
-     * @return the headerInfoReturn
-     */
-    protected final HeaderInfo<T> getHeaderInfoReturn()
-    {
-        return _headerInfoReturn;
-    }
-}

+ 0 - 79
MMOCore/src/org/mmocore/network/TCPSocket.java

@@ -1,79 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-
-/**
- * @author KenM
- *
- */
-public class TCPSocket implements ISocket
-{
-    private final Socket _socket;
-
-    public TCPSocket(Socket socket)
-    {
-        _socket = socket;
-    }
-    
-    /* (non-Javadoc)
-     * @see com.l2jserver.mmocore.network.ISocket#close()
-     */
-    public void close() throws IOException
-    {
-        _socket.close();
-    }
-
-    /* (non-Javadoc)
-     * @see com.l2jserver.mmocore.network.ISocket#getReadableByteChannel()
-     */
-    public ReadableByteChannel getReadableByteChannel()
-    {
-        return _socket.getChannel();
-    }
-
-    /* (non-Javadoc)
-     * @see com.l2jserver.mmocore.network.ISocket#getWritableByteChannel()
-     */
-    public WritableByteChannel getWritableByteChannel()
-    {
-        return _socket.getChannel();
-    }
-
-    /* (non-Javadoc)
-     * @see org.mmocore.network.ISocket#getInetAddress()
-     */
-    public InetAddress getInetAddress()
-    {
-        return _socket.getInetAddress();
-    }
-    
-    /* (non-Javadoc)
-     * @see org.mmocore.network.ISocket#getPort()
-     */
-    public int getPort()
-    {
-        return _socket.getPort();
-    }
-    
-}

+ 0 - 51
MMOCore/src/org/mmocore/network/UDPHeaderHandler.java

@@ -1,51 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.DatagramChannel;
-
-/**
- * @author KenM
- *
- */
-public abstract class UDPHeaderHandler<T extends MMOClient>  extends HeaderHandler<T, UDPHeaderHandler<T>>
-{
-    /**
-     * @param subHeaderHandler
-     */
-    public UDPHeaderHandler(UDPHeaderHandler<T> subHeaderHandler)
-    {
-        super(subHeaderHandler);
-    }
-
-    private final HeaderInfo<T> _headerInfoReturn = new HeaderInfo<T>();
-    
-    protected abstract HeaderInfo handleHeader(ByteBuffer buf);
-    
-    protected abstract void onUDPConnection(SelectorThread<T> selector, DatagramChannel dc, SocketAddress key, ByteBuffer buf);
-    
-    /**
-     * @return the headerInfoReturn
-     */
-    protected final HeaderInfo<T> getHeaderInfoReturn()
-    {
-        return _headerInfoReturn;
-    }
-}

+ 0 - 79
MMOCore/src/org/mmocore/network/UDPSocket.java

@@ -1,79 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package org.mmocore.network;
-
-import java.io.IOException;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-
-/**
- * @author KenM
- *
- */
-public class UDPSocket implements ISocket
-{
-    private final DatagramSocket _socket;
-
-    public UDPSocket(DatagramSocket socket)
-    {
-        _socket = socket;
-    }
-    
-    /* (non-Javadoc)
-     * @see com.l2jserver.mmocore.network.ISocket#close()
-     */
-    public void close() throws IOException
-    {
-        _socket.close();
-    }
-
-    /* (non-Javadoc)
-     * @see com.l2jserver.mmocore.network.ISocket#getReadableByteChannel()
-     */
-    public ReadableByteChannel getReadableByteChannel()
-    {
-        return _socket.getChannel();
-    }
-
-    /* (non-Javadoc)
-     * @see com.l2jserver.mmocore.network.ISocket#getWritableByteChannel()
-     */
-    public WritableByteChannel getWritableByteChannel()
-    {
-        return _socket.getChannel();
-    }
-
-    /* (non-Javadoc)
-     * @see org.mmocore.network.ISocket#getInetAddress()
-     */
-    public InetAddress getInetAddress()
-    {
-        return _socket.getInetAddress();
-    }
-    
-    /* (non-Javadoc)
-     * @see org.mmocore.network.ISocket#getPort()
-     */
-    public int getPort()
-    {
-        return _socket.getPort();
-    }
-    
-}

+ 0 - 76
MMOCore/src/org/mmocore/test/testserver/SelectorHelper.java

@@ -1,76 +0,0 @@
-/**
- * 
- */
-package org.mmocore.test.testserver;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.mmocore.network.HeaderInfo;
-import org.mmocore.network.TCPHeaderHandler;
-import org.mmocore.network.IClientFactory;
-import org.mmocore.network.IMMOExecutor;
-import org.mmocore.network.IPacketHandler;
-import org.mmocore.network.MMOConnection;
-import org.mmocore.network.ReceivablePacket;
-
-
-/**
- * @author KenM
- *
- */
-public class SelectorHelper extends TCPHeaderHandler<ServerClient> implements IPacketHandler<ServerClient>, IMMOExecutor<ServerClient>, IClientFactory<ServerClient>
-{
-    public SelectorHelper()
-    {
-        super(null);
-    }
-
-    ExecutorService _tpe = Executors.newFixedThreadPool(4);
-    
-    public ReceivablePacket<ServerClient> handlePacket(ByteBuffer buf, ServerClient client)
-    {
-        return new TestRecvPacket();
-    }
-
-    public void execute(ReceivablePacket<ServerClient> packet)
-    {
-        _tpe.execute(packet);
-    }
-
-    public ServerClient create(MMOConnection<ServerClient> con)
-    {
-        System.out.println("new client");
-        /*try
-        {
-            con.getSocketChannel().socket().setSendBufferSize(2*65536);
-        }
-        catch (SocketException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }*/
-        ServerClient sc = new ServerClient(con);
-        return sc;
-    }
-
-    @Override
-    public HeaderInfo<ServerClient> handleHeader(SelectionKey key, ByteBuffer buf)
-    {
-        int avaliable = buf.remaining();
-        if (avaliable >= 2)
-        {
-            int dataSize = buf.getShort() & 0xFFFF;
-            System.err.println("DATASIZE: "+dataSize);
-            return this.getHeaderInfoReturn().set(0, dataSize - 2, false, null);
-        }
-        else
-        {
-            System.err.println("HEADER PENDING: "+(2 - avaliable));
-            return this.getHeaderInfoReturn().set(2 - avaliable, 0, false, null);
-        }
-    }
-
-}

+ 0 - 48
MMOCore/src/org/mmocore/test/testserver/ServerClient.java

@@ -1,48 +0,0 @@
-/**
- * 
- */
-package org.mmocore.test.testserver;
-
-import java.nio.ByteBuffer;
-
-import org.mmocore.network.MMOClient;
-import org.mmocore.network.MMOConnection;
-import org.mmocore.network.SendablePacket;
-
-
-/**
- * @author KenM
- *
- */
-public final class ServerClient extends MMOClient<MMOConnection<ServerClient>>
-{
-
-    public ServerClient(MMOConnection<ServerClient> con)
-    {
-        super(con);
-    }
-
-    @Override
-    public boolean decrypt(ByteBuffer buf, int size)
-    {
-        return true;
-    }
-
-    @Override
-    public boolean encrypt(ByteBuffer buf, int size)
-    {
-        buf.position(buf.position() + size);
-        return true;
-    }
-
-    public void sendPacket(SendablePacket<ServerClient> sp)
-    {
-        //System.out.println("SENDPACKET");
-        this.getConnection().sendPacket(sp);
-    }
-    
-    public void onDisconection()
-    {
-        //System.out.println("CLIENT DISCONNECTED\n=============================\n");
-    }
-}

+ 0 - 35
MMOCore/src/org/mmocore/test/testserver/TestRecvPacket.java

@@ -1,35 +0,0 @@
-/**
- * 
- */
-package org.mmocore.test.testserver;
-
-import org.mmocore.network.ReceivablePacket;
-
-/**
- * @author KenM
- *
- */
-public class TestRecvPacket extends ReceivablePacket<ServerClient>
-{
-    private int _value;
-    
-    @Override
-    protected boolean read()
-    {
-        _value = readD();
-        return true;
-    }
-
-    @Override
-    public void run()
-    {
-        System.out.println("ServerRecebeu "+_value);
-        TestSendPacket tsp = new TestSendPacket(_value);
-        this.getClient().sendPacket(tsp);
-        this.getClient().sendPacket(tsp);
-        this.getClient().sendPacket(tsp);
-        this.getClient().sendPacket(tsp);
-        this.getClient().sendPacket(tsp);
-        this.getClient().sendPacket(tsp);
-    }
-}

+ 0 - 42
MMOCore/src/org/mmocore/test/testserver/TestSendPacket.java

@@ -1,42 +0,0 @@
-/**
- * 
- */
-package org.mmocore.test.testserver;
-
-import org.mmocore.network.SendablePacket;
-
-/**
- * @author KenM
- *
- */
-public class TestSendPacket extends SendablePacket<ServerClient>
-{
-    private int _value;
-    
-    public TestSendPacket(int value)
-    {
-        _value = value;
-    }
-    
-    @Override
-    protected void write()
-    {
-        writeD(_value);
-        for (int i = 0; i < 48000; i++)
-        {
-            writeC(i%256);
-        }
-    }
-
-    @Override
-    protected int getHeaderSize()
-    {
-        return 2;
-    }
-
-    @Override
-    protected void writeHeader(int dataSize)
-    {
-        writeH(dataSize + 2);
-    }
-}

+ 0 - 39
MMOCore/src/org/mmocore/test/testserver/TestServer.java

@@ -1,39 +0,0 @@
-/**
- * 
- */
-package org.mmocore.test.testserver;
-
-import java.io.IOException;
-
-import org.mmocore.network.SelectorConfig;
-import org.mmocore.network.SelectorThread;
-
-
-/**
- * @author KenM
- *
- */
-public class TestServer
-{
-    public static int PORT = 0xCAFE;
-    
-    public static void main(String[] args) throws IOException
-    {
-        if (args.length > 0)
-        {
-            PORT = Integer.parseInt(args[0]);
-        }
-        
-        SelectorHelper sh = new SelectorHelper();
-        SelectorConfig<ServerClient> ssc = new SelectorConfig<ServerClient>(null, null, sh, sh);
-        ssc.setMaxSendPerPass(2);
-        SelectorThread<ServerClient> selector = new SelectorThread<ServerClient>(ssc, sh, sh, null);
-        selector.openServerSocket(null, PORT);
-        //selector.openDatagramSocket();
-        selector.start();
-        
-        System.err.println("TestServer active on port "+PORT);
-    }
-
-
-}

+ 0 - 175
MMOCore/src/org/mmocore/util/collections/concurrent/SemiConcurrentLinkedList.java

@@ -1,175 +0,0 @@
-/**
- * 
- */
-package org.mmocore.util.collections.concurrent;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * This a semi-concurrent linked list implementation that aims to provide 
- * a high speed solution that fullfill the most used pattern of the MMOCore.<BR>
- * 
- * Iterations forward only
- * 1 thread appends (N if synchronized)
- * 1 thread read/delete
- * 
- * @author KenM
- *
- */
-public class SemiConcurrentLinkedList<E> implements Iterable<E>
-{
-    private volatile Node<E> _start = new Node<E>();
-    private volatile Node<E> _end = new Node<E>();
-    private int _size;
-    
-    public SemiConcurrentLinkedList()
-    {
-        this.clear();
-    }
-    
-    public void addLast(E elem)
-    {
-        Node<E> oldEndNode = _end;
-        
-        // assign the value to the current last node
-        oldEndNode._value = elem;
-        
-        // create the new end node
-        Node<E> newEndNode = new Node<E>(oldEndNode, null, null);
-        
-        // assign the new end as the next of the current end
-        oldEndNode.setNext(newEndNode);
-        
-        // place the new end
-        _end = newEndNode;
-        
-        // increment list size
-        _size++;
-    }
-    
-    public void remove(Node<E> node)
-    {
-        Node<E> previous = node.getPrevious();
-        Node<E> next = node.getNext();
-        
-        // set the next to skip the node being deleted
-        previous.setNext(next);
-        
-        // adjust previous
-        next.setPrevious(previous);
-        
-        _size--;
-    }
-    
-    public int size()
-    {
-        return _size;
-    }
-    
-    public final boolean isEmpty()
-    {
-        return _size == 0;
-    }
-    
-    public void clear()
-    {
-        _start.setNext(_end);
-        _end.setPrevious(_start);
-    }
-    
-    public Node<E> getStart()
-    {
-        return _start;
-    }
-    
-    public Node<E> getEnd()
-    {
-        return _end;
-    }
-    
-    public Iterator<E> iterator()
-    {
-        return new SemiConcurrentIterator(_start);
-    }
-    
-    public class SemiConcurrentIterator implements Iterator<E>
-    {
-        private Node<E> _current;
-        //private Node<V> _last;
-        
-        protected SemiConcurrentIterator(Node<E> start)
-        {
-            _current = start;
-        }
-        
-        public boolean hasNext()
-        {
-            return _current.getNext() != _end;
-        }
-
-        public E next()
-        {
-            _current = _current.getNext();
-            if (_current == _end)
-            {
-                throw new NoSuchElementException();
-            }
-            return _current.getValue();
-        }
-
-        public void remove()
-        {
-            SemiConcurrentLinkedList.this.remove(_current);
-            _current = _current.getPrevious();
-        }
-    }
-    
-    public final class Node<T>
-    {
-        private Node<T> _previous;
-        private Node<T> _next;
-        private T _value;
-        
-        protected Node()
-        {
-        }
-        
-        protected Node(T value)
-        {
-            _value = value;
-        }
-        
-        protected Node(Node<T> previous, Node<T> next, T value)
-        {
-            _previous = previous;
-            _next = next;
-            _value = value;
-        }
-        
-        public Node<T> getNext()
-        {
-            return _next;
-        }
-        
-        protected void setNext(Node<T> node)
-        {
-            _next = node;
-        }
-        
-        public Node<T> getPrevious()
-        {
-            return _previous;
-        }
-        
-        protected void setPrevious(Node<T> node)
-        {
-            _previous = node;
-        }
-        
-        public T getValue()
-        {
-            return _value;
-        }
-    }
-}

Some files were not shown because too many files changed in this diff