From 69d30645c8984c35b426ecd3e1cec0e7b9305117 Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Wed, 24 Apr 2013 01:16:50 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[LUCYSUS-1744]?= =?UTF-8?q?=20serializer=20api=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@1543 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../com/profiler/io/HeaderTBaseSerializer.java | 18 +++++++++++------- .../com/profiler/sender/UdpDataSender.java | 9 +-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/profiler/io/HeaderTBaseSerializer.java b/src/main/java/com/profiler/io/HeaderTBaseSerializer.java index d06324627..9988b27ba 100644 --- a/src/main/java/com/profiler/io/HeaderTBaseSerializer.java +++ b/src/main/java/com/profiler/io/HeaderTBaseSerializer.java @@ -39,17 +39,20 @@ public class HeaderTBaseSerializer { */ public HeaderTBaseSerializer() { - this(new TCompactProtocol.Factory()); + this(new TCompactProtocol.Factory(), new DefaultTBaseLocator()); } + private TBaseLocator locator; + /** * Create a new TSerializer. It will use the TProtocol specified by the * factory that is passed in. * * @param protocolFactory Factory to create a protocol */ - public HeaderTBaseSerializer(TProtocolFactory protocolFactory) { + public HeaderTBaseSerializer(TProtocolFactory protocolFactory, TBaseLocator locator) { protocol_ = protocolFactory.getProtocol(transport_); + this.locator = locator; } /** @@ -60,7 +63,8 @@ public class HeaderTBaseSerializer { * @param base The object to serialize * @return Serialized object in byte[] format */ - public byte[] serialize(Header header, TBase base) throws TException { + public byte[] serialize(TBase base) throws TException { + final Header header = locator.headerLookup(base); baos_.reset(); writeHeader(header); base.write(protocol_); @@ -90,9 +94,9 @@ public class HeaderTBaseSerializer { * @param charset Valid JVM charset * @return Serialized object as a String */ - public String toString(Header header, TBase base, String charset) throws TException { + public String toString(TBase base, String charset) throws TException { try { - return new String(serialize(header, base), charset); + return new String(serialize(base), charset); } catch (UnsupportedEncodingException uex) { throw new TException("JVM DOES NOT SUPPORT ENCODING: " + charset); } @@ -105,7 +109,7 @@ public class HeaderTBaseSerializer { * @param base The object to serialize * @return Serialized object as a String */ - public String toString(Header header, TBase base) throws TException { - return new String(serialize(header, base)); + public String toString(TBase base) throws TException { + return new String(serialize(base)); } } diff --git a/src/main/java/com/profiler/sender/UdpDataSender.java b/src/main/java/com/profiler/sender/UdpDataSender.java index b63186ccd..a14bec494 100644 --- a/src/main/java/com/profiler/sender/UdpDataSender.java +++ b/src/main/java/com/profiler/sender/UdpDataSender.java @@ -43,11 +43,9 @@ public class UdpDataSender implements DataSender, Runnable { private DatagramSocket udpSocket = null; private Thread ioThread; - private TBaseLocator locator = new DefaultTBaseLocator(); // 주의 single thread용임 private HeaderTBaseSerializer serializer = new HeaderTBaseSerializer(); - private AtomicBoolean allowInput = new AtomicBoolean(); public UdpDataSender(String host, int port) { @@ -261,8 +259,7 @@ public class UdpDataSender implements DataSender, Runnable { private byte[] serialize(TBase dto) { try { - Header header = headerLookup(dto); - return serializer.serialize(header, dto); + return serializer.serialize(dto); } catch (TException e) { if (logger.isWarnEnabled()) { logger.warn("Serialize fail:{} Caused:{}", new Object[] { dto, e.getMessage(), e}); @@ -275,8 +272,4 @@ public class UdpDataSender implements DataSender, Runnable { return serializer.getInterBufferSize(); } - private Header headerLookup(TBase dto) throws TException { - // header 객체 생성을 안하고 정적 lookup이 되도록 변경. - return locator.headerLookup(dto); - } }