Return-Path: X-Original-To: apmail-zest-dev-archive@minotaur.apache.org Delivered-To: apmail-zest-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 295E818B13 for ; Thu, 3 Dec 2015 15:48:52 +0000 (UTC) Received: (qmail 75227 invoked by uid 500); 3 Dec 2015 15:48:51 -0000 Delivered-To: apmail-zest-dev-archive@zest.apache.org Received: (qmail 75188 invoked by uid 500); 3 Dec 2015 15:48:51 -0000 Mailing-List: contact dev-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list dev@zest.apache.org Received: (qmail 75164 invoked by uid 99); 3 Dec 2015 15:48:51 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2015 15:48:51 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 0B351180AFA for ; Thu, 3 Dec 2015 15:48:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.121 X-Spam-Level: X-Spam-Status: No, score=-0.121 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id pmYTk_6XvUik for ; Thu, 3 Dec 2015 15:48:49 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 4CBDF232E0 for ; Thu, 3 Dec 2015 15:48:49 +0000 (UTC) Received: by lbbkw15 with SMTP id kw15so4112858lbb.0 for ; Thu, 03 Dec 2015 07:48:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=ipdQGgThXqVHN9+1QLZh8h85YpCamJQpJKt3Y3konOE=; b=tLwM60mXEse5rn3d/XEHYihG4YJtWK7eHAdTYy0lElKM9VBzHlw66kc3vyQBYtNJNa OwCWDw/z6gF/yWTjMKUqzHHOKX0gLQDWEl+PBEmrdOD90BqSA/XrAUE62OjXHx2afi33 hoWsdvmmacmwJgWYcRiOQQaU9ChY9tD7kylLTXUhr4QyRXYrsh1ReY/g9LY3DMelVQ48 rTg53VYKfbWPq6wWhaopxU4j7Cdp4YcvCmDfK2VldR8msDajS116fLXcwSEM6zjzLob+ JYOf1Nkm6gDgvg3MNclFCjle7Rt4u7D9rxMjKkubacq8rU6PMPtBQRjjrXGBGUM8ZUUL rBbQ== X-Received: by 10.112.199.194 with SMTP id jm2mr5140195lbc.109.1449157727568; Thu, 03 Dec 2015 07:48:47 -0800 (PST) Received: from [192.168.1.10] (x1-6-2c-b0-5d-ac-a5-ea.cpe.webspeed.dk. [62.243.119.227]) by smtp.googlemail.com with ESMTPSA id bm8sm1479341lbb.35.2015.12.03.07.48.46 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Dec 2015 07:48:47 -0800 (PST) Subject: Re: [Discuss] Object lifecycles... To: dev@zest.apache.org References: <56604EFA.8010208@zest.mail.kapsi.fi> From: =?UTF-8?Q?Kent_S=c3=b8lvsten?= X-Enigmail-Draft-Status: N1110 Message-ID: <56606464.6050905@gmail.com> Date: Thu, 3 Dec 2015 16:48:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <56604EFA.8010208@zest.mail.kapsi.fi> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit interesting.... My previous P.O.V was that we should support the equivalent of [Prototype] .... for mixins . Do you have some example use-cases from Qi4CS explaining the usage of [Initialize], or lifecycle methods on other fragment types? /Kent Den 03-12-2015 kl. 15:17 skrev Stanislav Muhametsin: > On 3.12.2015 9:38, Niclas Hedhman wrote: >> Gang, >> >> 1. Should Initializable.initalize() be invoked on prototypeFor()? >> >> At the moment, when prototypeFor() (and prototype() I guess) is >> called on >> TransientBuilder (probably ValueBuilder as well), the mixin's >> initialize() >> will be called. >> That means that the Composite is not really available (predictably) >> to the >> Mixin at this point. > > In Qi4CS, I have [Initialize] and [Prototype] attributes (@Initialize > and @Prototype annotations in Java). > Methods on fragments marked with these attributes will be invoked by > Qi4CS runtime in the following logic: > 1. Methods marked with [Initialize] will be invoked the first time > fragment is created (be it during prototype stage, or composite > creation), right after its constructor finishes executing. > 2. Methods marked with [Prototype] will be invoked when the > CompositeBuilder actually creates composite instance (prototype stage > ends), during its NewInstance() method. > > Naming is maybe not optimal, but I think you get the general idea. > The concept on not having interfaces and instead using attributes > (annotations) stems from rather old e-mail from you, Niclas. > I see you have revisited this idea later in this mail. :) > >> >> 2. Do we have a solid object lifecycle story at all?? >> >> While writing this mail, I start to think that the object lifecycle >> model >> is severely flawed, and possibly not easily fixed here and there. >> >> I think we need to dig through the requirements from the ground up. I >> think >> that the Fragments and the Composite need to be separated. >> >> I also wonder if we can indeed utilize finalize(), to get pre/post >> semantics uniformly across all composite meta types... Does anyone >> have a >> very strong understanding of how finalize() works, and why it is said >> to be >> "bad" to use it in programs?? > > Java's 'finalize' and C#'s destructors are very tricky, because most > assumptions that are valid during normal program flow, are not valid > in finalizers/destructors. > For example, in C#, the destructors are always run from within > dedicated finalizer thread (I don't know if Java does that). > Additionally, the fields of object during finalization/destruction > might point to already finalized objects, which can and usually does > cause a lot of subtle bugs. > > Personally, I've taken the stance recommended by C# - only use > destructors if your object needs to free native resources when it is > no longer used. > >> >> What I would like to see is pairs of annotations with strong semantics, >> something like (maybe better names) >> >> @OnEntityCreation // called on EntityBuilder.newInstance() >> @OnEntityDeletion // called on UnitOfWork.remove() >> >> @OnCompositeConstruction // called when in-memory instance created >> @OnCompositeDestruction // called via finalize() or UnitOfWork >> teardown. >> >> @OnMixinCreation // Called after Mixin constructor call. >> @OnMixinDestruction // called via @OnCompositeDestruction >> >> I am not sure if we need to separate the prototype/prototypeFor creation >> from the instantiation of 'final' Mixin instance that goes into the >> Composite. >> >> And in the process "fix" the ServiceComposite story as well, i.e. >> >> @OnServiceActivation >> @OnServicePassivation >> >> And in the process get rid of the all the related interfaces; >> Initializable >> Lifecycle >> Activatable >> ServiceActivator >> >> and so on. >> >> Any thoughts? > > I think annotations are excellent idea, and they have worked for me in > Qi4CS very well. > One thing you need to be careful of, is in which order you invoke > them: base-class-first or bottommost-class-first in class inheritance > hierarchy. > IIRC Qi4CS invokes the attributed (annotated) methods with > base-class-first strategy. > If a single class contains multiple methods marked with same > attribute, the order is whichever way they are returned by reflection > (this is checked only once - during code generation, once code is > generated, the order will always be the same). > > One very good thing (which you pointed out in the old e-mail) is that > attributed (annotated) methods can have parameter injections, and if > these injected values are used *only* in the lifecycle stage indicated > by attribute (annotation), then you don't need to have these > injections in fields. > >> >> >> Cheers >