Return-Path: Delivered-To: apmail-felix-dev-archive@www.apache.org Received: (qmail 13615 invoked from network); 1 Jul 2008 19:42:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Jul 2008 19:42:38 -0000 Received: (qmail 56723 invoked by uid 500); 1 Jul 2008 19:42:39 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 56681 invoked by uid 500); 1 Jul 2008 19:42:39 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 56670 invoked by uid 99); 1 Jul 2008 19:42:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jul 2008 12:42:39 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [74.125.44.155] (HELO yx-out-1718.google.com) (74.125.44.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jul 2008 19:41:47 +0000 Received: by yx-out-1718.google.com with SMTP id 4so23549yxp.10 for ; Tue, 01 Jul 2008 12:42:07 -0700 (PDT) Received: by 10.142.180.11 with SMTP id c11mr2636213wff.159.1214941326014; Tue, 01 Jul 2008 12:42:06 -0700 (PDT) Received: from ?192.168.251.5? ( [201.137.34.195]) by mx.google.com with ESMTPS id 29sm15234241wfg.0.2008.07.01.12.42.02 (version=SSLv3 cipher=RC4-MD5); Tue, 01 Jul 2008 12:42:05 -0700 (PDT) Message-Id: <5FC45A62-B083-4433-99AF-8265D2FEB90F@wimpi.net> From: Dieter Wimberger To: dev@felix.apache.org In-Reply-To: <87eb8aee0806280040w775220e5kad711d64d514b032@mail.gmail.com> Content-Type: multipart/signed; boundary=Apple-Mail-4-410904106; micalg=sha1; protocol="application/pkcs7-signature" Mime-Version: 1.0 (Apple Message framework v926) Subject: Re: General questions about starting and stopping bundles Date: Tue, 1 Jul 2008 14:41:45 -0500 References: <3D07940C-36D8-4E9E-B96C-C709B6223D49@wimpi.net> <87eb8aee0806280040w775220e5kad711d64d514b032@mail.gmail.com> X-Mailer: Apple Mail (2.926) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-4-410904106 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Alin: > The specs does not mandate this but I see it as a best practice when > the start method does not return in a "timely manner". Having this > thread also means that you must take care to stop the thread during > BundleActivator.stop as it can be that stop is called before your > starting thread ends. > You are making a good point here, except that I think that "stopping" is maybe not a good choice. Actually it's not recommendable to stop threads at all, it is a thread primitive that has been deprecated a while ago: http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html However, it may make sense to handle this case, and maybe to join the start thread before proceeding with a stop. As a side note, I always found it semantically strange to have "starting" and "stopping" as states (4.3.2 Bundle States), rather than "transitions". >> >> Stopping: >> Knopflerfish seems to assume that when a bundle is stopped, the >> framework >> should be taking care about unregistering services. >> (See "Automatic cleanup of services") >> >> Is this generally valid or container dependent? > > This is mandated by the core specs (section 4.3.6 on specs 4.0.1). > >> Also, does this also apply to Listener instances (like for example a >> ServiceListener) and service references that are being used? >> I.e. is there a need to call BundleContext.removeService/ >> FrameworkListener() >> or m_BundleContext.ungetService() for cleanup? > > In principle you should "undo" what you did during start, so release > resources, stop started threads, ... Good point, with the same exception as above (stopping threads may not be a good idea). > There is no need to unregister services registered during startup or > framework listeners because they will be cleaned up by the framework > after the stop method returns. Also, any services used by the bundle > being stopped will be released automatically by the framework. > But recall that other bundles that still have references to your > service will still be able to call your service so you may wanna play > defense and handle this case even if I consider this a programming > error from the point of view of the bundle that still uses the service > even if the service has been unregistered. When I wanna do that I > usually implement the service using a state service and by the moment > the bundle is stopped or the service s unregistered I change the > internal state of the service to stopped, state where I throw an > meaningful exception. But is a lot of work in plus that does not bring > real value to your service, it only helps the developer of the bundle > that is still using the invalid service to think about the fact that > he should not use anymore the service after it has been unregistered. > I usually try to design the use of other services in a way that allows "come and go". i.e. using a mediated reference instead of obtaining one and holding it; and kind of doing request/response transactions. However, I have come to the conclusion that if state needs to be maintained between calls to a service, then it is actually much more complex to handle (and design for) the "come and go" situation. Regards, Dieter --Apple-Mail-4-410904106 Content-Disposition: attachment; filename=smime.p7s Content-Type: application/pkcs7-signature; name=smime.p7s Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGRDCCAv0w ggJmoAMCAQICECcbNonIuyoFmlfrD6CU/vIwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UEBhMCWkEx JTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0ZSBQ ZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA4MDExNTE5MjcwN1oXDTA5MDExNDE5Mjcw N1owQjEfMB0GA1UEAxMWVGhhd3RlIEZyZWVtYWlsIE1lbWJlcjEfMB0GCSqGSIb3DQEJARYQZGll dGVyQHdpbXBpLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKXikeSvGCZqXLtR Q+GQDBa7XsiJ5M0iYY0y72InsqSMjf7WTea9hyVvtmI4SSih2IwbbxLKbOWpUoT402ykFqyefp45 IRGYHtVVcWfQaTrlgYI3Lg26vV7x4tu6OeOFCsyNRZWST+UAhFKBTWBEyBVER7sQqYoXsJxMXiy7 NblQt+Tdk191j+GunLyk6uONUk0y9CKH4jZWSAnH7U+9/hypcz/brafGZDirOGxgLpa+UunFIWug eEQr5wUl9nRvwaOq+h7jH7CMRgSR9SEFdUTme1SecvJw6zjddZbycE5BsQ1PlUDu7reJ7a/rbDoV Pvus2NXKif16Ay1cZ9S8dcM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