Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Problem with Classloading and Bundles
Problem with Classloading and Bundles [message #46171] Fri, 03 December 2004 15:49
Eclipse UserFriend
Originally posted by: buhla2.hta-bi.bfh.ch

hello!

i have a question regarding classloading and bundles/plugins.
in our plugin we have to load libraries bundles/plugins to work
with different kind of application servers like jb3 and jb4.

the individual libraries bundle contain a connector implementation
(coded by us) along with the specific libraries of the particular
application server. of course both things are in different packages
in our bundle and the connector is exported but the libraries are
not because only our connector implementation use those libraries
internally. The libraries bundle are created by our bundle creator
in a dynamically fashion.

the connector actually works fine for individual connection e.g.
to jb3 and jb4 (also concurrently) as long as the corresponding
libraries for each server type has been chosen correctly... that
means 3.x libs for jb3 and 4.x libs for jb4.

the problem arises if one choses a wrong library (e.g. the jars
for jb4 when trying to create a connection to a jb3 server) for
a particular connection type. after the confirmation of an
error message dialog he then choses the correct lib an tries
again... but the wrong lib is still beeing used.
is there a memory optimization which keeps the loaded libs in the
memory if they have the same signatures (but unfortunately
different signatures like the jb3 and jb4 libs)? does someone
have an idea why the old (wrong) libs are accessed instead of
the new ones? The bundle's uninstall method doesn't work
when that methods is called in the case of an exception.

The following code shows the connector singleton that creates the
libraries bundle. The shown method is colled for all connection
types but with different csi objects which contains the
setup info. the info objects contain the correct info in every
invocation (also those correct ones after an erronous invocation
when chosing a wrong lib). Somehow the libs are resistent in memory
and for each type its first created bundle is used again for all
further connection setups of the same type. the problem therefore
arises when chosen a wrong lib when the first connection is created
then al later tries (with correct libs) will also fail. does
anyone have an idea why the first chosen lib is chosed ever and
ever again? the connection implementation is not a normal class
(not a singleton or whatever) i. the manifest of a lib bundle
looks like that:

Bundle-Activator:
ch.bfh.jmxconsole.connectors.jsr77.internal.jb3.ConnectionIm plJB3
Bundle-ClassPath: /ConnectionImpl.jar, /jbossall-client.jar
Import-Package: ch.bfh.jmxconsole.core, ch.bfh.jmxconsole.core.connection,
ch.bfh.jmxconsole.core.jmx, ch.bfh.jmxconsole.connectors.jsr77,
org.osgi.framework, ch.bfh.jmxconsole.core.model.extension.jndi
Export-Package: ch.bfh.jmxconsole.connectors.jsr77.internal.jb3



the code that creates the lib bundles looks like that:

public Connection createConnection(ConnectionSetupInfo csi) throws
CreateConnectionException {
try {
int typeID = csi.getConnectionTypeID();
String activator;

File connectionImpl =
JSR77ConnectorPlugin.getJarFile(CONNECTION_JAR_FILE);
File[] libs = csi.getLibraries();
if (typeID == TYPE0) {
activator =
" ch.bfh.jmxconsole.connectors.jsr77.internal.custom.Connectio nImplCustom ";
} else if (typeID == TYPE1) {
activator =
" ch.bfh.jmxconsole.connectors.jsr77.internal.jb3.ConnectionIm plJB3 ";
} else if (typeID == TYPE2) {
activator =
" ch.bfh.jmxconsole.connectors.jsr77.internal.jb4.ConnectionIm plJB4 ";
} else if (typeID == TYPE3) {
activator =
" ch.bfh.jmxconsole.connectors.jsr77.internal.sjsas.Connection ImplSJSAS ";
}
String bundlePath = BundleCreator.createBundle(activator, connectionImpl,
libs, IMPORTS, new String[] {activator.substring(0,
activator.lastIndexOf("."))});
Bundle bundle = JSR77ConnectorPlugin.installBundle(bundlePath);
bundle.start();
BundleCreator.deleteBundle(bundlePath.substring(5));

Class connectionClass = bundle.loadClass(activator);
Object connection = connectionClass.newInstance();
Method mSetCSI = connectionClass.getMethod("setCSI",
new Class[] {ConnectionSetupInfo.class});
mSetCSI.invoke(connection, new Object[] {csi});
Method mSetBundle = connectionClass.getMethod("setBundle",
new Class[] {Bundle.class});
mSetBundle.invoke(connection, new Object[] {bundle});

return (Connection) connection;
} catch (CreateBundleException cbe) {
throw new CreateConnectionException(cbe.getMessage());
} catch (Exception e) {
throw new CreateConnectionException("An error occurred while trying to
" +
"establish a connection.");
}
}




thanks!

alex
Previous Topic:Eclipse based web applications
Next Topic:Discussion of Classloaders for (de) serialization
Goto Forum:
  


Current Time: Fri Sep 20 14:55:50 GMT 2024

Powered by FUDForum. Page generated in 0.04059 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top