Dynamic Loading of Modules
Niklas Elmqvist
d97elm at dtek.chalmers.se
Wed Feb 25 07:26:37 CET 1998
On Tue, 24 Feb 1998, Vadim Tkachenko wrote:
> Niklas Elmqvist wrote:
> > If you are wondering what the fuss is all about (or why this posting is
> > getting so long), let me just say this: One application of this could be
> > an Event class (in an event-driven system), whose base class is known to
> > the core server (allowing for it to check the priority and expiration of
> > the event, among other things), while the modules can inherit from the
> > base class and redefine it to suit their particular needs. I also plan on
> > using this technique for Handler objects which take care of things such as
> > socket I/O, parsing, DB managment, etc, and the good thing about it is
> > that I thus will be able to attach and detach the modules at run-time (to
> > remedy a bug, for example). If the base classes are correctly implemented,
> > the core will never even have to be recompiled and thus never rebooted
> > (not accounting for fatal bugs, that is <g>)!
>
> Not quite so.
>
> See, I use almost exactly the same technique in my Java development,
> and indeed, it's possible, using Class.forName( ... ), instantiate the
> absolutely unknown before classes - in fact, I suspect that the other
> guy, who lives at http://www.wwwalker.com/, used this technique to
> produce applets at least a year ago, but his technique seems to be even
> more pervert - he compiles classes on-demand, and then actually loads
> them.
That'd be really useful in some contexts, but not, I believe, in my MUD
server :)
> The weak point for me is that once you load the class, it's extremely
> difficult to UNLOAD it.
> I've heard that the guys who write the servlet support for Apache
> managed to write the custom ClassLoader to do that, but didn't have time
> to dig it myself.
The web server Apache, I presume? Never toyed around with this, but on a
side note I would like to add that the module system of Apache, although
useful and stable, could be done *much* better. The mods are linked to
the main binary at link-time, so you still have to recompile and reboot to
incorporate new mods. Of course, since a web server
> How do you handle this?
Fortunately, as I am developing my server in C++ on a Linux system, I have
access to the dynamic loading package (originally derived from Solaris, I
believe). To dynamically load a shared binary I simply do a dlopen(), to
retrieve a symbol (such as a function pointer) from the lib I do dlsym(),
and to unload the entire lib I do a dlclose(). Check out the manpages for
these functions to get an in-depth description.
However, since I have preciously little experience with Java, I cannot
help you in that matter.
-- Niklas Elmqvist (d97elm at dtek.chalmers.se) ----------------------
"You can't trample infidels when you're a tortoise. I mean, all you
could do is give them a meaningful look."
- Terry Pratchett, Small Gods
More information about the mud-dev-archive
mailing list