Return-Path: Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: (qmail 73469 invoked from network); 1 Sep 2005 20:55:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Sep 2005 20:55:16 -0000 Received: (qmail 87050 invoked by uid 500); 1 Sep 2005 20:55:15 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 87022 invoked by uid 500); 1 Sep 2005 20:55:14 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 87009 invoked by uid 99); 1 Sep 2005 20:55:14 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2005 13:55:14 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [24.93.47.43] (HELO ms-smtp-04.texas.rr.com) (24.93.47.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2005 13:55:28 -0700 Received: from [192.168.10.101] (cpe-24-27-74-67.houston.res.rr.com [24.27.74.67]) by ms-smtp-04.texas.rr.com (8.12.10/8.12.7) with ESMTP id j81KtA9C003439 for ; Thu, 1 Sep 2005 15:55:10 -0500 (CDT) Mime-Version: 1.0 (Apple Message framework v734) In-Reply-To: References: Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <5A2DEA32-C451-4829-A10D-2C78C1661068@apache.org> Content-Transfer-Encoding: 7bit From: Curt Arnold Subject: Re: Serializable NDC DiagnosticContext Date: Thu, 1 Sep 2005 15:55:09 -0500 To: Log4J Developers List X-Mailer: Apple Mail (2.734) X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Sep 1, 2005, at 12:52 PM, Kurt.Eckhardt@equifax.com wrote: > Hi Folks, > > I'd like to pass a cloned NDC Stack across an EJB call, but can't > since its > NDC.DiagnosticContext entries are not serializable. Does anybody > see any > potential issues with adding an "implements java.io.Serializable" > to the > DiagnosticContext class (see snip below)? > > // > ===================================================================== > private static class DiagnosticContext implements > java.io.Serializable { > > String fullMessage; > String message; > > DiagnosticContext(String message, DiagnosticContext parent) { > this.message = message; > if(parent != null) { > fullMessage = parent.fullMessage + ' ' + message; > } else { > fullMessage = message; > } > } > } > I have a couple of problems with the suggested implementation: DiagnosticContext is a private inner class and not part of the exposed log4j API. As it is currently, the NDC implementation could be rewritten to eliminate use of DiagnosticContext without breaking the API. Using the default serialized form is undesirable. See Item 55 in "Effective Java" for an explanation. Serializing a java.util.Stack (or any java.util.Collection) can be wasteful. Again see Item 55. The best thing I could suggest would be to implement DiagnosticContext.toString() returning fullMessage. That way the class that you using to perform serialization could do something like: void writeObject(ObjectOutputStream s) { ... ... Stack clonedNDC = NDC.cloneStack(); String[] ndcContents = null; if (clonedNDC != null) { ndcContents = new String[clonedNDC.size()]; for (int i = 0; i < ndcContents.length; i++) { ndcContents[i] = clonedNDC.get(i).toString(); } } s.writeObject(ndcContents); } and the corresponding readObject() could rebuild the NDC if desired. --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-dev-help@logging.apache.org