use of javax.management.JMException in project jdk8u_jdk by JetBrains.
the class ScanManager method addDirectoryScanner.
// Creates and registers a new directory scanner.
// Called by applyConfiguration.
// throws IllegalStateException if state is not STOPPED or COMPLETED
// (you cannot change the config while scanning is scheduled or running).
//
private DirectoryScannerMXBean addDirectoryScanner(DirectoryScannerConfig bean) throws JMException {
try {
final DirectoryScannerMXBean scanner;
final ObjectName scanName;
synchronized (this) {
if (state != STOPPED && state != COMPLETED)
throw new IllegalStateException(state.toString());
scanner = createDirectoryScanner(bean);
scanName = makeDirectoryScannerName(bean.getName());
}
LOG.fine("server: " + mbeanServer);
LOG.fine("scanner: " + scanner);
LOG.fine("scanName: " + scanName);
final ObjectInstance moi = mbeanServer.registerMBean(scanner, scanName);
final ObjectName moiName = moi.getObjectName();
final DirectoryScannerMXBean proxy = JMX.newMXBeanProxy(mbeanServer, moiName, DirectoryScannerMXBean.class, true);
scanmap.put(moiName, proxy);
return proxy;
} catch (RuntimeException x) {
final String msg = "Operation failed: " + x;
if (LOG.isLoggable(Level.FINEST))
LOG.log(Level.FINEST, msg, x);
else
LOG.fine(msg);
throw x;
} catch (JMException x) {
final String msg = "Operation failed: " + x;
if (LOG.isLoggable(Level.FINEST))
LOG.log(Level.FINEST, msg, x);
else
LOG.fine(msg);
throw x;
}
}
use of javax.management.JMException in project jdk8u_jdk by JetBrains.
the class XMBeanAttributes method doLoadAttributes.
// Don't call this in EDT, but execute returned Runnable inside
// EDT - typically in the done() method of a SwingWorker
// This method can return null.
private Runnable doLoadAttributes(final XMBean mbean, MBeanInfo infoOrNull) throws JMException, IOException {
if (mbean == null)
return null;
final MBeanInfo curMBeanInfo = (infoOrNull == null) ? mbean.getMBeanInfo() : infoOrNull;
final MBeanAttributeInfo[] attrsInfo = curMBeanInfo.getAttributes();
final HashMap<String, Object> attrs = new HashMap<String, Object>(attrsInfo.length);
final HashMap<String, Object> unavailableAttrs = new HashMap<String, Object>(attrsInfo.length);
final HashMap<String, Object> viewableAttrs = new HashMap<String, Object>(attrsInfo.length);
AttributeList list = null;
try {
list = mbean.getAttributes(attrsInfo);
} catch (Exception e) {
if (JConsole.isDebug()) {
System.err.println("Error calling getAttributes() on MBean \"" + mbean.getObjectName() + "\". JConsole will " + "try to get them individually calling " + "getAttribute() instead. Exception:");
e.printStackTrace(System.err);
}
list = new AttributeList();
//Can't load all attributes, do it one after each other.
for (int i = 0; i < attrsInfo.length; i++) {
String name = null;
try {
name = attrsInfo[i].getName();
Object value = mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), name);
list.add(new Attribute(name, value));
} catch (Exception ex) {
if (attrsInfo[i].isReadable()) {
unavailableAttrs.put(name, Utils.getActualException(ex).toString());
}
}
}
}
try {
int att_length = list.size();
for (int i = 0; i < att_length; i++) {
Attribute attribute = (Attribute) list.get(i);
if (isViewable(attribute)) {
viewableAttrs.put(attribute.getName(), attribute.getValue());
} else
attrs.put(attribute.getName(), attribute.getValue());
}
// check them one after the other.
if (att_length < attrsInfo.length) {
for (int i = 0; i < attrsInfo.length; i++) {
MBeanAttributeInfo attributeInfo = attrsInfo[i];
if (!attrs.containsKey(attributeInfo.getName()) && !viewableAttrs.containsKey(attributeInfo.getName()) && !unavailableAttrs.containsKey(attributeInfo.getName())) {
if (attributeInfo.isReadable()) {
// went wrong.
try {
Object v = mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), attributeInfo.getName());
//What happens if now it is ok?
// Be pragmatic, add it to readable...
attrs.put(attributeInfo.getName(), v);
} catch (Exception e) {
//Put the exception that will be displayed
// in tooltip
unavailableAttrs.put(attributeInfo.getName(), Utils.getActualException(e).toString());
}
}
}
}
}
} catch (Exception e) {
//sets all attributes unavailable except the writable ones
for (int i = 0; i < attrsInfo.length; i++) {
MBeanAttributeInfo attributeInfo = attrsInfo[i];
if (attributeInfo.isReadable()) {
unavailableAttrs.put(attributeInfo.getName(), Utils.getActualException(e).toString());
}
}
}
//one update at a time
return new Runnable() {
public void run() {
synchronized (XMBeanAttributes.this) {
XMBeanAttributes.this.mbean = mbean;
XMBeanAttributes.this.mbeanInfo = curMBeanInfo;
XMBeanAttributes.this.attributesInfo = attrsInfo;
XMBeanAttributes.this.attributes = attrs;
XMBeanAttributes.this.unavailableAttributes = unavailableAttrs;
XMBeanAttributes.this.viewableAttributes = viewableAttrs;
DefaultTableModel tableModel = (DefaultTableModel) getModel();
// add attribute information
emptyTable(tableModel);
addTableData(tableModel, mbean, attrsInfo, attrs, unavailableAttrs, viewableAttrs);
// update the model with the new data
tableModel.newDataAvailable(new TableModelEvent(tableModel));
// re-register for change events
tableModel.addTableModelListener(attributesListener);
}
}
};
}
use of javax.management.JMException in project tdi-studio-se by Talend.
the class MBeanServer method setAttribute.
/*
* @see IMBeanServer#setAttribute(ObjectName, Attribute)
*/
@Override
public void setAttribute(ObjectName objectName, Attribute attribute) throws JvmCoreException {
Assert.isNotNull(objectName);
Assert.isNotNull(attribute);
if (!checkReachability()) {
return;
}
try {
connection.setAttribute(objectName, attribute);
} catch (JMException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.setAttributeFailedMsg, attribute.getName()), e);
} catch (IOException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.setAttributeFailedMsg, attribute.getName()), e);
}
}
use of javax.management.JMException in project tdi-studio-se by Talend.
the class MBeanServer method invoke.
/*
* @see IMBeanServer#invoke(ObjectName, String, String[], String[])
*/
@Override
public Object invoke(ObjectName objectName, String method, Object[] params, String[] signatures) throws JvmCoreException {
Assert.isNotNull(objectName);
Assert.isNotNull(method);
if (!checkReachability()) {
return null;
}
try {
return connection.invoke(objectName, method, params, signatures);
} catch (JMException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.mBeanOperationFailedMsg, method), e);
} catch (IOException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.mBeanOperationFailedMsg, method), e);
}
}
use of javax.management.JMException in project felix by apache.
the class InvokeOperationCommandProcessor method executeRequest.
public Document executeRequest(HttpInputStream in) throws IOException, JMException {
Document document = builder.newDocument();
Element root = document.createElement("MBeanOperation");
document.appendChild(root);
Element operationElement = document.createElement("Operation");
operationElement.setAttribute("operation", "invoke");
root.appendChild(operationElement);
String objectVariable = in.getVariable("objectname");
String operationVariable = in.getVariable("operation");
if (objectVariable == null || objectVariable.equals("") || operationVariable == null || operationVariable.equals("")) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
return document;
}
operationElement.setAttribute("objectname", objectVariable);
List types = new ArrayList();
List values = new ArrayList();
int i = 0;
boolean unmatchedParameters = false;
boolean valid = false;
do {
String parameterType = in.getVariable("type" + i);
String parameterValue = in.getVariable("value" + i);
valid = (parameterType != null && parameterValue != null);
if (valid) {
types.add(parameterType);
Object value = null;
try {
value = CommandProcessorUtil.createParameterValue(parameterType, parameterValue);
} catch (Exception e) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Parameter " + i + ": " + parameterValue + " cannot be converted to type " + parameterType);
return document;
}
if (value != null) {
values.add(value);
}
}
if (parameterType == null ^ parameterValue == null) {
unmatchedParameters = true;
break;
}
i++;
} while (valid);
if (objectVariable == null || objectVariable.equals("") || operationVariable == null || operationVariable.equals("")) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
return document;
}
if (unmatchedParameters) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "count of parameter types doesn't match count of parameter values");
return document;
}
ObjectName name = null;
try {
name = new ObjectName(objectVariable);
} catch (MalformedObjectNameException e) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Malformed object name");
return document;
}
if (server.isRegistered(name)) {
MBeanInfo info = server.getMBeanInfo(name);
MBeanOperationInfo[] operations = info.getOperations();
boolean match = false;
if (operations != null) {
for (int j = 0; j < operations.length; j++) {
if (operations[j].getName().equals(operationVariable)) {
MBeanParameterInfo[] parameters = operations[j].getSignature();
if (parameters.length != types.size()) {
continue;
}
Iterator k = types.iterator();
boolean signatureMatch = true;
for (int p = 0; p < types.size(); p++) {
if (!parameters[p].getType().equals(k.next())) {
signatureMatch = false;
break;
}
}
match = signatureMatch;
}
if (match) {
break;
}
}
}
if (!match) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Operation singature has no match in the MBean");
} else {
try {
Object[] params = values.toArray();
String[] signature = new String[types.size()];
types.toArray(signature);
Object returnValue = server.invoke(name, operationVariable, params, signature);
operationElement.setAttribute("result", "success");
if (returnValue != null) {
operationElement.setAttribute("returnclass", returnValue.getClass().getName());
operationElement.setAttribute("return", returnValue.toString());
} else {
operationElement.setAttribute("returnclass", null);
operationElement.setAttribute("return", null);
}
} catch (Exception e) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", e.getMessage());
}
}
} else {
if (name != null) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", new StringBuffer("MBean ").append(name).append(" not registered").toString());
}
}
return document;
}
Aggregations