Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-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 366CF104C7 for ; Thu, 8 Aug 2013 14:14:24 +0000 (UTC) Received: (qmail 17432 invoked by uid 500); 8 Aug 2013 14:14:23 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 17296 invoked by uid 500); 8 Aug 2013 14:14:22 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 17288 invoked by uid 99); 8 Aug 2013 14:14:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Aug 2013 14:14:22 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of paul.joseph.davis@gmail.com designates 209.85.214.181 as permitted sender) Received: from [209.85.214.181] (HELO mail-ob0-f181.google.com) (209.85.214.181) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Aug 2013 14:14:17 +0000 Received: by mail-ob0-f181.google.com with SMTP id dn14so5072093obc.26 for ; Thu, 08 Aug 2013 07:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=RE80vNH30YJO9HHQ/EUNQC3xcHOKUzwaurZF/wbdkm0=; b=oR3CNQHNGOzxzUvv/QO5si26GMZsX1udVO/R5DGoeKEoyEn9BbWf+YEtmq6MUTh3Mi fedVoI41gMQtl7sZ2iwFZ72ye/K0jqOmjCdN0IoqtTjLsolyw9rEJ57IZWyJU7ODCmpI 5fOJ9rZU7GZYMLSeWhz/PL6UX72Wi2Pl1ips02BOl1JkfPyUncDQMC8Pgjo9Cgq9EsAY 7brPxz4Lq684VPF+GADLLBcIuBIjc6veQLGLJF19Nzq7eCYOp6VKzjYNo+i6JvAL32+P CeRqBmatspwqTL6OjLcD9ZvD6V97Oig6XV3uo8XfDmF5nU2YROubPSpVONOEbPd6kfor IbEQ== X-Received: by 10.182.176.34 with SMTP id cf2mr6488983obc.45.1375971237126; Thu, 08 Aug 2013 07:13:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.60.121.104 with HTTP; Thu, 8 Aug 2013 07:13:17 -0700 (PDT) In-Reply-To: References: <96FBCC7A-F696-4BD8-9B7B-4126F3B5362A@apache.org> From: Paul Davis Date: Thu, 8 Aug 2013 09:13:17 -0500 Message-ID: Subject: Re: [PLUGINS] Plugin Hooks To: dev@couchdb.apache.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Skimming over it I'm not convinced its any better than just writing a standard Erlang application. There's a bit more boilerplate but I don't see the move to a non-standard Erlang project structure as a net win. On Thu, Aug 8, 2013 at 9:08 AM, Alexander Shorin wrote: > Hi Jan! > > Have you looked at eplugin? Can he be useful? > > https://github.com/Licenser/eplugin > -- > ,,,^..^,,, > > > On Thu, Aug 8, 2013 at 12:47 PM, Jan Lehnardt wrote: >> Heya, >> >> I=92m toying with the idea of moving some of my experimental into >> bona-fide plugins. One of them is my log_to_db branch that on top of >> writing log messages to a text file also writes a document to a log >> database. >> >> Conceptually, this is the perfect use of a plugin: the feature is not >> useful in the general case, because *any* activity creates write load >> on a single database, but for certain low-volume installations, this >> might be a useful feature (I wouldn=92t have written it, if I hadn=92t >> needed it at some point) so allowing users to enable it as a plugin >> would be nice. >> >> But regardless of whether my plugin is useful, it illustrates an >> interesting point: >> >> A log_to_db plugin would need to register for logging events or, if it >> doesn=92t want to duplicate all the logging-level logic in couch_log, it >> would need some way of injecting a function call into >> `couch_log:log().`. We could of course try and find a way where a >> plugin would be able to provide an API compatible version of a CouchDB >> module and swap it out for it=92s custom one, but that=92s hardly a grea= t >> idea. >> >> Other software has the notion of =93hooks=94 (some may call it something >> else) where at well defined points in the main code base, external >> functions get called with certain parameters. To make things dynamic, >> there might be a way for plugins to register to be called by those >> hooks and the main code then asks the registry whether there are any >> plugin functions to call. >> >> In the log_to_db example, we=92d have something like this: >> >> couch_log_to_db.erl: >> >> init() -> >> couch_hooks:register(couch_log_hook, log_hook_fun/1), >> ok. >> >> log_hook_fun(Log) -> >> % do the log_to_db magic >> ok. >> >> >> couch_hooks.erl: >> >> register(Hook, Fun) -> >> % store the Fun with the Hook somewhere >> ok. >> >> call(Hook, Args) -> >> % retrieve Fun for Hook from somewhere >> Fun(Args). >> >> couch_log.erl: >> >> % in log() >> >> ... >> couch_hooks:call(couch_log_hook, Args), >> ... >> >> The main code would define what the hook name and arguments are and the >> plugin would have to conform. The plugin registry would just manage the >> registration and calling of functions for a hook, but nothing more. >> >> * * * >> >> This is just my first stab at this not thinking about it too much and I >> likely miss some subtleties in Erlang that make this not work (hot code >> upgrades e.g.). >> >> >> How do you think we should implement a hooks feature in CouchDB? >> >> >> Thanks! >> Jan >> -- >> >> >> >>