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 {
* Compression policy currently in use for this connection.
*/
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
* 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 {
public NIOConnection(IoSession session, PacketDeliverer packetDeliverer) {
this.ioSession = session;
this.backupDeliverer = packetDeliverer;
encoder = Charset.forName(CHARSET).newEncoder();
closed = false;
}
......@@ -206,8 +205,8 @@ public class NIOConnection implements Connection {
boolean errorDelivering = false;
try {
//XMLWriter xmlSerializer = new XMLWriter(buffer.asOutputStream(), new OutputFormat());
XMLWriter xmlSerializer = new XMLWriter(new ByteBufferWriter(buffer, encoder), new OutputFormat());
XMLWriter xmlSerializer =
new XMLWriter(new ByteBufferWriter(buffer, (CharsetEncoder) encoder.get()), new OutputFormat());
xmlSerializer.write(packet.getElement());
xmlSerializer.flush();
if (flashClient) {
......@@ -391,4 +390,11 @@ public class NIOConnection implements Connection {
public String toString() {
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