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 01A9310C69 for ; Thu, 8 Aug 2013 10:27:36 +0000 (UTC) Received: (qmail 40434 invoked by uid 500); 8 Aug 2013 10:27:35 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 40235 invoked by uid 500); 8 Aug 2013 10:27:35 -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 40199 invoked by uid 99); 8 Aug 2013 10:27:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Aug 2013 10:27:24 +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 [80.244.253.218] (HELO mail.traeumt.net) (80.244.253.218) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Aug 2013 10:27:17 +0000 Received: from rose.railnet.train (unknown [88.128.80.7]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.traeumt.net (Postfix) with ESMTPSA id 552DE140D1 for ; Thu, 8 Aug 2013 12:28:46 +0200 (CEST) From: Jan Lehnardt Content-Type: multipart/signed; boundary="Apple-Mail=_03B7B9A8-665F-459C-8886-06886547C6F0"; protocol="application/pgp-signature"; micalg=pgp-sha1 Message-Id: <001BB5DC-23F7-4BEB-9553-09DCF4F9F5CB@apache.org> Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: [PLUGINS] Plugin Hooks Date: Thu, 8 Aug 2013 12:26:35 +0200 References: <96FBCC7A-F696-4BD8-9B7B-4126F3B5362A@apache.org> To: dev@couchdb.apache.org In-Reply-To: X-Mailer: Apple Mail (2.1508) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail=_03B7B9A8-665F-459C-8886-06886547C6F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 how would this look in code? On Aug 8, 2013, at 12:21 , Jason Smith wrote: > Perhaps a custom behaviour to help catch API problems at compile time? >=20 > -behaviour(couchdb_plugin). >=20 >=20 >=20 > On Thu, Aug 8, 2013 at 3:47 PM, Jan Lehnardt wrote: >=20 >> Heya, >>=20 >> 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. >>=20 >> 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. >>=20 >> But regardless of whether my plugin is useful, it illustrates an >> interesting point: >>=20 >> 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 = great >> idea. >>=20 >> 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. >>=20 >> In the log_to_db example, we=92d have something like this: >>=20 >> couch_log_to_db.erl: >>=20 >> init() -> >> couch_hooks:register(couch_log_hook, log_hook_fun/1), >> ok. >>=20 >> log_hook_fun(Log) -> >> % do the log_to_db magic >> ok. >>=20 >>=20 >> couch_hooks.erl: >>=20 >> register(Hook, Fun) -> >> % store the Fun with the Hook somewhere >> ok. >>=20 >> call(Hook, Args) -> >> % retrieve Fun for Hook from somewhere >> Fun(Args). >>=20 >> couch_log.erl: >>=20 >> % in log() >>=20 >> ... >> couch_hooks:call(couch_log_hook, Args), >> ... >>=20 >> 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. >>=20 >> * * * >>=20 >> 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.). >>=20 >>=20 >> How do you think we should implement a hooks feature in CouchDB? >>=20 >>=20 >> Thanks! >> Jan >> -- >>=20 >>=20 >>=20 >>=20 >>=20 --Apple-Mail=_03B7B9A8-665F-459C-8886-06886547C6F0 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iEYEARECAAYFAlIDclsACgkQ7KW8t7uWVrA/XACgxONU7S22cK885YH2W5UsmTqw iFoAn0++8O7IoAEGa/yT164DWhz8WJzA =FIGb -----END PGP SIGNATURE----- --Apple-Mail=_03B7B9A8-665F-459C-8886-06886547C6F0--