Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WebGUI
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kieker
WebGUI
Commits
6bb09c62
Commit
6bb09c62
authored
12 years ago
by
Nils Christian Ehmke
Browse files
Options
Downloads
Patches
Plain Diff
Modified the plugin class loader.
parent
7139168b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginClassLoader.java
+14
-34
14 additions, 34 deletions
...src/main/java/kieker/webgui/common/PluginClassLoader.java
with
14 additions
and
34 deletions
Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginClassLoader.java
+
14
−
34
View file @
6bb09c62
...
...
@@ -25,6 +25,7 @@ import java.net.URL;
import
java.net.URLClassLoader
;
import
java.security.AccessController
;
import
java.security.PrivilegedAction
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
...
...
@@ -52,15 +53,17 @@ public final class PluginClassLoader extends ClassLoader {
* The singleton instance of this class.
*/
private
static
PluginClassLoader
instance
;
/**
* This list contains a class loader for each url added to this class loader.
*/
private
final
Map
<
String
,
URLClassLoader
>
classLoaders
=
new
HashMap
<
String
,
URLClassLoader
>();
private
final
List
<
URL
>
list
=
new
ArrayList
<
URL
>();
private
URLClassLoader
classLoader
=
null
;
/**
* The default constructor of this class. During the creation all available libraries will be added to the class loader.
*/
private
PluginClassLoader
()
{
classLoader
=
AnalysisController
.
class
.
getClassLoader
();
/* Make sure that all libs are loaded. */
final
List
<
MIDependency
>
libs
=
FileManager
.
getInstance
().
loadAllDependencies
();
for
(
final
MIDependency
lib
:
libs
)
{
...
...
@@ -79,15 +82,9 @@ public final class PluginClassLoader extends ClassLoader {
* The URL of the dependency to be added.
*/
public
void
addURL
(
final
URL
url
)
{
/* Create the new class loader within a privileged block. */
final
URLClassLoader
newClassLoader
=
(
URLClassLoader
)
AccessController
.
doPrivileged
(
new
PrivilegedAction
()
{
@Override
public
Object
run
()
{
return
new
URLClassLoader
(
new
URL
[]
{
url
},
AnalysisController
.
class
.
getClassLoader
());
}
});
this
.
classLoaders
.
put
(
url
.
toString
(),
newClassLoader
);
list
.
add
(
url
);
classLoader
=
new
URLClassLoader
(
list
.
toArray
(
new
URL
[
list
.
size
()]),
AnalysisController
.
class
.
getClassLoader
());
}
/**
...
...
@@ -97,7 +94,9 @@ public final class PluginClassLoader extends ClassLoader {
* The URL of the dependency to be added.
*/
public
void
removeURL
(
final
URL
url
)
{
// TODO Implement
list
.
remove
(
url
);
classLoader
=
new
URLClassLoader
(
list
.
toArray
(
new
URL
[
list
.
size
()]),
AnalysisController
.
class
.
getClassLoader
());
}
/**
...
...
@@ -131,25 +130,6 @@ public final class PluginClassLoader extends ClassLoader {
*/
@Override
public
Class
<?>
loadClass
(
final
String
name
)
throws
ClassNotFoundException
{
try
{
return
ClassLoader
.
getSystemClassLoader
().
loadClass
(
name
);
}
catch
(
final
ClassNotFoundException
ex
)
{
/* Ignore exception. */
}
synchronized
(
this
)
{
/* Run through all available class loaders and try to find the correct class. */
final
Iterator
<
URLClassLoader
>
classLoaderIter
=
this
.
classLoaders
.
values
().
iterator
();
while
(
classLoaderIter
.
hasNext
())
{
final
URLClassLoader
currClassLoader
=
classLoaderIter
.
next
();
/* If no exception is thrown, we found the correct class and return it. Otherwise we continue the search. */
try
{
return
currClassLoader
.
loadClass
(
name
);
}
catch
(
final
ClassNotFoundException
ex
)
{
// Ignore error
}
}
}
/* We were not able to found any class and throw an exception. */
throw
new
ClassNotFoundException
();
return
classLoader
.
loadClass
(
name
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment