The same singleton between different zone

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

jiaxintang
Posts: 7
Joined: 29 Nov 2008, 16:48

The same singleton between different zone

Postby jiaxintang » 17 Jun 2009, 13:26

I use a singleton to keep some config data I load when server start up. But I found that the different zones on the same server will share the singleton.

For example:
Class ConfigData is a singleton class
Class ZoneExt is the zone extension.
I put the ConfigData.getInstance() in ZoneExt.init(). I have two zones named 'zone1' and 'zone2', they all load ZoneExt. When I start up the SFS server, I can see the log info: ConfigData.hashcode are the same.

How can I use different memory space between different zone?

Thanks.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Jun 2009, 19:09

Actually this should be the proper behaviour of a Singleton, one and only one instance of it should exist across the whole JVM.

Anyways, you can accomplish what you are trying to do by simply removing
the javaExtensions/ folder from the classpath. By doing this you avoid that the system ClassLoader "sees" your classes.

Each extension is loaded in its own Class Loader so you will obtain that each Singleton will be unique for each extension and not shared across all of them.

If you run the server in standalone mode (start.bat or star.sh) you should edit the classpath in the start script

If you run the server as service/daemon you should edit the classpath in the Server/conf/wrapper.conf file
Lapo
--
gotoAndPlay()
...addicted to flash games
jiaxintang
Posts: 7
Joined: 29 Nov 2008, 16:48

Postby jiaxintang » 18 Jun 2009, 00:23

It works. Thank you.
abacus
Posts: 12
Joined: 07 Oct 2008, 10:42

Re: The same singleton between different zone

Postby abacus » 28 Dec 2010, 06:40

jiaxintang wrote:I use a singleton to keep some config data I load when server start up. But I found that the different zones on the same server will share the singleton.

For example:
Class ConfigData is a singleton class
Class ZoneExt is the zone extension.
I put the ConfigData.getInstance() in ZoneExt.init(). I have two zones named 'zone1' and 'zone2', they all load ZoneExt. When I start up the SFS server, I can see the log info: ConfigData.hashcode are the same.

How can I use different memory space between different zone?

Thanks.


I have just upgraded from SmartFox Server Version 1.6.5 to 1.6.6 and found that every extension is creating a new object of a singleton class rather than limiting to just one object across JVM.

This defies the entire purpose of singleton class that needs to be shared across the extensions.

Can you please help me with this?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 28 Dec 2010, 09:17

You need to add the extensions folder in the classpath, thus avoiding class loader isolation.

See the previous response:
viewtopic.php?p=22148#22148
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 21 guests