Page 1 of 1

Custom classes for various extensions

Posted: 29 Jun 2009, 21:25
by yaswanth
Hi Guys,

I have a set of classes that are common to all the extensions e.g: To read config, check for webserver session existance etc. And most of them are singletons, so just one instance of them is good enough through out the installation.

Is there a way that all these classes are initialized and are available to all the extensions without they being initiated in the extension's init function?

Say I have a config class:

Code: Select all

class cfg
myConfig = cfg()
Now can I initialize this class and object so that they are available to all the extensions?
If so how do I initialize it? Does something like.

Code: Select all

_server.myConfig
work??

Any help would be appreciated.

Regards,
Yaswanth

P.S> I am using Python to code my extensions :-)

Posted: 30 Jun 2009, 12:47
by Lapo
What you ask is not trivial and requires some extra explanation of the Extensions architecture.

Each extension is loaded in a separate Class Loader (familiar with Java?) so the same classes in two different extension are not the same classes
:?

Confused? Ok
To make it very simple the idea is that each python extension runs a dedicated instance of the Jython engine (the Java python implementation), therefore they cannot share the same classes, especially if we talk about singletons which should be globally available.

With this said, extensions can anyway communicate between them and exchange data. The details are discussed here:
http://www.smartfoxserver.com/docs/docP ... bility.htm

Posted: 02 Jul 2009, 11:32
by yaswanth
Thank you for the reply Lapo.
To make it very simple the idea is that each python extension runs a dedicated instance of the Jython engine
Does that mean that the DB connections that we make through Hibernate also creates separate connections?

Secondly, how does it work when there are dynamic rooms? When each room is started (and each room runs an extension) an instance of Jython engine starts or does just one instance of the extension serves for all the dynamic rooms?

Thanks,
Yaswanth

Posted: 02 Jul 2009, 12:29
by Lapo
Hi,
Does that mean that the DB connections that we make through Hibernate also creates separate connections?
Every query creates a separate connection. However database connections are pooled according the settings you can change in the server config.
Secondly, how does it work when there are dynamic rooms? When each room is started (and each room runs an extension) an instance of Jython engine starts or does just one instance of the extension serves for all the dynamic rooms?
Each room start a separate Jython engine with its scope and local data.