Commit bc7ce4d9 authored by Andre Freyssinet's avatar Andre Freyssinet

Adds a MBean to Rest/JMS service.

parent da0dca00
......@@ -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);
}
}
}
......@@ -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>();
......@@ -198,11 +201,54 @@ public class Helper {
this.cfName = "cf";
}
}
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)
ictx.close();
try {
ictx.close();
} catch (NamingException exc) {
logger.log(BasicLevel.DEBUG, "Helper.closeAll:", exc);
}
}
/**
......@@ -639,13 +689,8 @@ public class Helper {
ConsumerContext consumerCtx = (ConsumerContext) sessionCtxs.get(consName);
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: 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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment