Return-Path: X-Original-To: apmail-directory-dev-archive@www.apache.org Delivered-To: apmail-directory-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0312F186E0 for ; Tue, 2 Feb 2016 10:21:33 +0000 (UTC) Received: (qmail 12997 invoked by uid 500); 2 Feb 2016 10:21:32 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 12943 invoked by uid 500); 2 Feb 2016 10:21:32 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 12933 invoked by uid 99); 2 Feb 2016 10:21:32 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Feb 2016 10:21:32 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 06D74C0873 for ; Tue, 2 Feb 2016 10:21:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.653 X-Spam-Level: X-Spam-Status: No, score=-0.653 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RP_MATCHES_RCVD=-0.553, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=evolveum.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 8UYnQpSSdAEh for ; Tue, 2 Feb 2016 10:21:23 +0000 (UTC) Received: from hermes.evolveum.com (hermes.evolveum.com [141.101.128.38]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 4F8DE31AB2 for ; Tue, 2 Feb 2016 10:21:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hermes.evolveum.com (Postfix) with ESMTP id 427E1361076 for ; Tue, 2 Feb 2016 11:24:12 +0100 (CET) Received: from hermes.evolveum.com ([127.0.0.1]) by localhost (hermes.evolveum.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id qkLJIG6ev09G for ; Tue, 2 Feb 2016 11:24:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hermes.evolveum.com (Postfix) with ESMTP id B345A369B06 for ; Tue, 2 Feb 2016 11:24:11 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.9.0 hermes.evolveum.com B345A369B06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=evolveum.com; s=46F1F96C-8266-11E5-BB5D-6C9186186C84; t=1454408651; bh=7N/KEoXeviasvRcxwTPd6OLN8lg/qoPEKrCkX7knCSQ=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type: Content-Transfer-Encoding; b=MS2zyojmaf1grM8STGLRfNhl/vPNVYe3o6FyPGFRjTjkn/maGbOSTwFTGeS5hUGFc pt6MLflloyx5t39Q0nq31E9RTIA+AFlR8S7zsIw7z8sDV6ZOUUL/VhI69deUCFLMjH YJ/8mUQ/dmGP4AHcQXo6yNFjnJWGLD9IpYoFiJZU= X-Virus-Scanned: amavisd-new at hermes.evolveum.com Received: from hermes.evolveum.com ([127.0.0.1]) by localhost (hermes.evolveum.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yIAwtn465YAc for ; Tue, 2 Feb 2016 11:24:11 +0100 (CET) Received: from [10.1.1.50] (static-dsl-137.87-197-146.telecom.sk [87.197.146.137]) by hermes.evolveum.com (Postfix) with ESMTPSA id 9723A361076 for ; Tue, 2 Feb 2016 11:24:11 +0100 (CET) Subject: Re: Cursor to implement Closeable To: dev@directory.apache.org References: <56AC7286.2080201@gmail.com> <8D5F7E3237B3ED47B84CF187BB17B6661487AF37@SHSMSX103.ccr.corp.intel.com> <56AC97CA.6020208@gmail.com> <8D5F7E3237B3ED47B84CF187BB17B6661487B312@SHSMSX103.ccr.corp.intel.com> From: Radovan Semancik Message-ID: <56B08321.1000705@evolveum.com> Date: Tue, 2 Feb 2016 11:21:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <8D5F7E3237B3ED47B84CF187BB17B6661487B312@SHSMSX103.ccr.corp.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 01/30/2016 12:33 PM, Zheng, Kai wrote: > Not sure if it's a good practice to pass an exception as reason to a close method, as least in Java. > Confusing: exception thrown when this Cursor is accessed after close. When it's accessed after close, why call the method once more? Actually (as far as I know) there is no good way to do that in Java. No good way at all. Imagine that you implement a "driver" where LDAP is just one of many ways how to access the data. You do LDAP search in the driver and one of the entry has an application error. You want to throw an exception that indicates that condition, but you also have end the search and close the connection. And now imagine that there is a network timeout on close. Which exception do you throw? The typical implementation seems to be throwing the application exception and ignoring the IO exceptions from close(). But that may end up in resource leakage, because if it is a timeout then the cursor might or might not be closed. If the client code does not handle that properly then unclosed cursors may stay around for a long time. On the other hand, throwing the IO exception and ignoring application exceptions may be even worse, because it suggests that a retryable network error while the root cause of the problem may be non-retryable and it may be so serious that re-trying the operation may cause serious harm. So, throwing both exception as nested may in fact be a good compromise. -- Radovan Semancik Software Architect evolveum.com