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
18c0eefc
Commit
18c0eefc
authored
12 years ago
by
Nils Christian Ehmke
Browse files
Options
Downloads
Patches
Plain Diff
Classloader issue
parent
acf1eb36
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/persistence/impl/FSProjectDAOImpl.java
+61
-15
61 additions, 15 deletions
...java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java
with
61 additions
and
15 deletions
Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java
+
61
−
15
View file @
18c0eefc
...
@@ -38,9 +38,12 @@ import java.util.Map.Entry;
...
@@ -38,9 +38,12 @@ import java.util.Map.Entry;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.FileSystemUtils
;
import
org.springframework.util.WeakReferenceMonitor
;
import
org.springframework.util.WeakReferenceMonitor
;
import
org.springframework.util.WeakReferenceMonitor.ReleaseListener
;
import
org.springframework.util.WeakReferenceMonitor.ReleaseListener
;
...
@@ -75,6 +78,7 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -75,6 +78,7 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
private
static
final
String
LIB_EXTENSION
=
"jar"
;
private
static
final
String
LIB_EXTENSION
=
"jar"
;
private
static
final
String
LIB_DIRECTORY
=
"lib"
;
private
static
final
String
LIB_DIRECTORY
=
"lib"
;
private
static
final
String
ROOT_DIRECTORY
=
"data"
;
private
static
final
String
ROOT_DIRECTORY
=
"data"
;
private
static
final
String
TEMP_DIRECTORY
=
"temp"
;
/**
/**
* The library for kieker which is contained in the war-file as a resource.
* The library for kieker which is contained in the war-file as a resource.
*/
*/
...
@@ -86,6 +90,7 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -86,6 +90,7 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
private
final
MIAnalysisMetaModelFactory
factory
=
new
MAnalysisMetaModelFactory
();
private
final
MIAnalysisMetaModelFactory
factory
=
new
MAnalysisMetaModelFactory
();
private
final
Map
<
CloseableURLClassLoader
,
WeakReference
<
Object
>>
classLoaders
=
new
ConcurrentHashMap
<
CloseableURLClassLoader
,
WeakReference
<
Object
>>();
private
final
Map
<
CloseableURLClassLoader
,
WeakReference
<
Object
>>
classLoaders
=
new
ConcurrentHashMap
<
CloseableURLClassLoader
,
WeakReference
<
Object
>>();
private
final
Map
<
File
,
WeakReference
<
Object
>>
tempDirs
=
new
ConcurrentHashMap
<
File
,
WeakReference
<
Object
>>();
/**
/**
* Default constructor. <b>Do not use this constructor. This bean is Spring managed.</b>
* Default constructor. <b>Do not use this constructor. This bean is Spring managed.</b>
...
@@ -102,13 +107,22 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -102,13 +107,22 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
*/
*/
@PostConstruct
@PostConstruct
public
void
initialize
()
throws
IOException
{
public
void
initialize
()
throws
IOException
{
// Check for our root-directory and create it if necessary
// Check for the necessary directories and create them if necessary
final
File
rootDir
=
new
File
(
FSProjectDAOImpl
.
ROOT_DIRECTORY
);
this
.
checkDir
(
FSProjectDAOImpl
.
ROOT_DIRECTORY
);
if
(!
rootDir
.
exists
())
{
this
.
checkDir
(
FSProjectDAOImpl
.
TEMP_DIRECTORY
);
final
boolean
result
=
rootDir
.
mkdir
();
}
if
(!
result
)
{
throw
new
IOException
(
"Could not create root directory."
);
@PreDestroy
}
public
void
destroy
()
throws
IOException
{
// Try to clear the temporary directory
FileSystemUtils
.
deleteRecursively
(
new
File
(
FSProjectDAOImpl
.
TEMP_DIRECTORY
));
}
private
void
checkDir
(
final
String
dirName
)
throws
IOException
{
final
File
dir
=
new
File
(
dirName
);
if
(!
dir
.
exists
()
&&
!
dir
.
mkdir
())
{
// Try to create the directory
throw
new
IOException
(
"Could not create directory '"
+
dirName
+
"'."
);
}
}
}
}
...
@@ -366,18 +380,20 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -366,18 +380,20 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
throw
new
ProjectNotExistingException
(
"A project with the name '"
+
projectName
+
"' does not exist."
);
throw
new
ProjectNotExistingException
(
"A project with the name '"
+
projectName
+
"' does not exist."
);
}
}
// Create a new temporary directory
final
File
tempDir
=
this
.
createTemporaryDirectory
();
final
List
<
URL
>
libs
=
new
ArrayList
<
URL
>();
final
List
<
URL
>
libs
=
new
ArrayList
<
URL
>();
// Collect all libraries of the project
// Copy and collect all libraries of the project
// Run through the libs and put them into our list.
final
File
libDir
=
new
File
(
FSProjectDAOImpl
.
ROOT_DIRECTORY
+
File
.
separator
+
projectName
+
File
.
separator
+
FSProjectDAOImpl
.
LIB_DIRECTORY
);
final
File
libDir
=
new
File
(
FSProjectDAOImpl
.
ROOT_DIRECTORY
+
File
.
separator
+
projectName
+
File
.
separator
+
FSProjectDAOImpl
.
LIB_DIRECTORY
);
final
File
[]
files
=
libDir
.
listFiles
();
final
File
[]
files
=
libDir
.
listFiles
();
if
(
files
!=
null
)
{
if
(
files
!=
null
)
{
for
(
final
File
file
:
files
)
{
for
(
final
File
file
:
files
)
{
if
(
file
.
getName
().
endsWith
(
"."
+
FSProjectDAOImpl
.
LIB_EXTENSION
))
{
if
(
file
.
getName
().
endsWith
(
"."
+
FSProjectDAOImpl
.
LIB_EXTENSION
))
{
final
File
newLibFile
=
new
File
(
tempDir
,
file
.
getName
());
FileCopyUtils
.
copy
(
file
,
newLibFile
);
try
{
try
{
libs
.
add
(
f
ile
.
toURI
().
toURL
());
libs
.
add
(
newLibF
ile
.
toURI
().
toURL
());
}
catch
(
final
MalformedURLException
ex
)
{
}
catch
(
final
MalformedURLException
ex
)
{
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
}
...
@@ -393,12 +409,25 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -393,12 +409,25 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
final
CloseableURLClassLoader
classLoader
=
AccessController
.
doPrivileged
(
action
);
final
CloseableURLClassLoader
classLoader
=
AccessController
.
doPrivileged
(
action
);
// Remember the requester
// Remember the requester
this
.
classLoaders
.
put
(
classLoader
,
new
WeakReference
<
Object
>(
requester
));
final
WeakReference
<
Object
>
ref
=
new
WeakReference
<
Object
>(
requester
);
this
.
classLoaders
.
put
(
classLoader
,
ref
);
this
.
tempDirs
.
put
(
tempDir
,
ref
);
WeakReferenceMonitor
.
monitor
(
requester
,
this
);
WeakReferenceMonitor
.
monitor
(
requester
,
this
);
return
classLoader
;
return
classLoader
;
}
}
private
File
createTemporaryDirectory
()
{
int
counter
=
0
;
File
tempDir
;
do
{
tempDir
=
new
File
(
FSProjectDAOImpl
.
TEMP_DIRECTORY
,
"temp"
+
counter
);
counter
++;
}
while
(!
tempDir
.
mkdir
());
return
tempDir
;
}
/*
/*
* (non-Javadoc)
* (non-Javadoc)
*
*
...
@@ -614,16 +643,24 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -614,16 +643,24 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
synchronized
(
this
.
classLoaders
)
{
synchronized
(
this
.
classLoaders
)
{
int
open
=
0
;
int
open
=
0
;
final
List
<
CloseableURLClassLoader
>
toBeRemoved
=
new
ArrayList
<
CloseableURLClassLoader
>();
final
List
<
CloseableURLClassLoader
>
toBeClosed
=
new
ArrayList
<
CloseableURLClassLoader
>();
final
List
<
File
>
toBeRemoved
=
new
ArrayList
<
File
>();
// Run through the class loaders and check which of them can be closed
// Run through the class loaders and check which of them can be closed
for
(
final
Entry
<
CloseableURLClassLoader
,
WeakReference
<
Object
>>
entry
:
this
.
classLoaders
.
entrySet
())
{
for
(
final
Entry
<
CloseableURLClassLoader
,
WeakReference
<
Object
>>
entry
:
this
.
classLoaders
.
entrySet
())
{
if
(
entry
.
getValue
().
get
()
==
null
)
{
if
(
entry
.
getValue
().
get
()
==
null
)
{
toBe
Remov
ed
.
add
(
entry
.
getKey
());
toBe
Clos
ed
.
add
(
entry
.
getKey
());
}
else
{
}
else
{
open
++;
open
++;
}
}
}
}
for
(
final
CloseableURLClassLoader
classLoader
:
toBeRemoved
)
{
for
(
final
Entry
<
File
,
WeakReference
<
Object
>>
entry
:
this
.
tempDirs
.
entrySet
())
{
if
(
entry
.
getValue
().
get
()
==
null
)
{
toBeRemoved
.
add
(
entry
.
getKey
());
}
}
for
(
final
CloseableURLClassLoader
classLoader
:
toBeClosed
)
{
try
{
try
{
classLoader
.
close
();
classLoader
.
close
();
this
.
classLoaders
.
remove
(
classLoader
);
this
.
classLoaders
.
remove
(
classLoader
);
...
@@ -632,6 +669,15 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
...
@@ -632,6 +669,15 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
FSProjectDAOImpl
.
LOG
.
error
(
"Could not close classloader ("
+
classLoader
+
")"
);
FSProjectDAOImpl
.
LOG
.
error
(
"Could not close classloader ("
+
classLoader
+
")"
);
}
}
}
}
for
(
final
File
tempDir
:
toBeRemoved
)
{
final
boolean
result
=
FileSystemUtils
.
deleteRecursively
(
tempDir
);
if
(
result
)
{
this
.
tempDirs
.
remove
(
tempDir
);
FSProjectDAOImpl
.
LOG
.
info
(
"Removed temporary directory ("
+
tempDir
+
")"
);
}
else
{
FSProjectDAOImpl
.
LOG
.
error
(
"Could not remove temporary directory ("
+
tempDir
+
")"
);
}
}
FSProjectDAOImpl
.
LOG
.
info
(
open
+
" classloaders still open."
);
FSProjectDAOImpl
.
LOG
.
info
(
open
+
" classloaders still open."
);
}
}
}
}
...
...
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