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 D062110CC7 for ; Thu, 8 Aug 2013 10:40:12 +0000 (UTC) Received: (qmail 57231 invoked by uid 500); 8 Aug 2013 10:40:12 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 57206 invoked by uid 500); 8 Aug 2013 10:40:12 -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 57195 invoked by uid 99); 8 Aug 2013 10:40:12 -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:40:12 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jason.h.smith@gmail.com designates 209.85.219.45 as permitted sender) Received: from [209.85.219.45] (HELO mail-oa0-f45.google.com) (209.85.219.45) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Aug 2013 10:40:05 +0000 Received: by mail-oa0-f45.google.com with SMTP id m1so4992580oag.4 for ; Thu, 08 Aug 2013 03:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=xXL64tJeLAX8xehEzB2EzqgtDnShVoc2qEtg5DeIhWY=; b=nbfIjKFr4ah6s1mTqv5Kv/YPN1FjuFg3n7vRqQdVsbwvbHZ2jo/7jXLLXe8nQbpbaf RysxtGfZgJFigz9F8Jm4tMMTgSgl32WhYPw5Fjqe5Rrb7LqQvgqxySQQQyIerUAP+tku 90pO9yUDgoi9dyinQgYB/Dd0Yz/TD5QVt4iNg7D1sZy4M9cbdjymVi9zhJ0EyKpuS6Kv TbvJgWoqsvBBpRTPRHc1eXy+b8gbDOYnyo1+aHxI42bugCx83xbi6luLfFaanIGd8RZa y76Mf4ZIQ3sCwgdfY1ruM26gs3O3mAyA56Xg6IWpJy4c/uhPb+hyqfMPjgxJHayJsEek jdxA== X-Received: by 10.60.56.3 with SMTP id w3mr3856802oep.37.1375958383812; Thu, 08 Aug 2013 03:39:43 -0700 (PDT) MIME-Version: 1.0 Sender: jason.h.smith@gmail.com Received: by 10.182.103.133 with HTTP; Thu, 8 Aug 2013 03:39:23 -0700 (PDT) In-Reply-To: <001BB5DC-23F7-4BEB-9553-09DCF4F9F5CB@apache.org> References: <96FBCC7A-F696-4BD8-9B7B-4126F3B5362A@apache.org> <001BB5DC-23F7-4BEB-9553-09DCF4F9F5CB@apache.org> From: Jason Smith Date: Thu, 8 Aug 2013 17:39:23 +0700 X-Google-Sender-Auth: DAXiVzCMQNT0mQsCxX_sQfLAzPY Message-ID: Subject: Re: [PLUGINS] Plugin Hooks To: "dev@couchdb.apache.org" Content-Type: multipart/alternative; boundary=001a11c20a72b1666104e36d4657 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c20a72b1666104e36d4657 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Well, I just googled it. Basically there is a couchdb_plugin.erl which tells Erlang what a behavior looks like. And all that does is define the functions and arity which a couchdb_plugin would have to export. Probably there are some better Erlangers on the list who might chime in. It looks like okay bang-for-buck; only not much bang or much buck. On Thu, Aug 8, 2013 at 5:26 PM, Jan Lehnardt wrote: > 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? > > > > -behaviour(couchdb_plugin). > > > > > > > > On Thu, Aug 8, 2013 at 3:47 PM, Jan Lehnardt wrote: > > > >> Heya, > >> > >> I=E2=80=99m toying with the idea of moving some of my experimental int= o > >> 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=E2=80=99t have written it, if I ha= dn=E2=80=99t > >> 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=E2=80=99t 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=E2=80=99s custom one, but that=E2=80=99s= hardly a great > >> idea. > >> > >> Other software has the notion of =E2=80=9Chooks=E2=80=9D (some may cal= l 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=E2=80=99d 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 th= e > >> plugin would have to conform. The plugin registry would just manage th= e > >> 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 cod= e > >> upgrades e.g.). > >> > >> > >> How do you think we should implement a hooks feature in CouchDB? > >> > >> > >> Thanks! > >> Jan > >> -- > >> > >> > >> > >> > >> > > --001a11c20a72b1666104e36d4657--