use of javax.management.MalformedObjectNameException in project opennms by OpenNMS.
the class MBeansHelper method getMBeansTreeElements.
/**
*
* @param input
* any Mbean
* @param removeLastElement
* should last element be removed?
* @return a List of Elements to build the MBeanTree.
*/
private static List getMBeansTreeElements(Mbean input, boolean removeLastElement) {
List names = new ArrayList();
try {
/*
* By default, the MBeans are displayed in the tree based on their
* object names. The order of key properties specified when the
* object names are created is preserved by the MBeans tab when it
* adds MBeans to the MBean tree. The exact key property list that
* the MBeans tab will use to build the MBean tree will be the one
* returned by the method ObjectName.getKeyPropertyListString(),
* with type as the first key, and j2eeType, if present, as the
* second key.(http://visualvm.java.net/mbeans_tab.html).
*
* Below is the implementation of the above definition.
*/
final ObjectName objectname = ObjectName.getInstance(input.getObjectname());
final Map<String, String> keyProperty = buildKeyPropertyList(objectname);
names.add(objectname.getDomain());
names.addAll(keyProperty.entrySet());
// remove
if (removeLastElement)
names.remove(names.size() - 1);
// last
// element
// if needed
} catch (MalformedObjectNameException ex) {
}
return names;
}
use of javax.management.MalformedObjectNameException in project opennms by OpenNMS.
the class JolokiaBeanMonitor method poll.
/**
* {@inheritDoc}
*
* Poll the specified address for service availability.
*
* During the poll an attempt is made to execute the named method (with
* optional input) connect on the specified port. If the exec on request is
* successful, the banner line generated by the interface is parsed and if
* the banner text indicates that we are talking to Provided that the
* interface's response is valid we set the service status to
* SERVICE_AVAILABLE and return.
*/
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
//
// Process parameters
//
//
TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT);
// Port
int port = ParameterMap.getKeyedInteger(parameters, PARAMETER_PORT, DEFAULT_PORT);
//URL
String strURL = ParameterMap.getKeyedString(parameters, PARAMETER_URL, DEFAULT_URL);
//Username
String strUser = ParameterMap.getKeyedString(parameters, PARAMETER_USERNAME, null);
//Password
String strPasswd = ParameterMap.getKeyedString(parameters, PARAMETER_PASSWORD, null);
//AttrName
String strAttrName = ParameterMap.getKeyedString(parameters, PARAMETER_ATTRNAME, null);
//AttrPath
String strAttrPath = ParameterMap.getKeyedString(parameters, PARAMETER_ATTRPATH, null);
//BeanName
String strBeanName = ParameterMap.getKeyedString(parameters, PARAMETER_BEANNAME, null);
//MethodName
String strMethodName = ParameterMap.getKeyedString(parameters, PARAMETER_METHODNAME, null);
//Optional Inputs
String strInput1 = ParameterMap.getKeyedString(parameters, PARAMETER_METHODINPUT1, null);
String strInput2 = ParameterMap.getKeyedString(parameters, PARAMETER_METHODINPUT2, null);
// BannerMatch
String strBannerMatch = ParameterMap.getKeyedString(parameters, PARAMETER_BANNER, null);
// Get the address instance.
InetAddress ipAddr = svc.getAddress();
final String hostAddress = InetAddressUtils.str(ipAddr);
LOGGER.debug("poll: address = " + hostAddress + ", port = " + port + ", " + tracker);
strURL = strURL.replace("${ipaddr}", hostAddress);
strURL = strURL.replace("${port}", ((Integer) port).toString());
LOGGER.debug("poll: final URL address = " + strURL);
// Give it a whirl
PollStatus serviceStatus = PollStatus.unknown("Initialized");
for (tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt()) {
try {
tracker.startAttempt();
J4pClientBuilder j4pClientBuilder = new J4pClientBuilder();
j4pClientBuilder.url(strURL).connectionTimeout(tracker.getConnectionTimeout()).socketTimeout(tracker.getSoTimeout());
if (strUser != null && strPasswd != null) {
j4pClientBuilder.user(strUser).password(strPasswd);
}
J4pClient j4pClient = j4pClientBuilder.build();
LOGGER.debug("JolokiaBeanMonitor: connected to URLhost: " + strURL);
// We're connected, so upgrade status to unresponsive
serviceStatus = PollStatus.unresponsive();
if (strBannerMatch == null || strBannerMatch.length() == 0 || strBannerMatch.equals("*")) {
serviceStatus = PollStatus.available(tracker.elapsedTimeInMillis());
break;
}
//Exec a method or poll an attribute?
String response;
if (strAttrName != null) {
J4pReadRequest readReq = new J4pReadRequest(strBeanName, strAttrName);
readReq.setPreferredHttpMethod("POST");
if (strAttrPath != null) {
readReq.setPath(strAttrPath);
}
J4pReadResponse resp = j4pClient.execute(readReq);
response = resp.getValue().toString();
} else {
J4pExecRequest execReq;
//Default Inputs
if (strInput1 == null && strInput2 == null) {
LOGGER.debug("JolokiaBeanMonitor - execute bean: " + strBeanName + " method: " + strMethodName);
execReq = new J4pExecRequest(strBeanName, strMethodName);
} else if (strInput1 != null && strInput2 == null) {
//Single Input
LOGGER.debug("JolokiaBeanMonitor - execute bean: " + strBeanName + " method: " + strMethodName + " args: " + strInput1);
execReq = new J4pExecRequest(strBeanName, strMethodName, strInput1);
} else {
//Double Input
LOGGER.debug("JolokiaBeanMonitor - execute bean: " + strBeanName + " method: " + strMethodName + " args: " + strInput1 + " " + strInput2);
execReq = new J4pExecRequest(strBeanName, strMethodName, strInput1, strInput2);
}
execReq.setPreferredHttpMethod("POST");
J4pExecResponse resp = j4pClient.execute(execReq);
response = resp.getValue().toString();
}
double responseTime = tracker.elapsedTimeInMillis();
if (response == null) {
continue;
}
LOGGER.debug("poll: banner = " + response);
LOGGER.debug("poll: responseTime = " + responseTime + "ms");
//Could it be a regex?
if (strBannerMatch.charAt(0) == '~') {
if (!response.matches(strBannerMatch.substring(1))) {
serviceStatus = PollStatus.unavailable("Banner does not match Regex '" + strBannerMatch + "'");
} else {
serviceStatus = PollStatus.available(responseTime);
}
} else {
if (response.contains(strBannerMatch)) {
serviceStatus = PollStatus.available(responseTime);
} else {
serviceStatus = PollStatus.unavailable("Did not find expected Text '" + strBannerMatch + "'");
}
}
} catch (J4pConnectException e) {
String reason = "Connection exception for address: " + ipAddr + ":" + port + " " + e.getMessage();
LOGGER.debug(reason, e);
serviceStatus = PollStatus.unavailable(reason);
break;
} catch (J4pRemoteException e) {
String reason = "Remote exception from J4pRemote: " + e.getMessage();
LOGGER.debug(reason, e);
serviceStatus = PollStatus.unavailable(reason);
} catch (MalformedObjectNameException e) {
String reason = "Parameters for Jolokia are malformed: " + e.getMessage();
LOGGER.debug(reason, e);
serviceStatus = PollStatus.unavailable(reason);
} catch (J4pException e) {
String reason = J4pException.class.getSimpleName() + " during Jolokia monitor call: " + e.getMessage();
LOGGER.debug(reason, e);
serviceStatus = PollStatus.unavailable(reason);
}
}
return serviceStatus;
}
use of javax.management.MalformedObjectNameException in project tdi-studio-se by Talend.
the class DumpHprofAction method getInitialFileName.
/**
* Gets the initial file name.
*
* @param jvm The active JVM
* @return The file name, or <tt>null</tt> if file name is specified
* @throws JvmCoreException
*/
String getInitialFileName(IActiveJvm jvm) throws JvmCoreException {
ObjectName objectName;
try {
objectName = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
} catch (MalformedObjectNameException e) {
throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
} catch (NullPointerException e) {
throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
}
//$NON-NLS-1$
TabularData initialName = (TabularData) jvm.getMBeanServer().getAttribute(objectName, "SystemProperties");
//$NON-NLS-1$
CompositeData compisiteData = initialName.get(new Object[] { "user.home" });
String home = compisiteData.values().toArray(new String[0])[1];
StringBuffer initialFileName = new StringBuffer(home);
initialFileName.append(File.separator).append(new Date().getTime()).append('.').append(SnapshotType.Hprof.getExtension());
return initialFileName.toString();
}
use of javax.management.MalformedObjectNameException in project tdi-studio-se by Talend.
the class OverviewProperties method addGarbageCollectionProperties.
/**
* Adds the garbage collection properties.
*/
private void addGarbageCollectionProperties() {
List<OverviewProperty> list = new ArrayList<OverviewProperty>();
try {
//$NON-NLS-1$
ObjectName queryObjectName = ObjectName.getInstance("java.lang:type=GarbageCollector,name=*");
Set<ObjectName> objectNames = activeJvm.getMBeanServer().queryNames(queryObjectName);
for (ObjectName objectName : objectNames) {
//$NON-NLS-1$
String name = objectName.getKeyProperty("name");
list.add(new OverviewProperty(OverviewCategory.GarbageCollector, NLS.bind(Messages.collectionCountLabel, name), "CollectionCount", name, null, //$NON-NLS-1$
true));
list.add(new OverviewProperty(OverviewCategory.GarbageCollector, NLS.bind(Messages.collectionTimeLabel, name), "CollectionTime", name, IFormat.MILLISEC_FORMAT, //$NON-NLS-1$
true));
}
} catch (MalformedObjectNameException e) {
Activator.log(IStatus.ERROR, Messages.getObjectNameFailedMsg, e);
} catch (JvmCoreException e) {
Activator.log(Messages.getObjectNameFailedMsg, e);
}
overviewProperties.put(OverviewCategory.GarbageCollector, list);
}
use of javax.management.MalformedObjectNameException in project ACS by ACS-Community.
the class GCJMXClient method main.
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Must provide 2 arguments: <classname> <interval-in-ms>");
}
final GCJMXClient client = new GCJMXClient(args[0]);
try {
client.connect();
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
ObjectName objName = null;
try {
objName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
} catch (MalformedObjectNameException e1) {
System.err.println("bad name?");
System.exit(1);
}
final ObjectName objNameF = objName;
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
MBeanServerConnection con = client.getRemote();
try {
con.invoke(objNameF, "gc", null, null);
System.out.println("Called gc() on remote VM");
} catch (Exception e) {
System.err.println("Couldn't call gc() on remote VM");
}
}
};
timer.scheduleAtFixedRate(task, new Date(), Integer.parseInt(args[1]));
}
Aggregations