Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
096702c7
Commit
096702c7
authored
12 years ago
by
srosse
Browse files
Options
Downloads
Plain Diff
Merge OpenOLAT 8.3 to OpenOLAT default branch with 47979aa06a1e8128ea6675e7ffc57bffd9694f74
parents
3ea66b95
7c8ef396
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
src/main/java/org/olat/restapi/system/DatabaseWebService.java
+73
-20
73 additions, 20 deletions
...main/java/org/olat/restapi/system/DatabaseWebService.java
with
73 additions
and
20 deletions
src/main/java/org/olat/restapi/system/DatabaseWebService.java
+
73
−
20
View file @
096702c7
...
...
@@ -19,8 +19,10 @@
*/
package
org.olat.restapi.system
;
import
java.util.
Collection
;
import
java.util.
Set
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanInfo
;
import
javax.management.MBeanServer
;
import
javax.management.ObjectName
;
import
javax.ws.rs.GET
;
...
...
@@ -38,8 +40,6 @@ import org.olat.restapi.system.vo.DatabaseConnectionVO;
import
org.olat.restapi.system.vo.DatabaseVO
;
import
org.olat.restapi.system.vo.HibernateStatisticsVO
;
import
com.mchange.v2.c3p0.PooledDataSource
;
/**
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
...
...
@@ -92,33 +92,86 @@ public class DatabaseWebService {
private
DatabaseConnectionVO
getConnectionInfos
()
{
DatabaseConnectionVO
vo
=
new
DatabaseConnectionVO
();
vo
.
setActiveConnectionCount
(
0
);
vo
.
setCurrentConnectionCount
(
0
);
try
{
int
activeConnectionCount
=
0
;
int
currentConnectionCount
=
0
;
JMXManager
jmxManager
=
CoreSpringFactory
.
getImpl
(
JMXManager
.
class
);
MBeanServer
mBeanServer
=
jmxManager
.
getMBeanServer
();
ObjectName
c3p0ObjectName
=
new
ObjectName
(
"com.mchange.v2.c3p0:type=C3P0Registry"
);
boolean
found
=
searchC3P0DataSources
(
mBeanServer
,
vo
)
||
searchTomcatDataSources
(
mBeanServer
,
vo
);
if
(
log
.
isDebug
())
{
log
.
debug
(
"MBean for datasource found: "
+
found
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
return
vo
;
}
private
boolean
searchC3P0DataSources
(
MBeanServer
mBeanServer
,
DatabaseConnectionVO
vo
)
{
try
{
ObjectName
poolName
=
new
ObjectName
(
"com.mchange.v2.c3p0:type=*,*"
);
Set
<
ObjectName
>
names
=
mBeanServer
.
queryNames
(
poolName
,
null
);
if
(
names
.
size
()
>
0
)
{
int
activeConnectionCount
=
0
;
int
currentConnectionCount
=
0
;
Object
attributes
=
mBeanServer
.
getAttribute
(
c3p0ObjectName
,
"AllPooledDataSources"
);
if
(
attributes
instanceof
Collection
)
{
@SuppressWarnings
(
"unchecked"
)
Collection
<
Object
>
attributeCollection
=
(
Collection
<
Object
>)
attributes
;
for
(
Object
attribute
:
attributeCollection
)
{
if
(
attribute
instanceof
PooledDataSource
)
{
PooledDataSource
dataSource
=
(
PooledDataSource
)
attribute
;
activeConnectionCount
+=
dataSource
.
getNumBusyConnectionsAllUsers
();
currentConnectionCount
+=
dataSource
.
getNumConnectionsAllUsers
();
for
(
ObjectName
name:
names
)
{
String
cName
=
name
.
getCanonicalName
();
if
(
cName
.
startsWith
(
"com.mchange.v2.c3p0:type=PooledDataSource"
))
{
MBeanInfo
info
=
mBeanServer
.
getMBeanInfo
(
name
);
MBeanAttributeInfo
[]
attrs
=
info
.
getAttributes
();
for
(
MBeanAttributeInfo
attr:
attrs
)
{
String
attrName
=
attr
.
getName
();
if
(
"numBusyConnectionsAllUsers"
.
equals
(
attrName
))
{
Number
obj
=
(
Number
)
mBeanServer
.
getAttribute
(
name
,
"numBusyConnectionsAllUsers"
);
activeConnectionCount
+=
obj
.
intValue
();
}
else
if
(
"numConnectionsAllUsers"
.
equals
(
attrName
))
{
Number
obj
=
(
Number
)
mBeanServer
.
getAttribute
(
name
,
"numConnectionsAllUsers"
);
currentConnectionCount
+=
obj
.
intValue
();
}
}
}
}
vo
.
setActiveConnectionCount
(
activeConnectionCount
);
vo
.
setCurrentConnectionCount
(
currentConnectionCount
);
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
return
false
;
}
private
boolean
searchTomcatDataSources
(
MBeanServer
mBeanServer
,
DatabaseConnectionVO
vo
)
{
try
{
ObjectName
poolName
=
new
ObjectName
(
"Catalina:type=DataSource,*"
);
Set
<
ObjectName
>
names
=
mBeanServer
.
queryNames
(
poolName
,
null
);
if
(
names
.
size
()
>
0
)
{
int
activeConnectionCount
=
0
;
int
idleConnectionCount
=
0
;
for
(
ObjectName
name:
names
)
{
MBeanInfo
info
=
mBeanServer
.
getMBeanInfo
(
name
);
MBeanAttributeInfo
[]
attrs
=
info
.
getAttributes
();
for
(
MBeanAttributeInfo
attr:
attrs
)
{
String
attrName
=
attr
.
getName
();
if
(
"numActive"
.
equals
(
attrName
))
{
Number
obj
=
(
Number
)
mBeanServer
.
getAttribute
(
name
,
"numActive"
);
activeConnectionCount
+=
obj
.
intValue
();
}
else
if
(
"numIdle"
.
equals
(
attrName
))
{
Number
obj
=
(
Number
)
mBeanServer
.
getAttribute
(
name
,
"numIdle"
);
idleConnectionCount
+=
obj
.
intValue
();
}
}
}
vo
.
setActiveConnectionCount
(
activeConnectionCount
);
vo
.
setCurrentConnectionCount
(
current
ConnectionCount
);
vo
.
setActiveConnectionCount
(
activeConnectionCount
);
vo
.
setCurrentConnectionCount
(
activeConnectionCount
-
idle
ConnectionCount
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
return
vo
;
return
false
;
}
}
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