use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.
the class MBeanUtil method ensureMBeanIsRegistered.
/**
* Ensures that an MBean is registered for the specified <code>ManagedResource</code>. If an MBean
* cannot be found in the <code>MBeanServer</code>, then this creates and registers a
* <code>ModelMBean</code>. State changing callbacks into the <code>ManagedResource</code> will
* also be made.
*
* @param resource the ManagedResource to create a managing MBean for
*
* @return The object name of the MBean that manages the ManagedResource
*
* @see ManagedResource#setModelMBean
*/
static ObjectName ensureMBeanIsRegistered(ManagedResource resource) {
try {
ObjectName objName = ObjectName.getInstance(resource.getMBeanName());
synchronized (MBeanUtil.class) {
if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
return createMBean(resource);
}
}
raiseOnFailure(mbeanServer.isRegistered(objName), LocalizedStrings.MBeanUtil_COULDNT_FIND_MBEAN_REGISTERED_WITH_OBJECTNAME_0.toLocalizedString(new Object[] { objName.toString() }));
return objName;
} catch (java.lang.Exception e) {
throw new RuntimeAdminException(e);
}
}
use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.
the class MBeanUtil method createRegistry.
/**
* Create and configure (if necessary) and return the Commons-Modeler registry of managed object
* descriptions.
*
* @see org.apache.commons.modeler.Registry
*/
static synchronized Registry createRegistry() {
if (registry == null) {
try {
registry = Registry.getRegistry(null, null);
if (mbeanServer == null) {
throw new IllegalStateException(LocalizedStrings.MBeanUtil_MBEAN_SERVER_NOT_INITIALIZED_YET.toLocalizedString());
}
registry.setMBeanServer(mbeanServer);
String mbeansResource = getOSPath("/org/apache/geode/admin/jmx/mbeans-descriptors.xml");
// System.out.println(LocalizedStrings.MBeanUtil_LOADING_RESOURCE_0.toLocalizedString(mbeansResource));
URL url = ClassPathLoader.getLatest().getResource(MBeanUtil.class, mbeansResource);
raiseOnFailure(url != null, LocalizedStrings.MBeanUtil_FAILED_TO_FIND_0.toLocalizedString(new Object[] { mbeansResource }));
registry.loadMetadata(url);
// simple test to make sure the xml was actually loaded and is valid...
String[] test = registry.findManagedBeans();
raiseOnFailure(test != null && test.length > 0, LocalizedStrings.MBeanUtil_FAILED_TO_LOAD_0.toLocalizedString(new Object[] { mbeansResource }));
} catch (Exception e) {
logStackTrace(Level.WARN, e);
throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_GET_MBEAN_REGISTRY.toLocalizedString(), e);
}
}
return registry;
}
use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.
the class MBeanUtil method createMBean.
/**
* Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>.
* State changing callbacks into the <code>ManagedResource</code> will also be made.
*
* @param resource the ManagedResource to create a managing MBean for
* @param managed the ManagedBean definition to create the MBean with
* @see ManagedResource#setModelMBean
*/
static ObjectName createMBean(ManagedResource resource, ManagedBean managed) {
try {
DynamicManagedBean mb = new DynamicManagedBean(managed);
resource.setModelMBean(mb.createMBean(resource));
// create the ObjectName and register the MBean...
final ObjectName objName;
try {
objName = ObjectName.getInstance(resource.getMBeanName());
} catch (MalformedObjectNameException e) {
throw new MalformedObjectNameException(LocalizedStrings.MBeanUtil_0_IN_1.toLocalizedString(new Object[] { e.getMessage(), resource.getMBeanName() }));
}
synchronized (MBeanUtil.class) {
if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
mbeanServer.registerMBean(resource.getModelMBean(), objName);
synchronized (managedResources) {
managedResources.put(objName, resource);
}
}
}
return objName;
} catch (java.lang.Exception e) {
throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_MBEAN_FOR_0.toLocalizedString(new Object[] { resource.getMBeanName() }), e);
}
}
use of org.apache.geode.admin.RuntimeAdminException in project geode by apache.
the class AdminWaiters method sendAndWait.
// private static final long TIMEOUT = 10000L;
/**
* Sends <code>msg</code> using <code>dm</code> and waits for the response.
*
* @return the response.
* @throws RuntimeAdminException if this method is interrupted, times out, cancelled
* ({@link #cancelWaiters}), or failed with an exception on the server side.
*/
public static AdminResponse sendAndWait(AdminRequest msg, DistributionManager dm) {
// we have to handle admin messages sent to ourselves specially.
if (dm.getId().equals(msg.getRecipient())) {
// Sent from myself
msg.setSender(dm.getId());
return msg.createResponse(dm);
}
AdminResponse result = null;
try {
synchronized (msg) {
Set failures = dm.putOutgoing(msg);
if (failures != null && failures.size() > 0) {
// didn't go out
if (dm.getDistributionManagerIds().contains(msg.getRecipient())) {
// it's still in the view
String s = "";
if (logger.isTraceEnabled(LogMarker.DM)) {
s += " (" + msg + ")";
}
throw new RuntimeAdminException(LocalizedStrings.AdminWaiters_COULD_NOT_SEND_REQUEST_0.toLocalizedString(s));
}
throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SENT_TO_0_FAILED_SINCE_MEMBER_DEPARTED_1.toLocalizedString(new Object[] { msg.getRecipient(), "" }));
}
// sent it
long timeout = getWaitTimeout();
boolean gotResponse = msg.waitForResponse(timeout);
if (!gotResponse) {
if (dm.isCurrentMember(msg.getRecipient())) {
// still here?
// no one ever replied
StringBuffer sb = new StringBuffer("Administration request ");
sb.append(msg);
sb.append(" sent to ");
sb.append(msg.getRecipient());
sb.append(" timed out after ");
sb.append((timeout / 1000));
sb.append(" seconds.");
throw new RuntimeAdminException(sb.toString());
}
// still here?
// recipient vanished
String s = "";
if (logger.isTraceEnabled(LogMarker.DM)) {
s = " (" + msg + ")";
}
throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SENT_TO_0_FAILED_SINCE_MEMBER_DEPARTED_1.toLocalizedString(new Object[] { msg.getRecipient(), s }));
}
// !gotResponse
result = msg.getResponse();
}
// synchronized
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
dm.getCancelCriterion().checkCancelInProgress(ex);
String s = LocalizedStrings.AdminWaiters_REQUEST_WAIT_WAS_INTERRUPTED.toLocalizedString();
if (logger.isTraceEnabled(LogMarker.DM)) {
s += " (" + msg + ")";
}
throw new RuntimeAdminException(s, ex);
}
if (result == null) {
String s = "";
if (logger.isTraceEnabled(LogMarker.DM)) {
s += " (" + msg + ")";
}
throw new OperationCancelledException(LocalizedStrings.AdminWaiters_REQUEST_SEND_TO_0_WAS_CANCELLED_1.toLocalizedString(new Object[] { msg.getRecipient(), s }));
} else if (result instanceof AdminFailureResponse) {
throw new RuntimeAdminException(LocalizedStrings.AdminWaiters_REQUEST_FAILED.toLocalizedString(), ((AdminFailureResponse) result).getCause());
}
return result;
}
Aggregations