Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 08EB317AB2 for ; Fri, 6 Feb 2015 16:16:44 +0000 (UTC) Received: (qmail 88791 invoked by uid 500); 6 Feb 2015 16:16:36 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 88651 invoked by uid 500); 6 Feb 2015 16:16:36 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 87953 invoked by uid 99); 6 Feb 2015 16:16:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Feb 2015 16:16:35 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW X-Spam-Check-By: apache.org Received-SPF: error (nike.apache.org: local policy) Received: from [209.85.215.52] (HELO mail-la0-f52.google.com) (209.85.215.52) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Feb 2015 16:16:08 +0000 Received: by labgf13 with SMTP id gf13so2132904lab.3 for ; Fri, 06 Feb 2015 08:15:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:content-type; bh=PgXod4a2jfZ+HxdXC7aQX5sQpHuVoT54f4oHC0r2dZ8=; b=IsYrdFqCR/E53pU4xe4TlY/gURRIR6Nq6nkDSO4QGNXVkufynlPAbhSzNzeaE6W9O/ da4isgKXsW3Jc9bpNz3LQomyceY23kTanK/+BEkkDIdxsLmZt+PevL9GSaSySwlccH9Y VRfVjVvqf48nVy3zUVg38PD5NQ8JiUDJGp4BBsVjXCqd2jUNE3iqrGCrvaQTAEm17g0F mjMbqNtc6NARiYB/hkj5WWERWnl9chVF3dFOWLVJ3fSMqoe5Fim1VEn4mClPBKdf7CXV lJdoIH7f/Ekgcit9GZWYy7NrmZPKmzTkUdN2p0X/7txh+g3Hn4X5ZW7Ghf2YzD1Ff5OR fLZA== X-Gm-Message-State: ALoCoQkIkldukYuF2ekOdDnJ3ztnYjb9nA8goND75RPR10GKw7eHJIgEtJ+oDdzc9bRYDfiGpXQ1 X-Received: by 10.112.189.202 with SMTP id gk10mr2827453lbc.50.1423239302125; Fri, 06 Feb 2015 08:15:02 -0800 (PST) MIME-Version: 1.0 Sender: jcarman@carmanconsulting.com Received: by 10.112.151.238 with HTTP; Fri, 6 Feb 2015 08:14:41 -0800 (PST) In-Reply-To: References: From: James Carman Date: Fri, 6 Feb 2015 11:14:41 -0500 X-Google-Sender-Auth: o4Z2lP5f1eriK1rePz-VrFvuPjE Message-ID: Subject: Re: Re: [POOL2] Pooling mutable objects To: Commons Users List Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Try UUID.randomUUID().toString() rather than RandomStringUtils if you really want unique keys. On Fri, Feb 6, 2015 at 10:54 AM, Michael Osipov <1983-01-06@gmx.net> wrote: > This is what I did: > this.internalId = RandomStringUtils.randomAlphanumeric(8); > > Some Eclipse magic: > @Override > public int hashCode() { > final int prime = 31; > int result = 1; > result = prime * result + ((internalId == null) ? 0 : internalId.hashCode()); > return result; > } > > @Override > public boolean equals(Object obj) { > if (this == obj) > return true; > if (obj == null) > return false; > if (getClass() != obj.getClass()) > return false; > RawSession other = (RawSession) obj; > if (internalId == null) { > if (other.internalId != null) > return false; > } else if (!internalId.equals(other.internalId)) > return false; > return true; > } > >> Gesendet: Freitag, 06. Februar 2015 um 16:47 Uhr >> Von: "James Carman" >> An: "Commons Users List" >> Betreff: Re: [POOL2] Pooling mutable objects >> >> Or just let your IDE generate the methods. >> >> >> On Fri, Feb 6, 2015 at 9:05 AM, William Speirs wrote: >> > I'd think adding a UUID then overriding equals and hashCode would do the >> > trick. To aid you in doing this, commons-lang has EqualsBuilder [1] and >> > HashCodeBuilder [2], I highly recommend using them. >> > >> > Bill- >> > >> > >> > [1] >> > https://commons.apache.org/proper/commons-lang/javadocs/api-3.3.2/org/apache/commons/lang3/builder/EqualsBuilder.html >> > >> > [2] >> > https://commons.apache.org/proper/commons-lang/javadocs/api-3.3.2/org/apache/commons/lang3/builder/HashCodeBuilder.html >> > >> > On Fri, Feb 6, 2015 at 9:00 AM, Michael Osipov <1983-01-06@gmx.net> wrote: >> > >> >> Hi folks, >> >> >> >> I am developing a session pool for an HTTP backend which is requested with >> >> the fabulous HttpClient. >> >> >> >> The session object is this: >> >> >> >> public class RawSession { >> >> >> >> private CookieStore cookieStore; >> >> private String logId; >> >> private MutableInt requestId; >> >> private String clientId; >> >> private String serverId; >> >> >> >> } >> >> >> >> There won't be any setters but as you see, the cookie store and mutable >> >> int might change. >> >> Additionally, I did not implement any custom equals and hashCode methods. >> >> >> >> I have searched the docs and the found and did not find any clear answer >> >> which says >> >> that pooled objects have to be immutable. Though, I have found POOL-283 >> >> and POOL-284 which >> >> led me to the conclusion that this is a problem because the objects are >> >> stored in a map >> >> which relies on equals and hashCode. >> >> >> >> Does this ultimately mean that I have to override equals and hashCode and >> >> provide some internal, >> >> immutable value something like a UUID? Alternatively, I could retrieve the >> >> JSESSIONID from the >> >> cookie store and use this as a unique value. >> >> >> >> Thanks, >> >> >> >> Michael >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >> >> For additional commands, e-mail: user-help@commons.apache.org >> >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >> For additional commands, e-mail: user-help@commons.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org