Commit 89e514e6 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More optimization work. Reduce number of byte[] used by CharserEncoder by...

More optimization work. Reduce number of byte[] used by CharserEncoder by having an encoder per thread.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8606 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0db73760
...@@ -80,7 +80,7 @@ public class NIOConnection implements Connection { ...@@ -80,7 +80,7 @@ public class NIOConnection implements Connection {
* Compression policy currently in use for this connection. * Compression policy currently in use for this connection.
*/ */
private CompressionPolicy compressionPolicy = CompressionPolicy.disabled; private CompressionPolicy compressionPolicy = CompressionPolicy.disabled;
private CharsetEncoder encoder; private static ThreadLocal encoder = new ThreadLocalEncoder();
/** /**
* Flag that specifies if the connection should be considered closed. Closing a NIO connection * Flag that specifies if the connection should be considered closed. Closing a NIO connection
* is an asynch operation so instead of waiting for the connection to be actually closed just * is an asynch operation so instead of waiting for the connection to be actually closed just
...@@ -93,7 +93,6 @@ public class NIOConnection implements Connection { ...@@ -93,7 +93,6 @@ public class NIOConnection implements Connection {
public NIOConnection(IoSession session, PacketDeliverer packetDeliverer) { public NIOConnection(IoSession session, PacketDeliverer packetDeliverer) {
this.ioSession = session; this.ioSession = session;
this.backupDeliverer = packetDeliverer; this.backupDeliverer = packetDeliverer;
encoder = Charset.forName(CHARSET).newEncoder();
closed = false; closed = false;
} }
...@@ -206,8 +205,8 @@ public class NIOConnection implements Connection { ...@@ -206,8 +205,8 @@ public class NIOConnection implements Connection {
boolean errorDelivering = false; boolean errorDelivering = false;
try { try {
//XMLWriter xmlSerializer = new XMLWriter(buffer.asOutputStream(), new OutputFormat()); XMLWriter xmlSerializer =
XMLWriter xmlSerializer = new XMLWriter(new ByteBufferWriter(buffer, encoder), new OutputFormat()); new XMLWriter(new ByteBufferWriter(buffer, (CharsetEncoder) encoder.get()), new OutputFormat());
xmlSerializer.write(packet.getElement()); xmlSerializer.write(packet.getElement());
xmlSerializer.flush(); xmlSerializer.flush();
if (flashClient) { if (flashClient) {
...@@ -391,4 +390,11 @@ public class NIOConnection implements Connection { ...@@ -391,4 +390,11 @@ public class NIOConnection implements Connection {
public String toString() { public String toString() {
return super.toString() + " MINA Session: " + ioSession; return super.toString() + " MINA Session: " + ioSession;
} }
private static class ThreadLocalEncoder extends ThreadLocal {
protected Object initialValue() {
return Charset.forName(CHARSET).newEncoder();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment