Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 66483 invoked from network); 30 Sep 2010 11:02:26 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 30 Sep 2010 11:02:26 -0000 Received: (qmail 35030 invoked by uid 500); 30 Sep 2010 11:02:26 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 34658 invoked by uid 500); 30 Sep 2010 11:02:22 -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 34650 invoked by uid 99); 30 Sep 2010 11:02:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Sep 2010 11:02:21 +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 (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.160.171 as permitted sender) Received: from [209.85.160.171] (HELO mail-gy0-f171.google.com) (209.85.160.171) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Sep 2010 11:02:13 +0000 Received: by gyc15 with SMTP id 15so780791gyc.30 for ; Thu, 30 Sep 2010 04:01:52 -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=ruZWovlQv3Ue+kHka1GDjXFYyY3Tp7d0ALJZtvwrtSk=; b=dPK/fm6Hd0qvrDNMB5zkeubuvvnwSz3/5hZpeuGKnlTpi4frNvyW8+wZezNNPISRcb JzcPuAgxi2Qbn/sY+6GmK1b0YmRsO7ttB5RX2biz1sf11wtPkT8uHy68bf/Ii3DUXx/N A9XHbrnHLK+PhFX+HaEFiL5VO+DrORsDiLIOE= 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=Vxioj24f52bLhXvIzz2c8rkzzx6Fsxb689sw3N31cnZaUCFliXuryDQvpHc0VsmcZA h/nhUfTHXjzmsmlNVcviwknhQYNAEOaB3wUAW1RhDUv/ZjYmLWR5+V9N5ioSupE1kyzx yvVFoi88ZlEldpfpClKcaUg4Q/LReA/mjt04U= MIME-Version: 1.0 Received: by 10.229.234.2 with SMTP id ka2mr2462881qcb.170.1285844512076; Thu, 30 Sep 2010 04:01:52 -0700 (PDT) Received: by 10.229.230.213 with HTTP; Thu, 30 Sep 2010 04:01:51 -0700 (PDT) In-Reply-To: References: Date: Thu, 30 Sep 2010 12:01:51 +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 X-Virus-Checked: Checked by ClamAV on apache.org On 30 September 2010 06:39, Julien Aym=E9 wrote: > 2010/9/30 sebb : >> On 30 September 2010 02:58, Niall Pemberton = wrote: >>> 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 cl= ass. > > The use case is that someone may want to use an Executor instead of a > dedicated Thread to run background tasks such as Tailer, at least I > do. I have no problem with providing a convenient static method, as > Niall suggested, but I would like to keep the Tailer as a Runnable > with no embedded thread if possible. OK. So how about allowing the user to pass in an Executor when creating the instance? Would that be sufficient? > HTH, > Julien > >> >> 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 >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org