Return-Path: Delivered-To: apmail-incubator-cassandra-commits-archive@minotaur.apache.org Received: (qmail 58305 invoked from network); 16 Jan 2010 12:36:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Jan 2010 12:36:15 -0000 Received: (qmail 36082 invoked by uid 500); 16 Jan 2010 12:36:15 -0000 Delivered-To: apmail-incubator-cassandra-commits-archive@incubator.apache.org Received: (qmail 35982 invoked by uid 500); 16 Jan 2010 12:36:15 -0000 Mailing-List: contact cassandra-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-dev@incubator.apache.org Delivered-To: mailing list cassandra-commits@incubator.apache.org Received: (qmail 35965 invoked by uid 99); 16 Jan 2010 12:36:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jan 2010 12:36:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jan 2010 12:36:14 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 73B93234C4AD for ; Sat, 16 Jan 2010 04:35:54 -0800 (PST) Message-ID: <1427343832.289411263645354472.JavaMail.jira@brutus.apache.org> Date: Sat, 16 Jan 2010 12:35:54 +0000 (UTC) From: "Hudson (JIRA)" To: cassandra-commits@incubator.apache.org Subject: [jira] Commented: (CASSANDRA-700) Replacing the many forms of singleton instance methods In-Reply-To: <458336949.237291263471174497.JavaMail.jira@brutus.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CASSANDRA-700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12801154#action_12801154 ] Hudson commented on CASSANDRA-700: ---------------------------------- Integrated in Cassandra #325 (See [http://hudson.zones.apache.org/hudson/job/Cassandra/325/]) replace instance() accessors with public final fields. patch by Jeff Hodges; reviewed by Gary Dusbabek and jbellis for > Replacing the many forms of singleton instance methods > ------------------------------------------------------ > > Key: CASSANDRA-700 > URL: https://issues.apache.org/jira/browse/CASSANDRA-700 > Project: Cassandra > Issue Type: Improvement > Reporter: Jeff Hodges > Assignee: Jeff Hodges > Fix For: 0.9 > > Attachments: 0001-MessagingService.instance-MessagingService.instance.patch, 0001-removing-lots-of-static-instance-methods.patch, 0001-squashed-singleton-clean-up.patch, 0001-v2-removing-lots-of-static-instance-methods.patch, 0002-HintedHandOffManager.instance-HintedHandOffManager.i.patch, 0003-StorageService.instance-StorageService.instance.patch, 0004-AntiEntropyService.instance-AntiEntropyService.insta.patch, 0005-Gossiper.instance-Gossiper.instance.patch, 0006-StorageLoadBalancer.instance-StorageLoadBalancer.ins.patch, 0007-FailureDetector.instance-FailureDetector.instance.patch, 0008-ReadRepairManager.instance-ReadRepairManager.instanc.patch > > > In many places, the Cassandra codebase attempts to allow for only one instance of a particular class per process. It does so in a variety of ways, some of which are attempts at being thread-safe (with mixed results) while others seem to just delay instantiation. > This issue is to track the changes necessary to consolidate these many forms of singleton into one form. > What's interesting is that Java has a nice way of providing this facility in a very Java-y way. We can create a public static variable (called, say, instance) and, in the class definition, set it to a new instance of the very class we are in. We then can protect the class's constructor to prevent others from trying to use it. This allows us to have only one instance of the variable accessible only through the a static variable on the class itself. > This is thread-safe because class definitions in Java is thread-safe. This is lazily loaded because Java doesn't do class definition until the first time the class is referenced in any way. Basically, this is everything that was attempted with the various static instance() methods but with complete success. > The current classes I was able to find that can benefit from this are: > AntiEntropyService > FailureDetector > Gossiper > HintedHandOffManager > MessagingService > ReadRepairManager > StorageLoadBalancer > StorageService > Other classes with similar constructions would be nice to remove, too. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.