Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 27012 invoked from network); 30 Sep 2010 02:21:57 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 30 Sep 2010 02:21:57 -0000 Received: (qmail 50219 invoked by uid 500); 30 Sep 2010 02:21:56 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 50094 invoked by uid 500); 30 Sep 2010 02:21:56 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 50086 invoked by uid 99); 30 Sep 2010 02:21:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Sep 2010 02:21:55 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sebbaz@gmail.com designates 209.85.161.171 as permitted sender) Received: from [209.85.161.171] (HELO mail-gx0-f171.google.com) (209.85.161.171) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Sep 2010 02:21:49 +0000 Received: by gxk6 with SMTP id 6so536313gxk.30 for ; Wed, 29 Sep 2010 19:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=r9vUDACmkwRZYDCv++KhOEPbMR7emkg1xWvBS8UTuV4=; b=vhgM/u832qQdMV3pDbCTB5ouyhPg9wzmjUmKBOGmU8KKBzUnDyzCnLO21uBlddh94Z +KNVs9F3geBxeU38/LaUHFwBCvJANimOq5YC0FhVaYr4OXPzy1ld5YnAH7VTb9Kn2m5J Us5klIbHgzYMllXtD1+yoVi8mQdtkz6nDqJhg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=qYx5kgqHDEMw6553ZuiAIQy+vgjflq97SISDP+KOchw+H7ZyBOSPvgIV8IgjIKfIn5 /hWmDoT53Du+fbn/QFtvDh5MUcXw3gTSSnzlaMSUq5tDFN6G5Tk7FdXMZ8RGll3A0n2O zfhZPNK9VFfvYjdtjpEv4sCRL/QdyCnDMVrbk= MIME-Version: 1.0 Received: by 10.229.238.200 with SMTP id kt8mr2009376qcb.0.1285813288313; Wed, 29 Sep 2010 19:21:28 -0700 (PDT) Received: by 10.229.230.213 with HTTP; Wed, 29 Sep 2010 19:21:28 -0700 (PDT) In-Reply-To: References: Date: Thu, 30 Sep 2010 03:21:28 +0100 Message-ID: Subject: Re: [IO] Tailer API From: sebb To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 30 September 2010 02:58, Niall Pemberton wro= te: > On Thu, Sep 30, 2010 at 2:46 AM, sebb wrote: >> Just wondering if the Tailer API could be simplified by performing the >> thread start within the class? >> Is it ever going to be useful to have direct access to tailer thread? >> I suspect not, as the Listener should provide sufficient access. >> >> It's not safe to start a thread in the constructor (unless the ctor is >> final), but one could use static factory methods instead. >> >> So instead of: >> >> =A0TailerListener listener =3D ... >> =A0Tailer tailer =3D new Tailer(file, listener, delay); >> =A0Thread thread =3D new Thread(tailer); >> =A0thread.start(); >> =A0... >> =A0tailer.stop() >> >> one would do something like: >> >> =A0TailerListener listener =3D ... >> =A0Tailer tailer =3D Tailer.createTailer(file, listener, delay); >> =A0... >> =A0tailer.stop() >> >> This simplifies the API, and allows the class to force the thread to >> be a daemon thread. It also stops the caller from messing with the >> thread. >> >> WDYT? > > There are five different Thread constructors that take a Runnable and > a bunch of other methods that someone might want to use. I don't have > a problem providing a convenience static method - but it only saves > two lines of code - as long as they can construct one manually with or > without a Thread if they want to. But what is the use case for having access to the created thread? Seems to me it would be a lot safer if the thread were private to the class= . It would still be possible to use the code without a thread by exposing the method that loops over the file, and using the constructor instead. For example with the current code one could do something like: TailerListener listener =3D ... Tailer tailer =3D new Tailer(file, listener, delay); tailer.run() --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org