Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
joram
joram
Commits
d0f6bb11
Commit
d0f6bb11
authored
Jul 09, 2020
by
Andre Freyssinet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds a MBean to Rest/JMS service.
parent
5e18ef64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
10 deletions
+115
-10
joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/Activator.java
...in/java/org/objectweb/joram/tools/rest/jms/Activator.java
+24
-1
joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/Helper.java
.../main/java/org/objectweb/joram/tools/rest/jms/Helper.java
+54
-9
joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/HelperMBean.java
.../java/org/objectweb/joram/tools/rest/jms/HelperMBean.java
+37
-0
No files found.
joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/Activator.java
View file @
d0f6bb11
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2016 - 20
17
ScalAgent Distributed Technologies
* Copyright (C) 2016 - 20
20
ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -35,6 +35,7 @@ import org.osgi.service.http.HttpContext;
import
org.osgi.service.http.HttpService
;
import
fr.dyade.aaa.common.Debug
;
import
fr.dyade.aaa.util.management.MXWrapper
;
/**
*
...
...
@@ -92,17 +93,20 @@ public class Activator implements BundleActivator {
"Bad configuration property "
+
Helper
.
BUNDLE_CLEANER_PERIOD_PROP
+
", should be a number: "
+
value
);
}
}
Helper
.
getInstance
().
setCleanerPeriod
(
period
);
if
(
period
>
0
)
{
cleanerTask
=
new
CleanerTask
();
cleanerTask
.
setPeriod
(
period
);
cleanerTask
.
start
();
}
registerMBean
(
Helper
.
getInstance
(),
mbeanName
);
}
finally
{
Thread
.
currentThread
().
setContextClassLoader
(
originalContextClassLoader
);
}
}
public
void
stop
(
BundleContext
bundleContext
)
throws
Exception
{
unregisterMBean
(
mbeanName
);
if
(
cleanerTask
!=
null
)
cleanerTask
.
stop
();
Helper
.
getInstance
().
closeAll
();
...
...
@@ -112,4 +116,23 @@ public class Activator implements BundleActivator {
httpService
.
unregister
(
servletAlias
);
}
}
private
static
String
JMX_DOMAIN
=
"Joram Rest"
;
private
static
String
mbeanName
=
"connector=JMS"
;
public
static
void
registerMBean
(
Object
mbean
,
String
name
)
{
try
{
MXWrapper
.
registerMBean
(
mbean
,
JMX_DOMAIN
,
name
);
}
catch
(
Exception
e
)
{
logger
.
log
(
BasicLevel
.
WARN
,
"registerMBean: "
+
name
,
e
);
}
}
public
static
void
unregisterMBean
(
String
name
)
{
try
{
MXWrapper
.
unregisterMBean
(
JMX_DOMAIN
,
name
);
}
catch
(
Exception
e
)
{
logger
.
log
(
BasicLevel
.
WARN
,
"unregisterMBean: "
+
name
,
e
);
}
}
}
joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/Helper.java
View file @
d0f6bb11
...
...
@@ -24,6 +24,7 @@ package org.objectweb.joram.tools.rest.jms;
import
java.lang.reflect.Constructor
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
...
...
@@ -47,7 +48,7 @@ import org.osgi.framework.BundleContext;
import
fr.dyade.aaa.common.Debug
;
public
class
Helper
{
public
class
Helper
implements
HelperMBean
{
public
static
Logger
logger
=
Debug
.
getLogger
(
Helper
.
class
.
getName
());
private
static
final
String
BYTES_CLASS_NAME
=
byte
[].
class
.
getName
();
...
...
@@ -82,6 +83,8 @@ public class Helper {
private
String
IPAllowed
;
private
IPFilter
ipfilter
;
private
long
lastCleanTime
=
0L
;
private
Helper
()
{
restClientCtxs
=
new
HashMap
<
String
,
RestClientContext
>();
sessionCtxs
=
new
HashMap
<
String
,
SessionContext
>();
...
...
@@ -199,10 +202,53 @@ public class Helper {
}
}
private
long
cleanerPeriod
;
public
void
setCleanerPeriod
(
long
cleanerPeriod
)
{
this
.
cleanerPeriod
=
cleanerPeriod
;
}
public
long
getCleanerPeriod
()
{
return
cleanerPeriod
;
}
public
long
getDefaultIdleTimeout
()
{
return
globalIdleTimeout
;
}
public
void
setLastCleanTime
()
{
lastCleanTime
=
System
.
currentTimeMillis
();
}
public
String
getLastCleanTime
()
{
return
new
Date
(
lastCleanTime
).
toString
();
}
public
int
getNbContexts
()
{
return
restClientCtxs
.
size
();
}
public
String
dumpContexts
()
{
StringBuilder
builder
=
new
StringBuilder
();
ArrayList
<
RestClientContext
>
values
=
new
ArrayList
<
RestClientContext
>(
restClientCtxs
.
values
());
for
(
RestClientContext
ctx
:
values
)
{
builder
.
append
(
ctx
).
append
(
'\n'
);
}
return
builder
.
toString
();
}
public
String
dumpSessions
()
{
StringBuilder
builder
=
new
StringBuilder
();
ArrayList
<
SessionContext
>
values
=
new
ArrayList
<
SessionContext
>(
sessionCtxs
.
values
());
for
(
SessionContext
ctx
:
values
)
{
builder
.
append
(
ctx
).
append
(
'\n'
);
}
return
builder
.
toString
();
}
/**
*
@throws Exception
*
Should only be called in stop.
*/
public
void
closeAll
()
throws
Exception
{
public
void
closeAll
()
{
ArrayList
<
RestClientContext
>
values
=
new
ArrayList
<
RestClientContext
>(
restClientCtxs
.
values
());
if
(
logger
.
isLoggable
(
BasicLevel
.
DEBUG
))
logger
.
log
(
BasicLevel
.
DEBUG
,
"Helper.closeAll "
+
values
);
...
...
@@ -211,7 +257,11 @@ public class Helper {
}
// close jndi
if
(
ictx
!=
null
)
try
{
ictx
.
close
();
}
catch
(
NamingException
exc
)
{
logger
.
log
(
BasicLevel
.
DEBUG
,
"Helper.closeAll:"
,
exc
);
}
}
/**
...
...
@@ -632,12 +682,7 @@ public class Helper {
if
(
consumerCtx
==
null
)
throw
new
Exception
(
consName
+
" not found."
);
Message
message
=
consumerCtx
.
getMessage
(
msgId
);
if
(
message
!=
null
)
return
message
;
message
=
consumerCtx
.
receive
(
timeout
,
msgId
);
return
message
;
return
consumerCtx
.
receive
(
timeout
,
msgId
);
}
public
String
createClientId
()
{
...
...
joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/HelperMBean.java
0 → 100644
View file @
d0f6bb11
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2016 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package
org.objectweb.joram.tools.rest.jms
;
public
interface
HelperMBean
{
String
getRestUser
();
String
getIPAllowed
();
long
getDefaultIdleTimeout
();
long
getCleanerPeriod
();
int
getNbContexts
();
String
dumpContexts
();
String
dumpSessions
();
String
getLastCleanTime
();
void
close
(
String
clientId
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment