Saving configurations / class loader problems

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Saving configurations / class loader problems

Post by Hyrelius »

L2J Revision: 6241
L2JDP Revision: 9976

Hi there,

I'm currently having several scripts, that basically enable the player to have certain additional settings e.g. script-specific settings, that are created for every player, who has activated that script.

Currently I have a configurations-script, which is a central point for loading and saving additional settings.

However, I have several problems:
  • configurations-script is loaded by a different? class-loader (in-memory class-loader, default L2Script-loader) and thus cannot see other scripts (unless it creates another instance of those script, but this is not an option)
  • all other scripts can access the configurations-script, but they create a new instance each time, even though the configuration-script is built as a singleton; it seems the singletons are not real singletons, because different class-loaders load or try to access the class(es)
  • reflections in scripts do not work
I'd love to keep changes to the core and datapack as small as possible in order to be able to easily update the server. Yet still I have to build a way to keep player-specific settings available to all scripts and allow all scripts to modify the settings so that another script can read those settings (synergy-effect between the scripts).

I do know of a way to do so, but I want to avoid having to code it all into the Config-class or similar. I'd like to have a script if possible, because scripts are "optional". Is there a way to implement something like a "true singleton" in order to keep player- and script-specific settings available and adjustable to/by all scripts?

Perhaps I should learn more about the scripting engine and how it's built, but I'm afraid, that I'll end up recognizing, that it uses different class-loaders and hence the only solution would be to make the additional configuration available before any scripts are loaded - which would involve modifying the core.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Saving configurations / class loader problems

Post by jurchiks »

how about you just add a new class in core? smth like "CustomConfig" right next to the normal Config? Wouldn't mess syncing but would work for what you need.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: Saving configurations / class loader problems

Post by Hyrelius »

Yes - it sounds like an option.
The problem however is, that I'd have to maintain this script inside the Core-project. By maintaining I mean create e.g. DTOs, which work as holders, that I send one way or another. Perhaps I could even create dynamic beans from the XML file, but it still sounds a bit weird. Then again I guess there's no way to circumvent the class-loader problem other than this.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Saving configurations / class loader problems

Post by jurchiks »

It's a known problem in the ecj (eclipse compiler for java), which l2j uses for its dynamic script loading. Not sure if anyone has created a bug ticket in their tracker for it... Also not sure if the lib has been updated/if l2j has kept it up to date.
You could try finding a different compiler, but I don't think you're interested in that.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Saving configurations / class loader problems

Post by UnAfraid »

The problem is kinda general actually..
Each class get's loaded in separate class loader because u can't edit a class inside the class loader unless u're in debug mode (And u can't edit it's structure).
So the only way is to drop the whole class loader and initiate new one with the new class.
If we had shared class loader u could forget about script reloading..
Image
Post Reply