[Pharo-project] Zinc (bug?) - multiple default servers
If you evaluate "ZnServer startDefaultOn: aPortNumber" several times, you end up with that many instances of the default server class. Is that the intended behavior? #default usually = singleton, so I expected all the calls to operate on the same instance. -- View this message in context: http://forum.world.st/Zinc-bug-multiple-default-servers-tp4220409p4220409.ht... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Sean, On 21 Dec 2011, at 04:40, Sean P. DeNigris wrote:
If you evaluate "ZnServer startDefaultOn: aPortNumber" several times, you end up with that many instances of the default server class. Is that the intended behavior? #default usually = singleton, so I expected all the calls to operate on the same instance.
ZnServer>>#defaultOn: aNumber "Create a new Default instance on a given port, stopping any previously running Default and replacing it. Register the new instance." Default ifNotNil: [ Default stop ]. ^ Default := (self on: aNumber) register; yourself Hmm, I never looked at it that way, but now that you mention it, a clearer singleton behavior might make more sense. Note that in any case, only one instance was running. But it might make more sense to really maintain a singleton, the comments should be adapted as well. Thanks for bringing this to my attention. Regards, Sven
Name: Zinc-HTTP-SvenVanCaekenberghe.233 Author: SvenVanCaekenberghe Time: 22 December 2011, 12:54:05 pm UUID: 8dd541c9-2890-4a8f-b5cb-d6ac2e9341af Ancestors: Zinc-HTTP-SvenVanCaekenberghe.232 Rewrote ZnServer and subclasses's class methods #startDefaultOn: and #defaultOn: to treat the default instance like a singleton by reusing/restarting/reconfiguring existing instances; expanded comments; Changed the implementation of ZnServer>>#start to automagically register the default instance; Changed the implementation of ZnServer>>#stop to always unregister; added ZnServer>>#stop: with an option to control the unregistering so that it does not happen when shutting down the image ---- Name: Zinc-Tests-SvenVanCaekenberghe.121 Author: SvenVanCaekenberghe Time: 22 December 2011, 12:56:23 pm UUID: c1396284-0787-4c42-bedd-fb6ae918c68d Ancestors: Zinc-Tests-SvenVanCaekenberghe.120 added ZnServerTests>>#testDefault to test the new semantics of ZnServer class>>#startDefaultOn: --- ZnServerTests>>#testDefault | server | ZnServer stopDefault. self assert: ZnServer default isNil. server := ZnServer startDefaultOn: 1701. self assert: ZnServer default notNil. self assert: ZnServer default == server. self assert: ZnServer default port = 1701. self assert: ZnServer default isRunning. self assert: (ZnServer managedServers includes: server). ZnServer stopDefault. self assert: ZnServer default isNil. self deny: server isRunning. self deny: (ZnServer managedServers includes: server). server := ZnServer startDefaultOn: 1701. "Starting the default again is actually a restart" ZnServer startDefaultOn: 1701. self assert: ZnServer default == server. ZnServer stopDefault On 21 Dec 2011, at 08:26, Sven Van Caekenberghe wrote:
Sean,
On 21 Dec 2011, at 04:40, Sean P. DeNigris wrote:
If you evaluate "ZnServer startDefaultOn: aPortNumber" several times, you end up with that many instances of the default server class. Is that the intended behavior? #default usually = singleton, so I expected all the calls to operate on the same instance.
ZnServer>>#defaultOn: aNumber "Create a new Default instance on a given port, stopping any previously running Default and replacing it. Register the new instance."
Default ifNotNil: [ Default stop ]. ^ Default := (self on: aNumber) register; yourself
Hmm, I never looked at it that way, but now that you mention it, a clearer singleton behavior might make more sense. Note that in any case, only one instance was running. But it might make more sense to really maintain a singleton, the comments should be adapted as well.
Thanks for bringing this to my attention.
Regards,
Sven
thanks http://code.google.com/p/pharo/issues/detail?id=5127 On Dec 22, 2011, at 1:01 PM, Sven Van Caekenberghe wrote:
Name: Zinc-HTTP-SvenVanCaekenberghe.233 Author: SvenVanCaekenberghe Time: 22 December 2011, 12:54:05 pm UUID: 8dd541c9-2890-4a8f-b5cb-d6ac2e9341af Ancestors: Zinc-HTTP-SvenVanCaekenberghe.232
Rewrote ZnServer and subclasses's class methods #startDefaultOn: and #defaultOn: to treat the default instance like a singleton by reusing/restarting/reconfiguring existing instances; expanded comments; Changed the implementation of ZnServer>>#start to automagically register the default instance; Changed the implementation of ZnServer>>#stop to always unregister; added ZnServer>>#stop: with an option to control the unregistering so that it does not happen when shutting down the image
----
Name: Zinc-Tests-SvenVanCaekenberghe.121 Author: SvenVanCaekenberghe Time: 22 December 2011, 12:56:23 pm UUID: c1396284-0787-4c42-bedd-fb6ae918c68d Ancestors: Zinc-Tests-SvenVanCaekenberghe.120
added ZnServerTests>>#testDefault to test the new semantics of ZnServer class>>#startDefaultOn:
---
ZnServerTests>>#testDefault | server | ZnServer stopDefault. self assert: ZnServer default isNil. server := ZnServer startDefaultOn: 1701. self assert: ZnServer default notNil. self assert: ZnServer default == server. self assert: ZnServer default port = 1701. self assert: ZnServer default isRunning. self assert: (ZnServer managedServers includes: server). ZnServer stopDefault. self assert: ZnServer default isNil. self deny: server isRunning. self deny: (ZnServer managedServers includes: server). server := ZnServer startDefaultOn: 1701. "Starting the default again is actually a restart" ZnServer startDefaultOn: 1701. self assert: ZnServer default == server. ZnServer stopDefault
participants (3)
-
Sean P. DeNigris -
Stéphane Ducasse -
Sven Van Caekenberghe