How to get reference to extension level class loader?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

xitegma
Posts: 4
Joined: 02 Dec 2021, 00:37

How to get reference to extension level class loader?

Postby xitegma » 02 Dec 2021, 00:49

Regarding this article http://docs2x.smartfoxserver.com/ExtensionsJava/advanced-concepts under section "Class loading architecture" on the picture there is extension class loader shown specific gfor each extension.

For contenxt: im using org.reflections library to query available classes and find classes that i need.
Project is divided into multiple modules and in each module i have dummy class, so i can get the reference to that module classes through classloader.
Whem im instancing org.reflections library im passing that dummy classes to it and it seems to work fine until i have multiple extension running.
And it seems that im only able to find classes that was loaded last as far as i know because classloader keeps the last version of class if it finds duplicates.
For example: if i have zone A and zone B both running exact same extension jar build and zone B will initialize last - org.reflections library will find zone B classes when extensions ran.
It seems to me that for some reason im passing "global" extension class loader and that why it can find classes of zone that was loaded last.
Im wondering - how can i get a reference to specific zone classloader? So each time org.reflections library is used it will query its extension classes.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get reference to extension level class loader?

Postby Lapo » 02 Dec 2021, 10:27

Hi,
I am not familiar with this org.reflection library. The JDK already provide this feature, are you referring to the native Java reflection, perhaps?

Also it's not very clear what you're trying to accomplish and why doing it via reflection, which is pretty slow and complicated to use with multiple class loaders.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
xitegma
Posts: 4
Joined: 02 Dec 2021, 00:37

Re: How to get reference to extension level class loader?

Postby xitegma » 02 Dec 2021, 11:09

I'm reffering to this reflections library https://mvnrepository.com/artifact/org.reflections/reflections
I'm trying to make use of simple di container that i wrote, which works with Reflections (kinda similair to Spring, just bare bones), im marking my services with annotation to bind them in container.
Reflection is only used at startup, so it doesnt really affect performance.
Strangest thing is that everything worked already flawlessly right before ive decided to split project into different modules.
When everything was in single module - reflections works fine, ive just instantiated this library without any dummy classes and it worked as intended (means loading classes from extension where archive was deployed).

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 37 guests